// 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. 许可详情 引用的错误消息文本归其数据库厂商所有。