13

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?

1
  • Are you absolutely sure about your username and password? Commented Jun 27, 2015 at 18:00

5 Answers 5

16

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

Sign up to request clarification or add additional context in comments.

2 Comments

@ppardoz does this answer your question? Please mark it correct if it does.
Interesting edit. Postgres is definitely running and is allowing TCP connections on localhost. That sounds like it is on loopback or pg_hba.conf isn't allowing postgres to log in from remote hosts.
16

You have probably configured following two files

pg_hba.conf:

host all all 0.0.0.0/0 md5

postgresql.conf

listen_addresses='*'

You have to check if the port 5432 is open: http://www.yougetsignal.com/tools/open-ports/

If it's not then add a rule to your iptables:

iptables -A INPUT -s 0/0 -p tcp --dport 5432 -j ACCEPT

0/0: If you want anybody to access it.
You can change it to a specific ip address or range of ip addresses.

Comments

5

You have allow postgresql to accept request from outside network. To do that you have to change two files located at /etc/postgresql/{version_code}/main First one is pg_hba.conf, open and

change host all all ::1/128 md5 to host all all 0.0.0.0/0 md5

Second one is postgresql.conf, open and

change listen_address = 'localhost' to listen_address = '*'

Now restart the postgre server.

1 Comment

what if this has no effect?
2

In ubuntu 17.04 default port is 5433 check file postgresql.conf in path /etc/postgresql/9.6/main

Comments

0

I had the same issue, even thought had:

listen_address = '*'

when doing

netstat -anpt | grep LISTEN

there was nothing listening on port 5432.

The issue was in the pg_hba.conf* : I had configured the server to accept only local (socket) connection metching every host:

local   all      username       0.0.0.0/0               md5

changing local to host solved the issue

host   all      username       0.0.0.0/0               md5

Comments

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.