Thread: How to find compiled-in default port number?

How to find compiled-in default port number?

From
Виктор Егоров
Date:
Greetings.

Is there a way to find out the compiled-in port number?

I can parse `pg_config` output to check out port in cases port was actually specified.

However if defaults had been used, is there any tool that will tell me the magic 5432 number
or should I silently stick to this number in my scripts?

Thanks in advance!

--
Victor Y. Yegorov

Re: How to find compiled-in default port number?

From
Martin Gregorie
Date:
On Tue, 2012-03-13 at 11:16 +0200, Виктор Егоров wrote:
> Greetings.
>
> Is there a way to find out the compiled-in port number?
>
Two ways, with Postgres running:
- Scan the server's ports with nmap.
- as root on the server, run "lsof | less" and look at the
  Postgres process(es).

Both are fast, so do both. If lsof shows the PostgreSQL port but nmap
doesn't, then you'll know its being blocked by a firewall.


Martin



Re: How to find compiled-in default port number?

From
Adrian Klaver
Date:
On 03/13/2012 02:16 AM, Виктор Егоров wrote:
> Greetings.
>
> Is there a way to find out the compiled-in port number?
>
> I can parse `pg_config` output to check out port in cases port was
> actually specified.
>
> However if defaults had been used, is there any tool that will tell me
> the magic 5432 number
> or should I silently stick to this number in my scripts?

Not sure if this is what you want?:


This from Postgres 9.0.7.

test=> SELECT current_setting('port');
  current_setting
-----------------
  5432

test=> SELECT inet_server_port();
  inet_server_port
------------------
              5432

Be aware for inet_server_port() to work you have to connect in a method
other than Unix local socket. In other words something like:

psql -d test -U aklaver -h localhost


More information here:

http://www.postgresql.org/docs/9.0/interactive/functions-info.html

http://www.postgresql.org/docs/9.0/interactive/functions-admin.html


>
> Thanks in advance!
>
> --
> Victor Y. Yegorov


--
Adrian Klaver
adrian.klaver@gmail.com