Robert White
Robert White

Reputation: 71

Postgresql: Unable to connect through psql at console to default localhost

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.

Upvotes: 7

Views: 41824

Answers (3)

Daniel Vérité
Daniel Vérité

Reputation: 61666

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.

Upvotes: 1

errata
errata

Reputation: 26962

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

psql -h localhost -p 5432 

Upvotes: 11

Muhammad Taqi
Muhammad Taqi

Reputation: 5424

Default Admin Login sudo -u postgres psql

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

Upvotes: 4

Related Questions