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

An SSL/TLS-encrypted connection was closed unexpectedly without a clean shutdown. The driver reports SQLSTATE 08006 (connection_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

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