SQLSTATE 08003 ERROR Class 08: Connection Exception

connection_does_not_exist Connection Does Not Exist — SQLSTATE 08003

The application tried to use a connection that is already closed.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

Symptoms

The application tried to use a connection that is already closed.

  • The error is written to the server log and returned to the client carrying SQLSTATE 08003.
  • Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
  • PL/pgSQL can trap it by name: EXCEPTION WHEN connection_does_not_exist THEN.

Environment

Severity: ERROR  |  PostgreSQL versions: 12, 13, 14, 15, 16, 17

Commonly coincides with restarts, failover, maintenance, or network events; check server uptime and the log around the timestamp.

Root Cause

The client issued a command on a connection object whose server-side backend no longer exists.

Common causes:

  • A pooler recycled or closed the backend.
  • The session timed out (idle_session_timeout).
  • A prior fatal error closed the connection.
  • The application cached a connection past its lifetime.

Diagnostic Queries

Recovery

Steps to resolve 08003:

  1. Detect closed connections and reconnect before issuing queries.
  2. Validate connections on checkout from the pool (health-check query).
  3. Align client, pooler, and server idle timeouts so none closes a connection the others still hold.
  4. Do not cache long-lived connections across requests without a liveness check.

Reference: PostgreSQL error codes — Class 08 (Connection Exception).

Was this helpful?