简体   繁体   中英

How to get port number of database in postgresql for ubuntu?

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?

试试这个:

netstat -tulpn | grep postgres

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

eg

pg_lsclusters -h | awk '/^9.3/ { if ($2 == "main") { print $3; } }'
select setting from pg_settings where name = 'port'
  • 如果您在同一群集中有多个服务器,则使用

    select inet_server_port();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM