I just installed Postgres newly and I try to check if its running and on what port, although I know what default port it normally has these commands are not showing me the port.
service postgresql status
I get this
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese
Active: active (exited) since Tue 2018-09-18 14:17:14 CEST; 22min ago
Process: 2632 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 2632 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.service
Sep 18 14:17:14 user-HP-Pavilion-TS-15-Notebook-PC systemd[1]: Starting PostgreS
Sep 18 14:17:14 user-HP-Pavilion-TS-15-Notebook-PC systemd[1]: Started PostgreSQ
Sep 18 14:39:19 user-HP-Pavilion-TS-15-Notebook-PC systemd[1]: Started PostgreSQ
And when I just try to simply check process and see what port it shows this after the command
sudo netstat -plunt |grep postgres
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 2592/postgres
tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 1065/postgres_expor
How can I get the port to show and what is going on?
This answer on serverfault needs you to connect to the machine and no other packages or root user.
Just connect and run the command.
If you can connect to PostgreSQL from the original machine you can see what port it's listening on:
SHOW port;
First, find the “postmaster” process, the parent of all other PostgreSQL processes.
You can get it from the postmaster.pid
file in the PostgreSQL data directory if the database is started.
Then you can get the port with lsof
. Assuming the process ID is 23521, run
lsof -P -sTCP:LISTEN -i TCP -a -p 23521
That will show you the port where PostgreSQL is listening.
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