Find host name and port using PSQL commands

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

+114
postgresql psql
Apr 08 '11 at 17:13
source share
12 answers

The default PostgreSQL port is 5432 . The host on which the database is running must be provided by your hosting provider; I assume that it will be the same host as the web server if it is not specified. This will usually be configured as localhost if your web server and database server are on the same host.

+45
Apr 08 '11 at 17:18
source share
 SELECT * FROM pg_settings WHERE name = 'port'; 
+190
Apr 08 '11 at 17:21
source share

This command will give you the postgres port number

  \conninfo 

If postgres runs on a Linux server, you can also use the following command

 sudo netstat -plunt |grep postgres 

OR (if he comes as postmaster)

 sudo netstat -plunt |grep postmaster 

and you will see something like 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, the port number is 5432, which is also the default port number

credit reference

+107
Jun 24 '16 at 10:36
source share

select inet_server_addr(); provides the IP address of the server.

+41
Sep 17 '12 at 7:05
source share

select inet_server_port(); provides the server port.

+14
Apr 10 '14 at 11:20
source share

This is a non-sql method. Instructions are given on the image itself. Select the server on which you want to find information, and then follow the steps.

enter image description here

+10
Jun 05 '14 at 15:43
source share
 select inet_server_addr( ), inet_server_port( ); 
+10
Jun 02 '16 at 19:34
source share

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

For me on Ubuntu 14.04 this is /etc/postgresql/9.3/main/postgresql.conf

Inside there is a line:

 port = 5432 

Changing the number requires restarting postgresql for it to take effect.

+7
Apr 6 '15 at 21:11
source share

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".

+1
Jul 26 '19 at 12:35
source share

go to "Terminal" and just type

 service postgres status 

In the results you can get the port more Running postgres details

In my case, it works on port "5432" (by default).
I am using CentOS 7.Hope this helps.

0
Nov 08 '17 at 7:43 on
source share
 SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port; 

This uses the psql built-in HOST variable described here

And the Postgres System Information Functions documented here

0
Mar 28 '18 at 10:52
source share
 service postgresql status 

returns: 10 / main (port 5432): online

I am using Ubuntu 18.04

0
Apr 29 '19 at 16:55
source share



All Articles