SQLite Forum

PRAGMA wal_checkpoint(RESTART) unexpectedly returning SQLITE_BUSY immediately
Login
That's it. Setting `PRAGMA wal_autocheckpoint=0;` on every connection resolves the issue and lets `PRAGMA wal_checkpoint(RESTART);` succeed reliably. (I did see a single SQLITE_BUSY in my load test, but there is a lot of code involved and I am investigating if I accidentally created a connection inappropriately.)

Turns out this is [well-documented](https://www.sqlite.org/c3ref/wal_checkpoint_v2.html), I somehow missed it.

> All calls obtain an exclusive "checkpoint" lock on the database file. If any other process is running a checkpoint operation at the same time, the lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a busy-handler configured, it will not be invoked in this case.

Thank you Dan!