SQLSTATE 08006 FATAL Class 08: Connection Exception

connection_failure could not connect to the primary server: connection refused — 08006

PostgreSQL error “could not connect to the primary server: connection refused — 08006” (SQLSTATE 08006): what it means, common causes, and how to fix it.

PG 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

Diagnostic Queries

Symptoms

A standby/replica could not connect to its primary server to stream WAL. The startup/walreceiver process reports SQLSTATE 08006 (connection_failure).

  • The replica’s walreceiver cannot reach the primary.
  • Replication stalls and the replica falls behind.
  • Often a primary down, wrong primary_conninfo, or firewall.

What the server log shows

FATAL:  could not connect to the primary server: connection to server at "10.0.0.5", port 5432 failed: Connection refused

Why PostgreSQL raises this — what the manual says

Section 26.2 Log-Shipping Standby Servers (Streaming Replication):

“If you want to use streaming replication, fill in primary_conninfo with a libpq connection string, including the host name (or IP address) and any additional details needed to connect to the primary server.”

A streaming replica opens a replication connection to the primary defined by primary_conninfo. If that connection is refused (primary down, wrong host/port, firewall), the walreceiver cannot stream WAL and reports 08006.

Common causes

  • The primary server is down or not accepting connections.
  • Wrong host/port in primary_conninfo.
  • Firewall/network blocking the replication port.

How to fix it

  1. Verify the primary is up and listening on the replication port.
  2. Check primary_conninfo host/port and credentials.
  3. Open firewalls and confirm the replica can reach the primary.

Related & next steps

Reference: PostgreSQL 18 Section 27.2 “Log-Shipping Standby”.

Was this helpful?