// SQLite error reference

SQLITE_BUSY_SNAPSHOT: stale read can't become a write

In WAL mode, a transaction that started by reading tried to write after another connection had already changed the database. Waiting won't help; restart the transaction.

Result code
SQLITE_BUSY_SNAPSHOT
Name
517
Category
Extended result codes
Error message
database is locked

What it means

SQLITE_BUSY_SNAPSHOT (517) happens only on WAL-mode databases. A read transaction sees a snapshot of the database. If it then tries to write, SQLite must upgrade it to a write transaction, but if another connection committed changes after the snapshot was taken, the earlier reads are out of date and the upgrade is refused.

Unlike plain SQLITE_BUSY, a busy timeout doesn't fix this: the transaction must be rolled back and run again from the start.

Common causes

  • BEGIN (deferred) followed by SELECT and then UPDATE, while another process commits in between.
  • Long read transactions in an application that later decides to write.

How to fix it

  1. Start transactions that will write with BEGIN IMMEDIATE, so the write lock is taken before any reads.

    BEGIN IMMEDIATE;
    SELECT balance FROM accounts WHERE id = 1;
    UPDATE accounts SET balance = balance - 10 WHERE id = 1;
    COMMIT;
  2. When it does happen, roll back and retry the whole transaction.

    ROLLBACK;

Related errors

More extended result codes errors

The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.

// fewer errors, faster fixes

Work on SQLite in SQLly

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