busy_timeout
Milliseconds to keep retrying when the database is locked by another connection, instead of failing with SQLITE_BUSY.
- Default
0- Range
- 0 or more ms
- Restart needed
- No
- Default checked on
- SQLite 3.5x
What it does
Equivalent to calling sqlite3_busy_timeout(). Without it, a second writer fails immediately with 'database is locked'.
Default value
0. 0 in the C library (a stock SQLite 3.5x build). Wrappers differ: Python's sqlite3 module opens connections with a 5000ms timeout.
Check the current value
PRAGMA busy_timeout; SELECT * FROM pragma_busy_timeout; -- table-valued form, usable in queries
Change it
PRAGMA busy_timeout = 5000; -- this connection only
No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.
When to change it
In every application with more than one connection or process writing to the same file.
What can go wrong
Too long makes requests hang behind a long write transaction; it also cannot resolve the deadlock of two readers upgrading to writers (use BEGIN IMMEDIATE for write transactions).
The closest setting on other engines
| Engine | Setting | Default | Restart |
|---|---|---|---|
| SQLite |
busy_timeout this page
|
0 |
No |
| PostgreSQL |
lock_timeout
|
0 (disabled) |
No |
| MySQL |
innodb_lock_wait_timeout
|
50 |
No |
| SQL Server |
LOCK_TIMEOUT
|
-1 (wait forever) |
No |
Questions about busy_timeout
What is the default value of busy_timeout in SQLite?
0. 0 in the C library (a stock SQLite 3.5x build). Wrappers differ: Python's sqlite3 module opens connections with a 5000ms timeout.
Does changing busy_timeout require a restart?
No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.
When should I change busy_timeout?
In every application with more than one connection or process writing to the same file.
Back to all SQLite settings, or check the SQLite manual for every option.
Check busy_timeout on your own server
SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.