Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

postgresql

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.

like image 930
Robert White Avatar asked May 18 '15 16:05

Robert White


People also ask

How do I enable port 5432?

As an alternative you can go to Control Panel -> Systems and Security -> Windows Firewall -> Allow a program or feature through Windows Firewall -> Advanced Settings -> New Rule: Rule Type: Port. TCP or UDP: TCP. Specific local ports: 5432.

What is the default host for PostgreSQL?

Connecting to Your Database The PostgreSQL database service is available on localhost and the default PostgreSQL port is 5432 . A default user ( hosting-db ) and database ( postgres ) exist so you can quickly test your connection and perform management tasks.

How to connect to the PostgreSQL database server?

The following steps show you how to connect to the PostgreSQL database server via the psql program: First, launch the psql program and connect to the PostgreSQL Database Server using the postgres user: Second, enter all the information such as Server, Database, Port, Username, and Password.

How to fix PostgreSQL PSQL connection refused?

PostgreSQL psql: could not connect to server: Connection refused Step # 1: Allow remote IP address to access PostgreSQL. Now append following line. ... Please replace 192.168.1.0 and... Step # 2: Allow communication over TCP/IP. Save and close the file. Step # 3: Restart PostgreSQL server. This ...

How does PSQL connect to a localhost?

Whereas psql documentation says that: If you omit the host name, psql will connect via a Unix-domain socket to a server on the local host, or via TCP/IP to localhost on machines that don't have Unix-domain sockets.

What is the default port for Postgres server?

The default port is 5432. (If you are using Advanced Server this would be 5444.) This is the username that is created while the installation takes place. The default username for postgres is postgres.


1 Answers

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

psql -h localhost -p 5432 
like image 198
errata Avatar answered Oct 12 '22 19:10

errata