// libSQL error reference

SQLITE_BUSY: SQLITE_BUSY: the database is busy

A write could not start or commit because another connection held the lock: on remote writes this is one writer contending with itself across connections.

오류
SQLITE_BUSY
이름
5
카테고리
Local SQLite errors
오류 메시지
SQLITE_BUSY

의미

SQLITE_BUSY (5) means SQLite could not get the lock it needed because another connection was using the database. On a local file that is classic multi-process contention. On a remote libSQL server the same code surfaces when writes contend at the server, because sqld is still SQLite underneath with one writer at a time. The libsql JS client renders it as SQLITE_BUSY: database is locked.

일반적인 원인

  • Two connections wrote to the same remote database at once and one lost the race.
  • A local file was opened by more than one process.
  • No busy_timeout was set, so SQLite gave up instead of waiting.
  • A long transaction held the write lock past other clients' patience.

Find the cause

Look at the timing: a busy error under concurrent writes that goes away with retries is ordinary contention, and busy_timeout plus backoff is the fix. One that never clears points at a stuck transaction: check for long-open `BEGIN` blocks in your code, and on a local file check `lsof` for other processes. On remote databases, correlate the error timestamps with your request concurrency.

해결 방법

  1. On a local file, set a busy timeout so SQLite waits out short contention. On a remote Turso database the pragma is not supported, so retries with backoff are the mechanism there:

    PRAGMA busy_timeout = 5000;
    // @libsql/client local file: createClient({ url: 'file:local.db', timeout: 5000 })
  2. Retry failed writes with backoff instead of hammering:

    for (let i = 0; i < 5; i++) {
      try { await db.execute('UPDATE t SET v = v + 1 WHERE id = 1'); break; }
      catch (e) {
        if (!String(e).includes('SQLITE_BUSY')) throw e;
        await new Promise(r => setTimeout(r, 100 * 2 ** i));
      }
    }
  3. Batch writes so a burst commits as one operation instead of many lock races:

    await db.batch([
      'UPDATE a SET x = 1',
      'UPDATE b SET y = 2'
    ]);
  4. On a local file, find who else holds it open:

    lsof mydata.db

Other ways to handle it

Serialize writes through a single connection or queue. For remote databases, batches reduce the number of write transactions and so the number of races. PRAGMA journal_mode=WAL helps local file concurrency for readers but does not remove the single-writer rule, and Turso Cloud does not allow changing the journal mode at all.

안전하게 재현하세요

Local, honest: in one sqlite3 shell run `BEGIN; INSERT INTO t VALUES (1);` and leave it open. In another shell run `INSERT INTO t VALUES (2);` and it returns `database is locked` (SQLITE_BUSY). Needs any scratch file: `sqlite3 scratch.db 'CREATE TABLE t (a);'`. The remote flavor reproduces with two @libsql/client connections writing concurrently to the same test database.

질문

Does PRAGMA busy_timeout work on Turso Cloud?

No. Turso's limitations page lists busy_timeout as not supported: the cloud manages concurrency internally and the pragma has no effect. For remote writes, retry with backoff instead; for local file: databases the pragma works, and @libsql/client's timeout option sets the same thing.

Why do I get SQLITE_BUSY on an embedded replica but not on the remote database?

The replica is a local SQLite file with one writer at a time, so local lock rules apply on top of the remote behavior. See the embedded-replica-locked entry: two processes or a sync during a local write are the usual causes.

SQLITE_BUSY와 SQLITE_LOCKED의 차이점은 무엇입니까?

BUSY means the commit-level write lock was held by another connection; LOCKED means a needed table-level lock (often a shared-cache conflict) was unavailable. On remote libSQL servers the code that surfaces is SQLITE_BUSY.

관련 오류

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