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 ?
“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.
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.
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.
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