Tag Archives: 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”?

[Solved] 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”?

Error message.

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

There are many cases of this problem, the following are some of the cases I have encountered so far, and I will continue to add them afterwards.

1. The .s.PGSQL.5432 and .s.PGSQL.5432.lock files in the /tmp path are deleted.

Solution: Restart the database $sudo service postgresql restart

2. Modify the listening port.
Before I used 5434 to listen, but later I changed it to 5432, the database started, but psql could not enter the database, but I could enter it by psql -p 5432.

Solution: The port PGPORT was configured during installation. modify the port specified in ~/.bash_profile or /etc/profile file.

3. modified unix_socket_directories in postgresql.conf

 

Quoting from which.
“First, let’s look at the socket file “/tmp/.s.PGSQL.1921″, where 1921 is the port number of pg; the socket file can be configured with the
postgresql.conf file with the following parameters.
#unix_socket_directory = ”
#unix_socket_permissions = 0777
Note: The parameter unix_socket_directory is used to configure the directory of the socket file, the default is the /tmp directory, and the parameter
unix_socket_permissions is used to set the permissions of the socket file.”

Solution:Specify the host and connect with psql -h