# too many connections: Too many connections to one database

> The database hit its concurrent connection limit: pools opening unbounded connections per request are the usual cause.

Source: https://sqlly.app/errors/libsql/too-many-connections
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Error: `too many connections`
- Category: Remote server and Hrana errors

Error message:

```text
Too many connections to the database
```

## What it means

A remote database can only carry so many simultaneous connections, and the server refuses new ones past that point. Each serverless request that creates a fresh client counts as a new connection, so a function-per-request setup can blow through the limit even at modest traffic. This is a connection-count limit, distinct from the 429 request-rate limit, though both come from unbounded client fan-out.

## Common causes

- Creating a new client per request instead of reusing one.
- A connection pool sized far above what the database plan allows.
- Connections left open by interactive transactions that never committed or rolled back.
- Many serverless instances each holding their own pool.

## How to fix it

1. Create the client once at module scope and reuse it:

   ```sql
   // module scope, not per request
   export const db = createClient({ url: process.env.LIBSQL_URL, authToken: process.env.LIBSQL_TOKEN });
   ```
2. Shrink pool sizes to something the plan can carry:

   ```sql
   // generic pool config
   { max: 5 }
   ```
3. Always close or roll back interactive transactions, including on error:

   ```sql
   const tx = await db.transaction('write');
   try { await tx.execute(sql); await tx.commit(); }
   catch (e) { await tx.rollback(); throw e; }
   ```

## Reproduce it safely

```sql
Honest repro needs a real database and opening more connections than the plan allows, which can disturb other users, so I would use a dedicated test database: open a loop of `createClient(...)` connections without closing them until the server refuses. Exact refusal message varies by client; the observable is new connections failing while existing ones still work. `turso dev` has no such limit.
```

## How SQLly helps

SQLly holds one connection per open tab, so it is never the cause, but it is a clean probe: if SQLly connects fine while your service gets refused, your service's pool or per-request clients are what exhausted the limit.

## Questions

### Should I create a new @libsql/client for every request?

No. Create it once at module scope and reuse it; each new client is a new connection, and a fresh client per request in a serverless function multiplies into hundreds of connections under load.

### How many concurrent requests does @libsql/client make at once?

Up to 20 by default; the `concurrency` config option raises or removes the limit. Keep it aligned with what the database tolerates instead of disabling it.

### How is this different from a 429?

429 throttles request rate; this refuses new connections while existing ones still work. Both trace back to unbounded fan-out: per-request clients and pools sized for a different database.

## Related errors

- [`429 Too Many Requests`](https://sqlly.app/errors/libsql/rate-limited-429): request rate limit hit
- [`connection reset / interrupted`](https://sqlly.app/errors/libsql/connection-interrupted): Connection reset or dropped
- [`SQLITE_BUSY`](https://sqlly.app/errors/libsql/busy): SQLITE_BUSY: the database is busy

The code and message text are from the [libSQL / Turso documentation](https://docs.turso.tech/).
