4
votes

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.

2
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
pg_ctl status?..Vao Tsun
Please provide your error message. Which user are you attempting to start the service as. YOu must be the 'postgres' user.VynlJunkie

2 Answers

2
votes

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

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.