我有PSQL运行,并试图得到一个perl应用程序连接到数据库。是否有命令来查找数据库正在运行的当前端口和主机?


当前回答

要找到端口号,可以运行这个命令(假设您在localhost上)

select setting from pg_settings where name='port';

其他回答

这个命令将提供postgres端口号

 \conninfo

如果Postgres运行在Linux服务器上,也可以使用下面的命令

sudo netstat -plunt |grep postgres

或者(如果是邮政局长送来的)

sudo netstat -plunt |grep postmaster

你会看到类似的东西

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      140/postgres
tcp6       0      0 ::1:5432                :::*                    LISTEN      140/postgres

在本例中,端口号为5432,也是默认端口号

信贷:链接

service postgresql status

返回: 10/main(端口5432):online

我运行的是Ubuntu 18.04

可以使用psql \conninfo中的命令 在主机“host_name”上,以用户“user_name”在端口“port_number”连接到数据库“your_database”。

@ a_horis_with_no_name答案的补充。 获取主机名:

SELECT boot_val,reset_val FROM pg_settings WHERE name='listen_addresses';;

右键单击SQL server。我的是PostgresSQL 13和选择属性->连接。这有:

主机名 端口ID 用户名。