What this thread does
Do first: Identify the SQLite result code and use a WAL-reset-fixed release, such as 3.51.3, before changing journal mode.
Short answer
The message database is locked maps to SQLITE_BUSY, which indicates contention with another connection; SQLITE_LOCKED concerns the same connection or shared cache. SQLite still allows only one writer in WAL mode. A busy timeout waits for locks, while transaction structure determines when write contention is encountered.
What to do
1. Finish active statements and transactions. An implicit transaction ends when its last active statement finishes; closing the cursor or resetting/finalizing the statement guarantees completion. Explicit transactions normally require COMMIT or ROLLBACK. 2. When a transaction will write, use BEGIN IMMEDIATE rather than plain BEGIN to acquire the write transaction up front. It can itself return SQLITE_BUSY. Plain BEGIN defaults to DEFERRED; upgrading an existing reader can fail if another connection has modified the database. 3. On same-host storage, enable PRAGMA journal_mode=WAL;. A fresh database defaults to journal_mode=DELETE; successful conversion returns wal. Readers and a writer can proceed together, but writers still serialize. 4. Configure PRAGMA busy_timeout = milliseconds; for the connection, or use sqlite3_busy_timeout(sqlite3*, int ms). Supply your own waiting budget in milliseconds; the sources give no universal recommended duration. The PRAGMA maximum is 2147483647 milliseconds. For the C API, ms <= 0 disables busy handlers; after the waiting budget it returns SQLITE_BUSY. Only one busy handler exists per connection, so another handler can be replaced.
Before WAL use, account for the WAL-reset fix: likely affected versions run from 3.7.0 (2010-07-21) through 3.51.2 (2026-01-09). The fix is in 3.51.3 (2026-03-13) and later, with backports 3.44.6 and 3.50.7. It concerns simultaneous write/checkpoint activity on multiple connections to the same WAL database.
Limits and open questions
WAL requires all processes on the same host and does not support a network filesystem. It can still return SQLITE_BUSY. Waiting does not add another writer. No waiting duration, driver setting or workload-specific retry policy was established here.
Not for: PostgreSQL lock_timeout.
Sources
- SQLite: result codes
- SQLite: transaction control
- SQLite: WAL and WAL-reset fix
- SQLite: busy_timeout PRAGMA
- SQLite: busy-timeout C API
Checked
2026-11-17: read SQLite's result-code, transaction, WAL, busy_timeout PRAGMA and busy-timeout C API pages and the official repository's error-message table; no command was run.
Started from a post by @SQLite documentation, packaged by the editor. Original post