ConnectionThresholdReached
Runbook: ConnectionThresholdReached Alert
Alert Details
- Alert Name: ConnectionThresholdReached
- Expression:
sum without (datname, datid) (pg_stat_database_numbackends{datname!~"template.*"}) / (sum without (server) (pg_settings_max_connections)) * 100 >= 80
Description
This alert triggers when the currently established connections to a database host is equal or higher than 80% of the possible maximum connections of the server. If connections reach 100% (MaxConnectionsReached), new connection attempts will be rejected entirely, causing application errors.
Possible Causes
- Connection pool misconfiguration — pool size set too high relative to
max_connections - Connection leak in application code — connections opened but never closed
- Sudden traffic spike creating more connections than usual
- Long-running idle transactions holding connections open
- Missing or misconfigured connection pooler (PgBouncer)
Troubleshooting Steps
1. Check current connection count and the configured limit
|
|
2. Break down connections by database, user, and state
|
|
Look for:
- A single
application_nameoruserholding an unexpectedly large share of connections - Many connections in
idlestate — these are open but doing nothing and can often be closed - Connections in
idle in transaction— these hold locks and should be investigated first
3. Identify long-running idle connections
|
|
4. Terminate idle connections to free up capacity
Terminate connections that have been idle for more than a threshold (adjust interval as needed):
|
|
Note: Only terminate idle connections, not active ones. For idle in transaction connections, refer to the HighTransactionFailRate runbook.
5. Increase max_connections if the workload genuinely requires it
For RDS/Aurora, max_connections is a parameter group setting — it cannot be changed with ALTER SYSTEM:
- AWS Console → RDS → Parameter Groups → select the group for the affected instance → search
max_connections→ modify the value - Changes require a reboot of the instance to take effect
- Check available memory first: each PostgreSQL connection consumes roughly 5–10 MB of RAM. Increasing
max_connectionswithout sufficient memory causes swapping and degrades performance significantly. The default formula for RDS isLEAST({DBInstanceClassMemory/9531392}, 5000).
6. Long-term: add a connection pooler
If this alert recurs, the recommended fix is to add PgBouncer in front of PostgreSQL. PgBouncer multiplexes many application connections onto a smaller number of real server connections, keeping PostgreSQL’s connection count low regardless of application concurrency.
Additional resources
- Related alert: MaxConnectionsReached
- Related alert: HighTransactionFailRate