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


当前回答

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

select pg_read_file('/etc/hostname') as hostname, setting as port from pg_settings where name='port';

其他回答

从终端你可以做:

\conninfo

我建议阅读一份关于他们所有命令的详尽列表的文档:

\?

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

select pg_read_file('/etc/hostname') as hostname, setting as port from pg_settings where name='port';

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

到“终端机”输入

service postgres status

在结果中,您可以获得端口的详细信息

在我的例子中,它运行在端口“5432”(默认)上。我用的是CentOS 7。希望这能有所帮助。

select inet_server_addr( ), inet_server_port( );