DjangoPostgreSQLGunicorn

PostgreSQL connection count exceeds limits causing memory exhaustion

warning
Resource ContentionUpdated Mar 15, 2026(via Exa)
How to detect:

Every PostgreSQL connection consumes 5-10 MB for forked backend process. Django app with 20 Gunicorn workers × 4 threads = 80 connections. Multiple app servers can create 400-800 connections, causing PostgreSQL memory exhaustion and query latency spikes.

Recommended action:

Deploy PgBouncer in transaction mode as TCP proxy between Django and PostgreSQL. Configure pool size to 25-50% of PostgreSQL max_connections. Set Django CONN_MAX_AGE=0 to let PgBouncer manage connection reuse. Monitor pool saturation with SHOW POOLS command.