Appearance
Set busy_timeout before changing synchronous mode in SQLite
In SQLite, even with journaling mode set to WAL, only one connection can be writing to the database at each time. Thus setting the busy_timeout
is important, as if not set, SQLite will never wait for a lock to release, it will error out when it can't acquire a lock.
You should set this as the first pragma before changing other parameters as other pragmas might require a lock.
Sometimes you see people doing this
sql
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;
PRAGMA busy_timeout = 5000;
But changing synchronous
requires taking a lock! Set the busy_timeout
first instead
sql
PRAGMA busy_timeout = 5000; -- this first before any other PRAGMA
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;