Independent technical referenceOfficial site
  • Software and digital services
  • Databases

08006

PostgreSQL 08006 connection_failure: active session link broke

Verified with sources3 sourcesReviewed Oct 19, 2026
Technician coming? See the 2 steps they must show you
Trace

Risk level

High

Professional inspection is recommended.

Urgency

Medium

Quick answer

SQLSTATE 08006 (connection_failure) means an already established PostgreSQL connection broke during use. Note the disconnect timestamp, check server health with pg_isready, and verify whether any in-flight write committed before retrying.

Safety first

Stop and check this first

  • Never automatically retry a non-idempotent write statement after 08006 if it ran outside an explicit BEGIN ... COMMIT block; the backend may have finished and committed the statement before noticing the client disconnection.
  • Never use kill -9 (SIGKILL) on PostgreSQL server processes or delete WAL files to recover from hung connections; use pg_terminate_backend() for a single session or pg_ctl for a clean server shutdown.

Safe checks you can perform

  • Correlate the disconnect timestamp with pg_isready and server logs
  • Check whether the interrupted command ran inside a transaction block
  • Review TCP keepalive and tcp_user_timeout settings on client and server

Leave these tasks to a qualified professional

  • Do not attempt this professional task: Tune TCP keepalives and client_connection_check_interval for network intermediaries
  • Do not attempt this professional task: Implement clean connection replacement and idempotent transaction retry logic

What a technician must be able to justify

Technician visit

These are the steps they must carry out and show you. Tick them as they work: if steps are skipped, do not accept a part swap.

These are not instructions for opening or handling the equipment yourself. They are the checks that should support a technical conclusion.

  1. Tune TCP keepalives and client_connection_check_interval for network intermediaries

    What they doHave the DBA and developer set server and libpq keepalives_idle, keepalives_interval, keepalives_count, and tcp_user_timeout below the idle timeout of any firewall or load balancer, and configure client_connection_check_interval where supported.

    They must show youthe SHOW output for all TCP keepalive settings on the server and the matching libpq connection parameters.

    In writingthe exact keepalives_idle, keepalives_interval, keepalives_count, and tcp_user_timeout values deployed on server and client.

  2. Implement clean connection replacement and idempotent transaction retry logic

    What they doHave the application developer close broken handles with PQfinish or reset them with PQreset when 08006 occurs, wrap multi-step writes in explicit BEGIN and COMMIT blocks, and verify outcome state before replaying interrupted autocommit writes.

    They must show youthe error-handling code path that replaces CONNECTION_BAD handles and checks write completion before retrying.

    In writingthe recovery procedure and transaction boundary rules adopted for Class 08 connection failures.

Before accepting a part or repair

Nothing has been shown yet. Do not accept a part swap based on the code alone.

Follow these steps

Note: Follow the documented order. An error code identifies the affected system, but it does not prove by itself which part has failed.

  1. Correlate the disconnect timestamp with pg_isready and server logs

    Tools required

    Who:
    Your DBA or platform engineer compares client and server logs around the disconnect timestamp.
    How:
    Run pg_isready against the server and inspect PostgreSQL logs for administrator shutdown signals (SIGTERM, SIGINT, SIGQUIT), pg_terminate_backend calls, or backend crash recovery messages at the exact failure time.
    Result that matters:
    Before closing a session for a fast shutdown or administrative termination, the backend attempts to send an error or notice message giving the reason for disconnection.
    If the server log records a fast shutdown, pg_terminate_backend, or child process exit at that timestamp, that confirms the backend terminated the session.
    If the server remained up with zero backend termination entries and pg_isready returns 0, that rules out a cluster restart and points to an intermediate network, proxy, or firewall drop.
    Evidence to keep:
    Keep the correlated client error log, server log excerpt, and PQbackendPID if logged.

    Redact connection strings, query parameter values, and personal data before sharing server or client log excerpts.

    Evidence: PostgreSQL server shutdown · PostgreSQL 18 libpq connection status functions · PostgreSQL 18 pg_isready · PostgreSQL 18 protocol message flow

  2. Check whether the interrupted command ran inside a transaction block

    No special tools

    Who:
    Your developer inspects the transaction boundary of the failed request and queries the target rows on a fresh connection.
    How:
    Determine whether the disconnected session had issued an explicit BEGIN without COMMIT, or was running a standalone autocommit statement outside a transaction block.
    Result that matters:
    The protocol guarantees that any open transaction block is rolled back on abnormal termination, whereas a non-SELECT query outside BEGIN and COMMIT may finish and commit before the backend detects the disconnect.
    If the statement was inside an uncommitted BEGIN block, that confirms the server rolled back the transaction when the connection closed.
    If the statement ran outside any transaction block, that indicates its changes might have committed before the socket drop was recognized and requires checking the target rows before retrying.
    Evidence to keep:
    Record the transaction status, the verification SELECT result, and the request idempotency key.

    Evidence: PostgreSQL 18 frontend/backend protocol overview · PostgreSQL 18 protocol message flow

  3. Review TCP keepalive and tcp_user_timeout settings on client and server

    No special tools

    Who:
    Your DBA and developer inspect socket keepalive parameters on both ends in read-only mode.
    How:
    Check server values for tcp_keepalives_idle, tcp_keepalives_interval, tcp_keepalives_count, tcp_user_timeout, and client_connection_check_interval, and compare them with libpq keepalives, keepalives_idle, keepalives_interval, keepalives_count, and tcp_user_timeout.
    Result that matters:
    By default, server TCP keepalive parameters are 0 (using operating system defaults, or 2 hours idle and 1 second interval on Windows) and client keepalives default to 1 (on).
    If intermediate load balancers or firewalls drop idle TCP flows earlier than tcp_keepalives_idle, that points to silent NAT state expiration causing 08006 on the next query.
    If tcp_user_timeout is set to a very small millisecond value on a congested link, that suggests premature socket closure during transient packet delay.
    Evidence to keep:
    Save the output of SHOW tcp_keepalives_idle, SHOW tcp_keepalives_interval, SHOW tcp_keepalives_count, and SHOW tcp_user_timeout.

    Evidence: PostgreSQL database connection control functions · PostgreSQL connection settings

