The 'production-ready opener' worth memorizing
Most production Python apps using SQLite end up with a small connection-opening helper that sets a fixed list of PRAGMAs every time. The list, with rationale:
journal_mode = WAL— concurrent readers/writers (track 4).synchronous = NORMAL— safe with WAL, faster than FULL.foreign_keys = ON— actually enforce FKs (track 4).busy_timeout = 5000— wait briefly on transient locks instead of failing.temp_store = MEMORY— keep temp B-trees in RAM rather than disk.cache_size = -64000— 64 MB page cache for read-heavy workloads.mmap_size = 134217728— 128 MB memory-mapped I/O for fast reads on large files.
Self-reference: Pippa's
backend/store/conversations.py opens every connection with this exact set (with project-tuned cache and mmap sizes). The fact that the WebUI feels instant on a 100k-row JSONL+SQLite history is largely down to these seven settings.