Diagnostic Queries
Symptoms
The client could not open a connection because the server refused it at the network level. The driver reports SQLSTATE 08006 (connection_failure).
- Nothing is listening on the host/port, or it is blocked.
- Common with a stopped server or wrong host/port.
- A hint suggests checking host and port and that the server is accepting TCP/IP connections.
What the server log shows
could not connect to server: Connection refused
Is the server running on host "db.example.com" (203.0.113.10) and accepting
TCP/IP connections on port 5432?
Why PostgreSQL raises this — what the manual says
Section 18.3 Starting the Database Server:
“If there is in fact no server listening there, the kernel error message will typically be either Connection refused or No such file or directory, as illustrated.”
“Connection refused” means the OS actively rejected the TCP connection — typically nothing is listening on that host/port, or a firewall blocks it. The client cannot establish a session and reports 08006.
Common causes
- The PostgreSQL server is not running.
- Wrong host/port, or the server isn’t listening on that address (
listen_addresses). - A firewall blocking the port.
How to fix it
- Verify the server is running and listening on the expected port.
- Check
listen_addressesandportinpostgresql.conf. - Confirm host/port in the connection string and open the firewall.
Related & next steps
Reference: PostgreSQL 18 Section 19.3 “Starting the Server”.
Thanks — noted. This helps keep the database accurate.