SQLSTATE 08006 ERROR Class 08: Connection Exception

connection_failure SSL connection has been closed unexpectedly — 08006

PostgreSQL error "SSL connection has been closed 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

An SSL/TLS-encrypted connection was closed unexpectedly without a clean shutdown. The driver reports SQLSTATE 08006 (connection_failure).

  • The encrypted connection dropped abnormally.
  • Often a backend crash/restart or network drop on a TLS session.
  • Distinct from a TLS negotiation failure.

What the server log shows

SSL connection has been closed unexpectedly

Why PostgreSQL raises this — what the manual says

As Section 18.9 Secure TCP/IP Connections with SSL explains:

An encrypted (SSL/TLS) connection was torn down without a clean close-notify handshake — commonly caused by the peer process crashing, a network drop, or an idle/keepalive timeout closing the socket mid-session.

On a TLS connection, an abrupt break (without a proper close-notify) leaves the SSL session terminated unexpectedly. The client cannot continue and reports 08006.

Common causes

  • A backend crash, restart, or failover on a TLS session.
  • Network instability or a middlebox resetting the connection.
  • TLS renegotiation/timeouts on long-idle encrypted sessions.

How to fix it

  1. Reconnect and retry; handle dropped encrypted connections gracefully.
  2. Check the server log for crashes/terminations.
  3. Investigate network devices/load balancers and keepalive/idle settings.

Related & next steps

Reference: PostgreSQL 18 Section 19.9 “SSL”.

Was this helpful?