PostgreSQL Error 08003: Connection Does Not Exist

PostgreSQL error 08003 (Connection Does Not Exist) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

SQLSTATE 08003 PostgreSQL Last verified 2026-08-19

Quick Answer

Enable pool health checks / pre-ping so stale connections are recycled. If that does not apply, acquire a fresh connection from the pool on each request — the full checklist is below.

Error Code

SQLSTATE: 08003
Official name: Connection Does Not Exist
Service: PostgreSQL

What does this error mean?

The operation was attempted on a connection that does not exist (already closed or never opened).

Common Causes

How to Fix

  1. Enable pool health checks / pre-ping so stale connections are recycled
  2. Acquire a fresh connection from the pool on each request
  3. Avoid sharing a single connection across async tasks/threads
  4. Lower pool idle/recycle times so dead connections are reaped sooner

Code Examples

Pool with pre-ping python
from sqlalchemy import create_engine

engine = create_engine(
    url,
    pool_pre_ping=True,
    pool_recycle=300,
    pool_size=10,
    max_overflow=5,
)

pre_ping issues a cheap SELECT 1 before handing out a pooled connection, replacing dead ones that would raise 08003.

Framework-Specific Fixes

sqlalchemy

Use pool_pre_ping and pool_recycle to drop dead pooled connections before use.

engine = create_engine(url, pool_pre_ping=True, pool_recycle=300)
django

Set CONN_HEALTH_CHECKS=True and an appropriate CONN_MAX_AGE.

DATABASES = {'default': {
  'CONN_MAX_AGE': 60,
  'CONN_HEALTH_CHECKS': True
}}

You Might Also Like

Frequently Asked Questions

Why am I seeing PostgreSQL error 08003?

Most often this happens when reusing a connection object after it was closed by the pool, or when calling a query after a previous fatal error severed the connection.

How do I fix PostgreSQL error 08003?

Enable pool health checks / pre-ping so stale connections are recycled.

Which frameworks have documented fixes for error 08003?

This page documents fixes for: sqlalchemy, django.

Official Sources

This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.