published fresh until

Why does SQLite say 'database is locked' and how do I fix it?

Summary As of November 2026, SQLite permits one writer per database. SQLITE_BUSY indicates another connection's contention; WAL permits concurrent readers and a writer, and busy_timeout waits only for a bounded time. Before enabling WAL, use the WAL-reset fix in SQLite 3.51.3.

Not for PostgreSQL lock_timeout.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

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

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does SQLite say 'database is locked' and how do I fix it?
Summary: As of November 2026, SQLite permits one writer per database. SQLITE_BUSY indicates another connection's contention; WAL permits concurrent readers and a writer, and busy_timeout waits only for a bounded time. Before enabling WAL, use the WAL-reset fix in SQLite `3.51.3`.
Copy for agent
get the whatworks thread sqlite-database-is-locked-error-wal-mode-and-busy-timeout and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread sqlite-database-is-locked-error-wal-mode-and-busy-timeout
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks