postgresql 使用 PSQL 命令查找主机名和端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5598517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:55:04  来源:igfitidea点击:

Find the host name and port using PSQL commands

postgresqlpsql

提问by jamesatha

I have PSQL running, and am trying to get a perl application connecting to the database. Is there a command to find the current port and host that the database is running on?

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

采纳答案by Brad Koch

The default PostgreSQL port is 5432. The host that the database is operating on should have been provided by your hosting provider; I'd guess it would be the same host as the web server if one wasn't specified. Typically this would be configured as localhost, assuming your web server and database server are on the same host.

默认的 PostgreSQL 端口是5432. 运行数据库的主机应该由您的主机提供商提供;如果未指定,我猜它与 Web 服务器是同一台主机。通常这将被配置为 localhost,假设您的 Web 服务器和数据库服务器在同一主机上。

回答by a_horse_with_no_name

SELECT *
FROM pg_settings
WHERE name = 'port';

回答by Khaino

This command will give you postgres port number

此命令将为您提供 postgres 端口号

 \conninfo

If postgres is running on Linux server, you can also use the following command

如果 postgres 在 Linux 服务器上运行,您也可以使用以下命令

sudo netstat -plunt |grep postgres

OR (if it comes as postmaster)

或(如果它是邮政局长)

sudo netstat -plunt |grep postmaster

and you will see something similar as this

你会看到类似的东西

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

in this case, port number is 5432 which is also default port number

在这种情况下,端口号是 5432,这也是默认端口号

credits link

学分链接

回答by Kaarel

select inet_server_addr();gives you the ip address of the server.

select inet_server_addr();给你服务器的IP地址。

回答by Andromida

select inet_server_port();gives you the port of the server.

select inet_server_port();给你服务器的端口。

回答by gerardw

select inet_server_addr( ), inet_server_port( );

回答by bonCodigo

This is non-sql method. Instructions are given on the image itself. Select the server that you want to find the info about and then follow the steps.

这是非sql方法。图像本身给出了说明。选择要查找其信息的服务器,然后按照步骤操作。

enter image description here

在此处输入图片说明

回答by Eric Leschinski

The postgresql port is defined in your postgresql.conffile.

postgresql 端口在您的postgresql.conf文件中定义。

For me in Ubuntu 14.04 it is: /etc/postgresql/9.3/main/postgresql.conf

对于 Ubuntu 14.04 中的我来说,它是: /etc/postgresql/9.3/main/postgresql.conf

Inside there is a line:

里面有一行:

port = 5432

Changing the number there requires restart of postgresql for it to take effect.

更改那里的数字需要重新启动 postgresql 才能生效。

回答by INTRA TUBE

You can use the command in psql \conninfoyou will get You are connected to database "your_database" as user "user_name" on host "host_name" at port "port_number".

您可以在 psql 中使用该命令,\conninfo您将获得You are connected to database "your_database" as user "user_name" on host "host_name" at port "port_number".

回答by Vinayak Mishra

From the terminal you can do:

从终端您可以执行以下操作:

\conninfo

\conninfo

I would suggest reading a documentation on their exhaustive list of all commands using:

我建议使用以下方法阅读有关所有命令的详尽列表的文档:

\?

\?