Disk hygiene and memory tuning
Three knobs that affect SQLite performance at the storage layer:
- VACUUM — rebuilds the database file, reclaiming space from deleted rows and defragmenting the B-trees. Slow (writes the whole file), but periodically useful after big deletes.
- PRAGMA page_size = N — the unit of B-tree storage. Default 4096 bytes (post-3.12). Larger pages mean fewer I/O ops for sequential scans but more wasted space for small rows. Set before any tables are created — or run VACUUM after changing it.
- PRAGMA cache_size = N — the in-memory page cache. Negative values mean kibibytes (e.g., -64000 = 64 MB). Bigger cache = fewer disk hits.
Warning:
VACUUM requires up to 2x the database size in temporary disk space. On a 50 GB database, that's 100 GB free. Plan for it. auto_vacuum is an alternative that incrementalizes the work but has its own tradeoffs.