Postgresql server is not listening
I know this question has asked many times, but non of those answers worked for me.
The problem is, when I run "psql", I get the message
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
When I run "sudo /etc/init.d/postgresql status”, it says service is running,
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2018-07-10 10:51:05 +0530; 22s ago
Process: 3219 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 3219 (code=exited, status=0/SUCCESS)
But when I run “sudo lsof -i :5432” and “netstat -nltp | grep 5432” and “sudo netstat -lp --protocol=unix | grep postgres”, I gets an empty output.
Content of /etc/postgresql/9.5/main/pg_hba.conf is,
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Content of /etc/postgresql/9.5/main/postgresql.conf
hba_file = '/etc/postgresql/9.5/main/pg_hba.conf'
port = 5432
listen_addresses = '*'
Finally, I uninstalled postgres using “sudo apt-get --purge remove postgresql* command and reinstalled using “apt-get install postgresql-9.5”, but the result is same.
Thank you
Solution 1:
I could find an answer to solve my problem in here. Cannot connect to PostgreSQL server. The issue was pg cluster wasn't initiating.
-
sudo pg_ctlcluster 9.5 main start
- will tell whether cluster is running - Then if it gives any errors you can view them using
journalctl -xe
- It shown me the error as
DETAIL: File must have permissions u=rw (0600) or less if owned by the database user, or permissions u=rw,g=r (0640) or less if owned by root
. Then Once I changed the permission of the private key file, problem solved