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
And I get this error 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?
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.
“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.
If you are trying to connect to a Postgres instance on the same host as your terminal, you can run lsof -p :5432 which will show which, if any, processes are listening on that port. The postgres process should be connected there. You can also look at the listen_address and port value in your postgresql.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With