server closed the connection unexpectedly

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

Symptoms

The client’s connection to the server was dropped unexpectedly mid-session. The driver reports SQLSTATE 08006 (connection_failure).

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

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