Still not solved

If the error persists, stop here. See what the technician must do and show you.

Virtual technician

Does 08006 still appear after these checks?

This guided flow uses the exact code and your answers to choose a test, an expected result and the next branch.

Where this code applies

A code is meaningful only inside the right product and version context.

Primary scope

System
Software and digital services
Brand
PostgreSQL
Product type
Databases

Known code variants

  • connection_failure
  • PostgreSQL 08006
  • SQLSTATE 08006

What it means

PostgreSQL Appendix A assigns 08006 to connection_failure under Class 08 Connection Exception. The protocol documentation describes mid-session connection loss from a broken communications link, an administrator-commanded fast shutdown or backend termination, a process crash at either end, or an unacknowledged TCP stream timed out by keepalives or tcp_user_timeout. When a session terminates abnormally, PostgreSQL rolls back any open transaction block, though an autocommit write outside BEGIN and COMMIT may finish before the backend notices the drop. Code 08006 alone does not prove whether the network, proxy, or server failed.

Warnings and stop conditions

  • Highsource verified

    Never automatically retry a non-idempotent write statement after 08006 if it ran outside an explicit BEGIN ... COMMIT block; the backend may have finished and committed the statement before noticing the client disconnection.

    Evidence: PostgreSQL 18 protocol message flow

  • Highsource verified

    Never use kill -9 (SIGKILL) on PostgreSQL server processes or delete WAL files to recover from hung connections; use pg_terminate_backend() for a single session or pg_ctl for a clean server shutdown.

    Evidence: PostgreSQL server shutdown

Symptoms and causes

Probable causes · in order

  • Communications link drop or idle NAT/firewall timeout between endpointsCommon

    A lost network path, proxy reset, or expired unacknowledged transmission closes the socket mid-session, requiring both frontend and backend to abandon the broken connection.

    Evidence: PostgreSQL connection settings · PostgreSQL 18 protocol message flow

  • Administrator fast shutdown (SIGINT) or pg_terminate_backend signalPossible

    When the server receives SIGINT for a fast shutdown or a session receives SIGTERM via pg_terminate_backend(), the backend aborts current transactions, sends a notice or error message, and closes the connection.

    Evidence: PostgreSQL server shutdown · PostgreSQL 18 protocol message flow

  • TCP keepalive or tcp_user_timeout threshold exceeded on an unresponsive peerPossible

    If tcp_keepalives_count keepalive probes go unacknowledged or transmitted data remains unacknowledged past tcp_user_timeout, the operating system or libpq forcibly closes the TCP connection.

    Evidence: PostgreSQL database connection control functions · PostgreSQL connection settings

  • Backend or client process crash or authentication_timeout during handshakeLess common

    A core dump at either endpoint or failing to complete authentication within authentication_timeout (default 1m) causes immediate connection closure.

    Evidence: PostgreSQL connection settings · PostgreSQL 18 protocol message flow

Sources and technical references

  1. 1

    PostgreSQL 18 Appendix A: Error Codes

    PostgreSQL Global Development Group · 2026 · official_doc

  2. 2

    PostgreSQL error and notice fields

    PostgreSQL Global Development Group · 2026 · official_doc

  3. 3

    PostgreSQL database connection control functions

    PostgreSQL Global Development Group · 2026 · official_doc

Sources: PostgreSQL 18 Appendix A: Error Codes · PostgreSQL error and notice fields · PostgreSQL database connection control functionsreviewed 2026-10-19 · verified

Was this entry useful?