Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to postgres from remote host

Tags:

postgresql

I have a database server (192.168.1.50) running postgres. I have created a database named "testdb" and a user "testuser" with password "testuserpw".
Locally, I can connect to the db using:

psql -d testdb -U testuser 

When I issue the command from another host (192.168.1.60):

psql -h 192.168.1.50 -d testdb -U testuser 

I have the error:

psql: could not connect to server: Connection refused Is the server running on host "192.168.1.50" and accepting TCP/IP connections on port 5432? 

Any idea ?

like image 275
Luc Avatar asked May 27 '11 10:05

Luc


People also ask

Can't connect to PostgreSQL database?

“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.

How do I connect to PostgreSQL database host?

1) Connect to PostgreSQL database server using psql 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.


1 Answers

Check the setting of listen_addresses in your postgresql.conf file. Many distributions make it default to 127.0.0.1, i.e. listen only to connections coming in from localhost. It should be set to '*' to listen for connections on all interfaces.

If you are still having trouble, use lsof to see what network sockets the postgres process is listening on.

like image 139
araqnid Avatar answered Sep 28 '22 17:09

araqnid