A node-state receiver kept its last 48 hours of samples in SQLite and ran an hourly thread to delete older rows. The file was 304MB. The table held 521,840 rows spanning 21 days, of which 436,672 were past the retention window. The free-page count was zero. In twenty days the thread had never deleted a single row.

A one-word difference

The thread was started correctly. The server log had the answer, sixty times in a row at twenty past every hour: database table is locked. That message is SQLITE_LOCKED. The more familiar one, database is locked, is SQLITE_BUSY. The busy timeout that every careful SQLite client sets handles the second and does nothing for the first. Retry logic layered on top would not have helped either. That is why the failure rate was exactly 100% rather than mostly-working.

The cause was that the function returning a database connection ran the schema DDL every time it was called: create table if not exists, create index if not exists. With ingest requests arriving every five seconds, the retention thread's delete kept colliding with a DDL statement on the same table from another connection, and that collision is the one the timeout does not wait out.

The repair and its second surprise

The DDL moved to a one-time initialisation at startup. The journal switched to write-ahead mode so reads stop blocking writes. The delete was broken into batches of 5,000 with a short sleep between, because dropping 430,000 rows in one transaction would have blocked ingest for the duration. And the thread now logs success as well as failure, because for twenty days silence had been indistinguishable from health.

The first rotation deleted 436,672 rows. What remained was 85,702 rows covering 60.8 hours, against a rule of 48. That residue was a separate bug in how the cutoff timestamp was formatted, and it is its own story. With both fixed, effective retention measured 48.0 hours, a vacuum took the file from 288MB to 36MB, and both machines feeding the receiver kept sending throughout. Whether the hourly rollup would fold real data correctly at the next boundary was still to be observed.