Skip to main content

db_size_bytes

Function db_size_bytes 

Source
pub async fn db_size_bytes(pool: &SqlitePool) -> Result<i64>
Expand description

The used size of the SQLite database, in bytes, computed as (page_count - freelist_count) * page_size. Backs the DB-size watermark that disables new polling.

Subtracting the freelist is what keeps the watermark from latching the poller off: page_count counts pages the file has allocated, including ones freed by a DELETE but not yet returned to the OS (SQLite keeps them on a freelist for reuse and never shrinks the file without a VACUUM). Counting only the live pages means a retention prune (which frees pages, see reclaim) is actually reflected here, so the watermark can drop back below its threshold and polling resumes. Cheap (three PRAGMA reads); works for file + :memory:.

The WAL counts too. This is the number the DB-size watermark compares against a VOLUME size, and in WAL mode the -wal sidecar sits on that same volume — so leaving it out understated exactly the quantity the watermark exists to bound. It is added back below, best-effort: a WAL that cannot be stat’d contributes zero rather than failing the check, since a watermark that errors is worse than one that is slightly optimistic.