# The database refuses connections with "Too many connections"

UrbeStack sysadmin note about MariaDB. Last updated 30 Nov 2026.

MariaDB refuses site and client connections with `ERROR 1040 (08004): Too many connections` when it reaches `max_connections`, which defaults to `151`. To fix it, find what holds the connections and raise the limit if the server has enough memory.

## Symptoms

Clients receive this error when they try to connect.

```output
ERROR 1040 (08004): Too many connections
```

WordPress and other applications show their database connection errors at the same time.

## Cause

MariaDB accepts up to `max_connections` connections at once. The distribution sets it to `151`, and UrbeStack leaves that value to you.

A slow query, a site under heavy load, or connections an application leaves open can fill the available slots.

## Resolution

Run these commands as root to see the peak number of simultaneous connections since MariaDB started and what holds the connections now. MariaDB allows one additional connection for an administrator.

```
mariadb -N -e "SHOW GLOBAL STATUS LIKE 'Max_used_connections'"
mariadb -e "SHOW PROCESSLIST"
```

In the process list, the `User` and `db` columns show which site holds each connection. The `Time` column shows how long each has run.

Each connection uses memory. Raise the limit only as far as the server's memory allows. This command raises it to `300` immediately, until MariaDB restarts.

```
mariadb -e "SET GLOBAL max_connections=300"
```

To keep the setting after a restart, add `max_connections = 300` under `[mysqld]` in `/etc/my.cnf.d/mariadb-server.cnf` on AlmaLinux or `/etc/mysql/mariadb.conf.d/50-server.cnf` on Ubuntu. Then run `urbestack-service-restart --name mariadb`.

If the problem persists after you follow this note, you can [open a support ticket](https://support.urbestack.com/new?type=support). Including the output of the commands you ran helps support diagnose the problem.
