Fix SQLite database is locked errors
Understand locks and avoid unsafe database changes.
Step-by-step instructions
- Check whether another application or transaction is using the database.
- Close unnecessary connections and finish pending transactions. Do not forcibly delete journal or WAL files.
- Retry the operation after the writer finishes. In your own application, consider a suitable busy timeout and shorter transactions.
- If the database belongs to a running service, use its supported backup or maintenance workflow.
SQL example
Adapt example table names to your database.
PRAGMA busy_timeout = 5000;