PostgreSQL 08006: connection failure
The connection to the server broke during use. The server process ended, restarted or was killed, or the network dropped an idle connection.
- SQLSTATE
08006- Name
connection_failure- Category
- Connection Exception
What it means
08006 is a client-side code: drivers report it when an established connection fails mid-conversation. The server can't send an error over a connection that no longer works, so the message comes from the client library. libpq-based tools (psql, psycopg) print the message above, and PgJDBC reports SQLSTATE 08006 with An I/O error occurred while sending to the backend.
The server log usually explains it: a backend crash and restart, an out-of-memory kill, an administrator terminating the session, or nothing at all when a firewall or load balancer silently dropped an idle TCP connection.
Common causes
- The server process for the session crashed or was killed, often by the operating system's out-of-memory killer, which makes PostgreSQL restart all sessions.
- The server was restarted or failed over.
- A firewall, NAT gateway or cloud load balancer dropped a connection that was idle longer than its timeout.
- The session was terminated by
pg_terminate_backend()or an idle timeout, and the client only noticed on its next query.
How to fix it
-
Check the server log around the time of the failure for
terminated by signal,server process ... was terminated, or a restart. -
If an idle connection was dropped by the network, enable TCP keepalives on the server (or the client) so the connection never looks idle.
ALTER SYSTEM SET tcp_keepalives_idle = 60; ALTER SYSTEM SET tcp_keepalives_interval = 10; ALTER SYSTEM SET tcp_keepalives_count = 6; SELECT pg_reload_conf();
-
Configure the connection pool to validate or recycle connections before handing them out, and retry the operation once on a fresh connection when it is safe to do so.
-
If the server ran out of memory, find the query that used it and lower
work_memor the number of concurrent connections.
Related errors
57P01terminating connection due to administrator08001unable to establish connection53200out of memory2013MySQL: Lost connection to MySQL server during query2006MySQL: MySQL server has gone awayORA-03113Oracle: end-of-file on communication channel
The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.
Work on PostgreSQL in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.