Psycopg 3 Migration

Django 4.2 adds Psycopg 3 support, the new PostgreSQL driver for Python. Psycopg 3 is async-capable, more performant, and offers better PostgreSQL type support. The backend is used with 'django.db.backends.postgresql' and psycopg (without the 2).

Configuration

python
# settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydb',
        'USER': 'myuser',
        'PASSWORD': 'mypassword',
        'HOST': 'localhost',
        'PORT': '5432',
        # Django auto-detects psycopg vs psycopg2
        # pip install psycopg[binary]  # Psycopg 3
        # pip install psycopg2-binary  # Psycopg 2 (legacy)
    }
}

# Check the version used
# python -c "import psycopg; print(psycopg.__version__)"

Sources