I'm using postgresql 9.3 on ubuntu 14.04 LTS. I know that the default port number for postgres is 5432. But, in case if it is different from the default one, then how can I get it?
-
1this will find more answers on serverfault.comPerfect28– Perfect282014-07-07 11:36:51 +00:00Commented Jul 7, 2014 at 11:36
Add a comment
|
3 Answers
Try with this :
netstat -tulpn | grep postgres
1 Comment
Siddharth M
Yes it works! But it is showing only when I'm logging-in as root.
It depends on how you installed PostgreSQL and how it was configured.
There might even be multiple instances of PostgreSQL 9.3 on the machine - zero or more from Ubuntu packages, managed via pg_wrapper, and zero or more from other sources like the EDB graphical installer, compiled from source, etc.
Assuming you're only interested in packaged versions managed by pg_wrapper and you only expect there to be one version: use pg_lsclusters.
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
9.2 main 5433 down postgres /var/lib/postgresql/9.2/main /var/log/postgresql/postgresql-9.2-main.log
9.3 main 5432 online postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
e.g.
pg_lsclusters -h | awk '/^9.3/ { if ($2 == "main") { print $3; } }'
Comments
select setting from pg_settings where name = 'port'
if you have multiple servers in the same cluster then use
select inet_server_port();
1 Comment
Craig Ringer
That's only useful if you already know the port to connect to, though. So it's kind of a catch-22. You can't assume that the default port is the one you want - it depends on how the machine is set up, and it might well connect to some other PostgreSQL instance by default.