My problem is after postgresql installed try to configure postgresql database it's show error message like below:

dineshlap@ss-laptop:~$ sudo -u postgres psql postgres
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"?

and i tried lot of solutions from internet. but, nothing worked for me! :(

if you know the solution for this problem please, answer this post!

Note : I'm using ubuntu 14.04 (64 bit) and postgresql 9.3

  • Did you modify the postgresql.conf file in /etc/postgresql/9.3? The line listen_addresses = 'localhost' must be uncommented (without #).
    – xunilk
    May 21, 2015 at 12:57
  • @xunilk thanks for your response! i tried but, same problem occurs!
    – Dinesh
    May 22, 2015 at 5:47
  • Uninstall postgresql with purge and clean and try to install it again. I had a similar problem in Debian and I solved it in this way.
    – xunilk
    May 22, 2015 at 16:11
  • I solved my issue after correcting the pg_hba.conf file. I had removed the CIDR block info from the bindings section. Sep 12, 2016 at 17:48

5 Answers 5


Just try to restart

sudo /etc/init.d/postgresql restart

this worked for me :)

  • its asking for password. what's the default password here? Oct 7, 2016 at 8:57
  • 1
    @PranavSingh that's your sudo password nothing to do with psql
    – Talal
    Oct 8, 2016 at 12:10

Ubuntu16.04 and 9.3

sudo systemctl restart postgresql-9.3.service

Maybe you find out service before restarting server

service --status-all
  • 3
    This question is about 14.04, so you can't call systemctl. The other answer recommends restart. Seems very odd to include a version number in the command also - is this really needed?
    – Zanna
    Jan 11, 2017 at 3:53
  • 1
    My ubuntu is 16.04 on ubuntu 14.* try like "sudo service xyz start" Jan 11, 2017 at 14:48

In some case you may have permission issue. I create a shell script like this:


chown -R $User:$User /var/run/postgresql
sudo /etc/init.d/postgresql restart

replace $User with your username, and execute the file (assuming the file name is postgresql.sh):

sudo ./postgresrun.sh

I had the same problem. after running

systemctl status postgresql@9.6-main.service

It showed the following error

data directory "/var/lib/postgresql/9.6/main" has group or world access


so I ran:

sudo chmod 0700 /var/lib/postgresql/9.6/main

Then I restarted:

sudo systemctl restart postgresql@9.6-main.service

running sudo systemctl restart postgresql@9.6-main.service showed my service active and running!


Try this one sir,

Edited your pg_hba.conf and add your host address :

local    all    postgres                     peer
host     all    all     md5

and also edited your postgres.confadd your queue with :

listen_addresses = " * "

and then restart your service :

sudo service postgresql restart

see your log output said what the miracled:

sudo tail -f /var/log/postgresql/postgresql-9.6-main.log

Hope this helps sir.

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.