5

I have installed postgresql on Ubuntu 16.04, when I run psql command this error appears:

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

I tried to restart and reload postgres service but the error shows every time.

Dat Nguyen
  • 1,626
  • 22
  • 25
Louis
  • 71
  • 1
  • 4
  • 1
    Postgres server creates this file on startup. Thus, your server isn't running. Please look into the system or postgres logs to find details, why your server doesn't start. – clemens Jun 27 '17 at 05:27
  • `pg_ctl status`?.. – Vao Tsun Jun 27 '17 at 05:53
  • Please provide your error message. Which user are you attempting to start the service as. YOu must be the 'postgres' user. – VynlJunkie Jun 27 '17 at 09:48

2 Answers2

3

I got same errors in Ubuntu 14.04 and it worked for me. Try to restart Postgres service

$ sudo service postgresql restart

or

$ sudo /etc/init.d/postgresql restart
Ken Nguyen
  • 425
  • 1
  • 5
  • 12
1

Follow these steps

1) go to /var/log/postgresql and open log file

if you see error similar to this in your log file

FATAL: private key file "/etc/ssl/private/ssl-cert-snakeoil.key" has group or world access

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.

a) execute the following commands to change the permission (make sure to change the key file name if it is diff for you)

$ sudo chown postgres /etc/ssl/private/ssl-cert-snakeoil.key
$ sudo chgrp postgres /etc/ssl/private/ssl-cert-snakeoil.key
$ sudo chmod 740 /etc/ssl/private/ssl-cert-snakeoil.key

now restart the service

$ sudo /etc/init.d/postgresql restart

it should show this messge [ ok ] Restarting postgresql (via systemctl): postgresql.service.

now type these commands to verify

$ sudo su - postgres
$ psql

You should see this message

root@imp-itpl0023:/etc/ssl/private# su - postgres
postgres@imp-itpl0023:~$ psql
psql (10.3 (Ubuntu 10.3-1.pgdg16.04+1))
Type "help" for help.
Gahan
  • 4,075
  • 4
  • 24
  • 44