7

Postgresql server running and verified on 5432 on my localhost system:

If I type: psql -l I get the following response:

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

If I type psql -h localhost -l, it works and gives me a list of the databases.

The pg_hba.conf file is wide open, showing:

TYPE    DATABASE        USER            ADDRESS                 METHOD

The value "local" is for Unix domain socket connections only:

local   all             all                                     trust

Allow any IP to connect without password:

host    all             all             0.0.0.0/0               trust

IPv4 local connections:

host    all             all             127.0.0.1/32            trust

IPv6 local connections:

host    all             all             ::1/128                 trust

What have I missed? On other systems the first call from the command line works fine.

3 Answers 3

11

It sounds like when you are running the command you are connecting to localhost, not the file socket.. try

psql -h localhost -p 5432 
Sign up to request clarification or add additional context in comments.

Comments

4

Default Admin Login sudo -u postgres psql

Login into specific db with privilages psql -h host -p port -U User_Name db_name

Comments

1

Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

This just means that the unix_socket_directory configuration parameter on the server differs from the default of the client-side psql.

/var/run/postgresql is the default Unix domain socket path for Debian-based packages. For a self-compiled server, it is /tmp. It may also be a custom path specified in postgresql.conf or through a start directive.

Assuming it's /tmp you could do psql -l -h /tmp. The command knows that the parameter following -h is to be interpreted as a directory and not as a hostname because it starts with a slash.

2 Comments

If this command works psql -U postgres -h /tmp, or this one su - postgres -c "psql -h /tmp" , then you should find a solution here : stackoverflow.com/a/50055155/3412316
@Kiruahxh: but note that the solution is a band aid that won't resist a reboot (/var/run will be cleared). The root cause of the problem is a mismatch between client and server about where to connect, which is a configuration issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.