The connection to the PostgreSQL server was lost unexpectedly during an active transaction or query.
Common causes
1Network interruption between client and server
2PostgreSQL server ran out of memory and killed the backend process
3Server was forcibly restarted or crashed during query execution
4TCP timeout on long-running queries without keepalive configured
How to fix it
1Step 1: Check PostgreSQL server logs for OOM kills or panic messages.
2Step 2: Enable TCP keepalives on the connection (`keepalives_idle`, `keepalives_interval`).
3Step 3: Verify the network path is stable — check MTU, packet loss with `ping` or `traceroute`.
4Step 4: Add retry logic with exponential backoff in the data pipeline.
5Step 5: If queries are long-running, consider `statement_timeout` to avoid holding connections.
Example log output
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) SSL connection has been closed unexpectedly
DETAIL: server closed the connection unexpectedly — This probably means the server terminated abnormally before or while processing the request.
SQLSTATE: 08006
Frequently asked questions
How do I prevent 08006 errors in automated pipelines?
Add retry logic with exponential backoff, validate data quality before loading, and monitor pipeline failures in MetricSign to catch this error early.