Your Laravel app is running fine, then suddenly every request fails with FATAL: sorry, too many clients already. The database is up. The queries are normal. Nothing deployed. What changed is the number of open connections, and PostgreSQL has a hard ceiling on them. On RDS that ceiling is lower than most people expect, and a Laravel app with queues, workers, and a web server can hit it fast. Here is how to confirm it, buy time, and fix it properly.
What "too many clients" actually means
PostgreSQL allows a fixed number of simultaneous connections, controlled by the max_connections setting. Every connection is a backend process on the server, and each one uses memory. Once the limit is reached, new connections are refused with the "too many clients" error, no matter how simple the query would have been. The app does not slow down first. It just stops connecting.
On RDS, max_connections is not a number you pick freely. The default parameter group sets it from instance memory with the formula LEAST({DBInstanceClassMemory/9531392}, 5000). A small instance with 1 GB of RAM gets roughly 112 connections. A 4 GB instance gets roughly 450. That sounds like plenty until you count what actually connects.
Counting what connects to your database
A single Laravel app can open far more connections than you think. Count them:
- Each PHP-FPM worker holds one connection per request it serves.
- Each queue worker holds a persistent connection while it runs.
- Horizon supervisors spawn multiple worker processes per queue.
- Scheduled tasks, the web dashboard, and any console command each open their own.
- A deploy that restarts workers can briefly double the count while old and new processes overlap.
Ten FPM workers, eight queue workers, and a couple of scheduled jobs can already take 20 plus connections. Run two app servers or a staging copy against the same instance and the number doubles again.
Confirm it is the pool, not a slow query
Before changing anything, check the actual connection count. Connect with psql and run:
SELECT count(*), state FROM pg_stat_activity GROUP BY state;
If the total is close to max_connections and most rows are idle, the pool is exhausted by connections sitting open, not by work. If most rows are active with long-running queries, you have a slow query problem instead, and pooling will not fix it. A related post walks through reading PostgreSQL EXPLAIN ANALYZE to find the slow query.
On RDS you can also watch the DatabaseConnections metric in CloudWatch. A graph that climbs steadily and never comes down points at connections leaking or never closing, usually workers that never restart.
Quick fixes that buy time
If the site is down right now, the fastest relief is to kill idle connections and restart the workers:
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE state = 'idle'
AND state_change < now() - interval '10 minutes';
Then restart PHP-FPM and the queue workers so they reconnect cleanly. This is triage, not a fix. If the same pattern repeats, the connections will pile up again within hours. Also check that your app is not opening a connection per request and never closing it: in Laravel, make sure PDO::ATTR_PERSISTENT is not enabled unless you have a specific reason, since persistent connections survive across requests and quietly accumulate.
The durable fix: put a pooler in front of PostgreSQL
The real answer is connection pooling. A pooler keeps a small number of real connections to PostgreSQL and multiplexes many more client connections over them. Two options work well on AWS:
- RDS Proxy. A managed pooler from AWS. It sits between your app and the instance, reuses connections, and survives failovers better than a direct connection. It costs extra, but there is nothing to run or patch.
- PgBouncer. A lightweight, self-managed pooler you run on your EC2 instance or a small dedicated host. Transaction pooling mode gives the best reuse, but it only works if your app does not rely on session-level features such as prepared statements held across transactions or advisory locks.
Either way, point the Laravel DB_HOST at the pooler instead of the RDS endpoint and let it absorb the connection spikes.
Preventing it in Laravel
Pooling fixes the symptom at the database. The app side still matters:
- Cap your queue workers. Set the number of Horizon processes per queue deliberately instead of letting every queue scale without a ceiling.
- Restart workers on deploy with a
--max-jobsor--max-timelimit so long-lived processes do not accumulate stale connections. - Keep
DB_POOLstyle settings honest: one connection per worker is normal, but every extra supervisor, replica, or staging copy counts against the samemax_connections. - Set an RDS parameter group change deliberately. You can raise
max_connectionsin a custom parameter group, but each connection costs memory, so raising it without a pooler just moves the failure from "too many clients" to out-of-memory errors on a small instance.
Takeaway
"Too many clients" is a capacity error, not a query error. Check pg_stat_activity first to confirm the pool is the problem, terminate stale idle connections to restore service, then add a pooler such as RDS Proxy or PgBouncer and cap your worker counts so the connections stop piling up. The database is fine. It just needs fewer doors open at once.