psql: error: could not connect to server: No such file or directory

Viewed 1581

i have installed Postgresql and struggling to configure it, tried reinstalling but still facing issue, i removed all the files and then installed postgre 9.6 version, but getting below issues.

9.6 main    5432 down   postgres /var/lib/postgresql/9.6/main /var/log/postgresql/postgresql-9.6-main.log

When i try to run postgre by using sudo -u postgres psql it gives below output

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

i have tried from other questions as well but can't fix the problem.

1 Answers

Very likely your PostgreSQL client is configured with a different socket directory (/var/run/postgresql) than your server. Check the unix_socket_directories configuration parameter in postgresql.conf.

Chances are that the server is listening on the default dirextory /tmp. Try

psql -h /tmp ...

Of course it could also be that the server is listening on a different port, e.g. 5555 (configuration parameter port). Then run

psql -p 5555 ...
Related