I found there is a PostgreSQL extension pg-hostname which can get the hostname from server. When we have installed the extension we can enable that and query information by inet_server_port & hostname function.
On Windows you can use Control Panel -> Administrative Tools -> Services and restart the PostgreSQL service. For ]po[, the PostgreSQL service is called "]po[ PostgreSQL". Repeating the "Check for Port IP" step above, you should now see that the port IP is "0.0.
its hostname : this is usually a string like customers.mydomain.com ; its port : the default port for PostgreSQL databases is 5432; the name of the database that you want to connect to.
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
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.
select inet_server_addr();
gives you the ip address 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( );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With