Find the host name and port using PSQL commands

吃可爱长大的小学妹 提交于 2019-11-28 03:05:12
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.

a_horse_with_no_name
SELECT *
FROM pg_settings
WHERE name = 'port';

This command will give you postgres port number

 \conninfo

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

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

credits link

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

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

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.

select inet_server_addr( ), inet_server_port( );

The postgresql port is defined in your postgresql.conf file.

For me in Ubuntu 14.04 it is: /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.

go to the "Terminal" and just type

service postgres status

In the results you can get the port details

In my case it's running on port "5432" (default).
I'm using CentOS 7.Hope this helps.

SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port;

This uses psql's built in HOST variable, documented here

And postgres System Information Functions, documented here

service postgresql status

returns: 10/main (port 5432): online

I'm running Ubuntu 18.04

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!