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

Source: https://sqlly.app/errors/libsql/busy
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: `SQLITE_BUSY`
- Name: `5`
- Category: Local SQLite errors

Error message:

```text
SQLITE_BUSY
```

## What it means

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

## Common causes

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

## How to fix it

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:

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

   ```sql
   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:

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

   ```sql
   lsof mydata.db
   ```

## Reproduce it safely

```sql
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.
```

## How SQLly helps

SQLly runs your retry loop's steps one statement at a time, so you can reproduce the contention deliberately: hold a transaction open in one SQLly tab and write to the same table from another to see SQLITE_BUSY on a local file.

## Questions

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

### What is the difference between SQLITE_BUSY and 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.

## Related errors

- [`SQLITE_BUSY: database is locked`](https://sqlly.app/errors/libsql/embedded-replica-locked): embedded replica file locked
- [`429 Too Many Requests`](https://sqlly.app/errors/libsql/rate-limited-429): request rate limit hit
- [`too many connections`](https://sqlly.app/errors/libsql/too-many-connections): Too many connections to one database

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