08003ERRORTier 2 — Caution✅ HIGH confidenceconnection 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
- 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
How to reproduce
Application attempts to query on a connection the server already closed.
Fix 1: Discard and replace the stale connection
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
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.
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