https://www.sqlite.org/lockingv3.html

I have read through the attached link but what is outlined here doesn't
seem to match with what I am seeing in a production SQLite setup we have.
Specifically the writer starvation part of the document.

We have a DB that is heavily read. Writes happen very infrequently. We were
finding that writes were failing with "Database locked" (SQLITE_BUSY I
believe) from time to time.

To reproduce I execute continuous reads in a tight loop. Then I tried to
execute a write operation (create table) and received database locked.

After a bit of reading and troubleshooting I stumbled across the
busy_timeout option (which defaults to 0). Prior to execute the create
table statement I set PRAGMA busy_timeout=1000 (1 s) and the writes always
succeeded.

So since busy_timeout defaults to 0, all write attempts if a lock can't be
obtained will return SQLITE_BUSY immediately. Where does the PENDING lock
come into play here? I thought the PENDING was meant to be an intermediary
step before EXCLUSIVE. Does the busy_timeout impact the writers attempt to
obtain PENDING? Or does the busy_timeout trigger after X amount of ms
between obtaining PENDING and trying to move to EXCLUSIVE?

Thanks
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to