PG
PRO
08003ERRORTier 2 — Caution✅ HIGH confidence

connection does not exist

Category: Connection ExceptionVersions: All Postgres versions

What this means

SQLSTATE 08003 is raised when a client attempts to use a connection that no longer exists on the server — typically because the server closed or reset it, or because the client holds a stale reference.

Why it happens

  1. 1Server-side connection timeout closed the connection while the client still holds the handle
  2. 2Server restarted or was shut down while connections were open
  3. 3Network failure severed the connection without the client detecting it
  4. 4Application holding a connection from a pool that was already evicted

How to reproduce

Application attempts to query on a connection the server already closed.

trigger — this will ERROR
ERROR: connection does not exist

Fix 1: Discard and replace the stale connection

On receiving 08003, immediately.

fix

Why this works

Close the stale connection object and obtain a fresh connection from the pool or reconnect.

Fix 2: Set tcp_keepalives_idle to detect dead connections earlier

In production to reduce the window where stale connections go undetected.

fix
SET tcp_keepalives_idle = 60;

Why this works

TCP keepalives probe the connection and surface failures sooner, reducing the chance of using a dead connection.

What not to do

Retry on the same connection after 08003

Why it's wrong: The connection is gone server-side; all operations on it will fail.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 08 — Connection Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE. Behaviour consistent across all versions.

See also

📄 Reference pages

tcp_keepalives_idlePgBouncer
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →