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

  • In pg_hba, change peer to trust and restart the server. peer only works if your Ubuntu user name matches the database user name. Does that work?
    – Jos
    Jul 10, 2018 at 9:07
  • Thanks, I did that change just now, but no any difference. I think for some reason postgresql is not listening at all.
    – Sameera K
    Jul 10, 2018 at 9:43

1 Answer 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.

  1. sudo pg_ctlcluster 9.5 main start - will tell whether cluster is running
  2. Then if it gives any errors you can view them using journalctl -xe
  3. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.