Database error "Too many connections": causes and fixes

For hosting customers · Updated 2026-10-29

On this page
  1. Symptoms
  2. Causes
  3. Fix
  4. Still not working?

Symptoms

  • A page shows SQLSTATE[HY000] [1040] Too many connections or WordPress shows "Error establishing a database connection" only at busy times.
  • A PostgreSQL app logs FATAL: too many connections for role "username_app".
  • The errors come and go, often during traffic peaks, imports or cron jobs.

Causes

  1. Many slow requests at the same time. Each PHP request that is still running keeps its database connection open.
  2. Persistent connections or a large connection pool in an application that keeps connections open while idle.
  3. Cron jobs or imports that open many connections or run for a long time.
  4. PostgreSQL: one user has 20 connections open. Each PostgreSQL user may have up to 20 at the same time.
  5. The whole database server is busy with all accounts on the server (MySQL).

Fix

Make pages lighter

  • For WordPress, turn on the page cache on the WordPress page (section Files): cached pages do not open a database connection at all.
  • Remove plugins that run slow queries on every page, and check Errors (section Advanced) for repeated database errors.

Use fewer connections in applications

  • Turn off persistent connections (PHP: do not use PDO::ATTR_PERSISTENT or mysqli p: hosts).
  • In Node.js or Python apps, set the connection pool to a small size, for example 5, and close connections you no longer need.
  • For PostgreSQL, keep the pool of all processes together under 20 per user, or give a second app its own user.

Spread out cron jobs and imports

Run heavy cron jobs less often or at quiet times, and import large files with the mysql command over SSH instead of many small requests.

Still not working?

If the error appears while your own site is quiet, the database server itself may be overloaded. Contact your hosting provider through Support with the time of the errors and the exact message.

Was this article helpful?

Still stuck?

Ask the AI about your exact situation — it answers from this knowledge base — or contact us.