SQLite Database Is Locked: Fix SQLITE_BUSY
By Sharon Ben-Moshe · August 26, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Fix SQLite “database is locked” (SQLITE_BUSY) by finding long write transactions, setting a busy timeout, using WAL deliberately, and avoiding unsafe file access.
Quick answer
SQLite “database is locked” usually means a connection needs a lock that another connection holds. Keep write transactions short, configure an appropriate busy timeout, use WAL for the right workload, and distinguish SQLITE_BUSY from SQLITE_LOCKED before changing files.
FAQs
What is the difference between SQLITE_BUSY and SQLITE_LOCKED?
SQLITE_BUSY means SQLite could not obtain a lock because another connection or process holds an incompatible one. SQLITE_LOCKED is a different result code, typically a conflict within the same connection or shared-cache context. Capture the actual code before choosing a fix.
Does WAL mode fix SQLite database is locked?
WAL can let readers and a writer coexist more effectively in an appropriate setup, but SQLite still serializes writes. It cannot repair a long-running writer, a leaked transaction, or incompatible filesystem locking.
What does PRAGMA busy_timeout do?
PRAGMA busy_timeout configures how long a connection may wait when SQLite encounters a lock. It helps with brief, expected contention. It should accompany short transactions and correct connection lifecycle management, not replace them.
Should I delete a SQLite WAL or journal file to remove a lock?
No. Deleting SQLite journal, WAL, or shared-memory files while a database may be active can damage a working recovery or locking workflow. Stop and identify the process holding the database first; let SQLite manage its own files.
Keep reading
PostgreSQL Relation Does Not Exist: Fix 42P01
By Sharon Ben-Moshe · Aug 26, 2026
Fix PostgreSQL error 42P01 by checking the database, schema search path, exact identifier case, migrations, and object permissions.
Read postMySQL Error 1054: Fix “Unknown Column”
By Sharon Ben-Moshe · Aug 26, 2026
Fix MySQL ERROR 1054 (42S22) by checking table columns, aliases, clause visibility, identifier quoting, and the migration actually deployed.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.