// 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. 라이선스 세부 정보 인용된 오류 메시지 텍스트의 권리는 해당 데이터베이스 공급업체에 있습니다.