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


当前回答

service postgresql status

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

我运行的是Ubuntu 18.04

其他回答

选择inet_server_port ();提供服务器的端口。

service postgresql status

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

我运行的是Ubuntu 18.04

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

我使用这样的解决方案。不需要插件。不需要临时表。仅适用于unix。

select pg_read_file('/etc/hostname') as hostname, setting as port from pg_settings where name='port';
SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port;

这里使用了psql内置的HOST变量

和postgres系统信息函数,文档在这里