Postgres server not listening

Pablo Pardo picture Pablo Pardo · Jun 27, 2015 · Viewed 40.5k times · Source

I'm trying to connect with my client (Macbook Pro) to a Postgres Database located in another PC in the same network (Ubuntu) I can see the database from the host with pgAdmin, connecting to localhost, but I can't see from the client.

I've allowed all the connections in pg_hba.conf and postgresql.conf

I'm trying to connect from the client through pgAdmin to the IP server where the database is stored (192.168.1.34) and port 5432

enter image description here And I get this error enter image description here What do I'm doing wrong?

Am I missing something

After reading suggestions, I can say: On the ubuntu machine (home test server) I have no firewall. Postgres is running.

I've tried from the ubuntu console to access to the database: psql -h 127.0.0.1 mydatabase postgres and can connect (which means that the server is running and username is ok) But if I try to access the same database, from the same machine, changing localhost with the IP, I can not connect. Should not be psql -h 127.0.0.1 mydatabase postgres the same as psql -h 192.168.1.34 mydatabase postgres when I connect from the server?

Maybe is in loopback, as Alain suggested?

Answer

Alain O'Dea picture Alain O'Dea · Jun 27, 2015

It's not connecting so it's likely not listening on the right interface or is blocked by the firewall.

Is postgres running?

sudo service postgresql status

Is postgres listening on tcp/5432 on your LAN IP or 0.0.0.0 (all interfaces)?

netstat -anpt | grep LISTEN

It could be listening on 127.0.0.1 (loopback) only which means it can't be reached from the Mac.

If it's not listening or is on loopback check postgresql.conf for listen_addresses:

http://www.postgresql.org/docs/9.1/static/runtime-config-connection.html

Is there a firewall running on the Ubuntu box?

Make sure to allow inbound connections to tcp/5432 from the Mac's IP at minimum.

GUFW makes this easier to configure, but it can be done with iptables as well.

Further reference for the Ubuntu setup:

https://help.ubuntu.com/community/PostgreSQL