SQLSTATE 08006 ERROR Class 08: Connection Exception

connection_failure could not connect to server: Connection refused — 08006

PostgreSQL error "could not connect to server: Connection refused" (SQLSTATE 08006): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. Verify the server is running and listening on the expected port.
  2. Check listen_addresses and port in postgresql.conf.
  3. Confirm host/port in the connection string and open the firewall.

Related & next steps

Reference: PostgreSQL 18 Section 19.3 “Starting the Server”.

Was this helpful?