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:
- Detect closed connections and reconnect before issuing queries.
- Validate connections on checkout from the pool (health-check query).
- Align client, pooler, and server idle timeouts so none closes a connection the others still hold.
- Do not cache long-lived connections across requests without a liveness check.
Reference: PostgreSQL error codes — Class 08 (Connection Exception).
Thanks — noted. This helps keep the database accurate.