could not connect to the primary server: connection refused

SQLSTATE 08006 condition connection_failure class 08 — Connection Exception severity FATAL
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 11 Jun 2026 · Reproduced live with the SQL on this page.

Symptoms

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

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

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”.