connection does not exist
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.
- 1Server-side connection timeout closed the connection while the client still holds the handle
- 2Server restarted or was shut down while connections were open
- 3Network failure severed the connection without the client detecting it
- 4Application holding a connection from a pool that was already evicted
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 = 60;
Why this works
TCP keepalives probe the connection and surface failures sooner, reducing the chance of using a dead connection.
✕ Retry on the same connection after 08003
The connection is gone server-side; all operations on it will fail.
Class 08 — Connection Exception
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev