// libSQL error reference

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.

Ошибка
too many connections
Категория
Remote server and Hrana errors
Сообщение об ошибке
Too many connections to the database

Что это значит

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.

Распространённые причины

  • 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.

Find the cause

Count concurrent clients: grep your code for `createClient` calls. One per request path is the bug. Then estimate concurrency: serverless platforms scale to many instances, each with its own pool, so multiply pool size by instance count and compare with the point where the refusals started. If connections climb over time and never fall, look for transactions opened without commit or rollback.

Как исправить

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

    // 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:

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

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

Other ways to handle it

HTTP-over-request connections (/v2/pipeline per request, no persistent session) sidestep the persistent-connection count at the cost of per-request latency. Batching statements also reduces the connection time per unit of work.

Безопасное воспроизведение

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.

Вопросы

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.

Связанные ошибки

More remote server and hrana errors errors

Код и текст сообщения взяты из libSQL / Turso documentation. Смотрите весь libSQL error list или поиск по всем ошибкам баз данных.

// меньше ошибок, быстрее исправления

Work on libSQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for libSQL and the other databases you use.

Текст и данные на этой странице: CC BY 4.0, с указанием SQLly (sqlly.app). Код и фрагменты SQL: MIT. Подробнее о лицензии Цитируемый текст сообщений об ошибках принадлежит производителю СУБД.