SQLSTATE 08006 ERROR Class 08: Connection Exception

connection_failure server closed the connection unexpectedly — 08006

PostgreSQL error "server closed the connection unexpectedly" (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’s connection to the server was dropped unexpectedly mid-session. The driver reports SQLSTATE 08006 (connection_failure).

  • The connection ended without a clean close.
  • Often follows a backend crash, restart, or network drop.
  • May indicate the server terminated the backend.

What the server log shows

server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.

Why PostgreSQL raises this — what the manual says

As Section 32.1 Database Connection Control Functions explains:

This client-side message means the backend terminated the socket before completing the protocol exchange — commonly because the server process crashed, was shut down, or a connection limit or authentication step rejected the session mid-handshake.

When the TCP/socket connection breaks without a protocol-level close, the client reports 08006. This typically means the backend exited (crash, termination, or restart) or the network path failed.

Common causes

  • A backend crash or server restart/failover.
  • An admin terminating the session, or OOM killing the backend.
  • Network instability, idle timeouts, or a firewall closing the socket.

How to fix it

  1. Reconnect and retry; make the application resilient to dropped connections.
  2. Check the server log for crashes/terminations around the time it dropped.
  3. Investigate network/firewall idle timeouts; use TCP keepalives or a pooler.

Related & next steps

Reference: PostgreSQL 18 Section 34.1 “Connection Control”.

Was this helpful?