16

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

Dinesh
  • 281
  • 1
  • 2
  • 8
  • Did you modify the **postgresql.conf** file in **/etc/postgresql/9.3**? The line **listen_addresses = 'localhost'** must be uncommented (without #). – xunilk May 21 '15 at 12:57
  • @xunilk thanks for your response! i tried but, same problem occurs! – Dinesh May 22 '15 at 05: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 '15 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. – Mario Tacke Sep 12 '16 at 17:48

5 Answers5

28

Just try to restart

sudo /etc/init.d/postgresql restart

this worked for me :)

Talal
  • 879
  • 1
  • 7
  • 8
3

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 '17 at 03:53
  • 1
    My ubuntu is 16.04 on ubuntu 14.* try like "sudo service xyz start" – Giang Bui Truong Jan 11 '17 at 14:48
0

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


SOLUTION

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!

0

Try this one sir,

Edited your pg_hba.conf and add your host address :

local    all    postgres                     peer
host     all    all         127.0.0.1/24     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.

abu-ahmed al-khatiri
  • 1,699
  • 13
  • 33
0

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

#!/bin/bash

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