troubleshooting#postgres#database#scaling
PostgreSQL: Too Many Connections
The classic Postgres scaling wall — and how PgBouncer solves it.
Problem
Application errors with `FATAL: sorry, too many clients already` under load.
Step-by-step Solution
- 1Check current limit: `SHOW max_connections;` (default 100).
- 2See who's connected: `SELECT usename, state, count(*) FROM pg_stat_activity GROUP BY 1,2;`.
- 3Kill idle-in-transaction sessions older than 5 minutes with `pg_terminate_backend()`.
- 4Introduce **PgBouncer** in transaction pooling mode — one physical connection serves many clients.
- 5Set app-side pool size (e.g., HikariCP maximumPoolSize) to a small number like 10–20 per instance.
- 6Add `idle_in_transaction_session_timeout = '5min'` to `postgresql.conf`.
- 7Monitor with `pg_stat_activity` and alert when connection usage exceeds 70% of the cap.
See problem and step-by-step solution above.
Keep reading
You may also like
troubleshooting
Kubernetes Pod stuck in CrashLoopBackOff
A methodical checklist to diagnose and fix crash-looping pods in production.
Read
troubleshooting
K8s Errors Part 3: Cluster / Storage / RBAC / Autoscale
The remaining 20 errors — RBAC, HPA not scaling, PVC pending, ETCD sadness, cert expiry, quotas and more.
Read
troubleshooting
Nginx 502 Bad Gateway after Deploy
Nine times out of ten it's one of these five issues — here's how to isolate them.
Read
Discussion (0)
No comments yet. Be the first to weigh in.