DjangoPostgreSQLMySQL

Database connection pool exhaustion causes Connection refused errors

critical
Connection ManagementUpdated Aug 23, 2025(via Exa)
How to detect:

Django app randomly returns 'Connection refused' errors when connecting to database. Connection pool is exhausted due to connections not being closed properly. If CONN_MAX_AGE is set too high, connections never close and pool fills up.

Recommended action:

Check CONN_MAX_AGE setting: set to 0 for development, 60-300 seconds for production. Monitor active connections with `SELECT * FROM pg_stat_activity` (PostgreSQL) or `SHOW PROCESSLIST` (MySQL). Identify queries holding connections open and ensure proper connection cleanup in view code.