Databases allow a fixed number of connections at once, set by max_connections. "Too many connections" means they're all taken, so new requests are refused. Sometimes that's genuine traffic growth. More often the app is leaking connections: opening them and never closing them, or opening a new one for every request instead of reusing a pool. Raising the limit buys time; fixing the leak fixes it.
What's the problem
The site shows "Too many connections" (MySQL error 1040), PostgreSQL's too_many_connections error (code 53300), or a database connection error, usually at busy times or a while after a restart.
Why it happens
- Connection leak: code opens connections and doesn't release them, so they pile up.
- No connection pooling, especially with serverless functions, where each instance opens its own connections.
- Slow queries hold connections longer, so more are needed at once.
- A traffic spike or bots.
- A low limit on a small or shared database plan.
How to fix it
- See what's connected. In MySQL:
SHOW PROCESSLIST;. In PostgreSQL: querypg_stat_activity. Look for many idle connections from your app. - Fix leaks: make sure every connection is closed or returned to the pool, even when errors happen.
- Use a connection pool, and for serverless apps, a pooler such as PgBouncer or your provider's pooling service.
- Speed up slow queries so connections are freed faster.
- Then, if needed, raise
max_connectionsor move to a bigger database plan. Each connection uses memory, so don't just set it very high.
What Preventionlabs checks
One click runs the full report on your domain. For this problem it shows whether your site loads, how fast, and where its redirects go; uptime checked every 5 minutes, with an email when the site goes down and when it is back. With Cloudflare connected, it also shows which pages returned server errors (5xx) to visitors, and when; recent deploys and account changes, with their times. It can't connect to your database, so the database error itself is in your host's or database provider's logs.
Run your free reportYour first report is free, no card needed. Then A$50 a month, up to 10 domains. Read-only: it never changes anything.
Sources
- MySQL: Too many connectionsofficial docs
If clients encounter Too many connections errors when attempting to connect to the mysqld server, all available connections are in use by other clients.
- PostgreSQL: Connections and Authenticationofficial docs
Determines the maximum number of concurrent connections to the database server.
- MySQL: Server Error Message Referenceofficial docs
Error number: 1040 ; Symbol: ER_CON_COUNT_ERROR ; SQLSTATE: 08004 Message: Too many connections
- PostgreSQL: PostgreSQL Error Codesofficial docs
53300 too_many_connections