FluentDBFluentDB
PostgreSQL errors

PostgreSQL: server closed the connection unexpectedly

ERRORSQLSTATE 08006connection_failure
server closed the connection unexpectedly

The connection dropped mid-request. The backend may have crashed (often the out-of-memory killer), been terminated by an admin or restart, or the socket was severed by a timeout or proxy. Check the server log for the real cause and add reconnect logic.

What this error means

This is a client-side message: the socket to the backend closed while a request was in flight, and the client cannot tell why, only that the server went away.

The true cause is in the server log: a crash (PANIC or a signal), an admin restart, an out-of-memory kill, or a proxy or timeout dropping an idle or long-running connection.

How to fix it

01

The backend crashed or was OOM-killed

Check the server log around the disconnect. If it was killed for memory, lower work_mem or add RAM.

text
-- look for PANIC, terminating, or a signal 9 in the Postgres log
02

A restart or failover terminated it

Expected during maintenance. Add reconnect and retry logic in your client or pool.

03

An idle or long connection was dropped

Set TCP keepalives, shorten idle_in_transaction_session_timeout, and check any proxy or load-balancer timeouts.

How to avoid it next time

  • Add reconnect and retry logic so restarts and failovers are transparent.
  • Right-size memory and set sane keepalive and timeout values.
Varies by version

This is a client-side libpq message with no server SQLSTATE. 08006 (connection_failure) is the nearest class. A clean admin termination instead arrives as 57P01 (admin_shutdown).

Frequently asked questions

How do I find why it closed?

The client cannot say. Read the Postgres server log around the timestamp; it records crashes, restarts, and terminations.

Is this a network or a server problem?

Either. A crash or OOM kill is server-side; a dropped idle socket is often a proxy or network timeout. The server log distinguishes them.

Stop struggling with SQL

Use FluentDB, the AI database client for macOS.