08003
PostgreSQLERRORNotableConnection ExceptionHIGH confidence

connection does not exist

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.

expected output

ERROR:  connection does not exist

Fix 1

Discard and replace the stale connection

WHEN On receiving 08003, immediately.

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

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

Set tcp_keepalives_idle to detect dead connections earlier
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

The connection is gone server-side; all operations on it will fail.

Sources
Official documentation ↗

Class 08 — Connection Exception

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors