Skip to main content

open_connection

Function open_connection 

Source
pub fn open_connection(path: &Path) -> Result<Connection>
Expand description

Open a SQLite connection with WAL mode and performance pragmas.

This is used by both the background writer (read-write) and the query engine (read-only). The pragmas are safe for both use cases.

§Pragmas

  • journal_mode = WAL: enables concurrent reads during writes.
  • synchronous = NORMAL: safe with WAL, ~3x faster than FULL. Acceptable durability trade-off for a local request log — at most one batch (200ms) of events could be lost on OS crash.
  • cache_size = -64000: 64MB page cache in memory. Improves read performance for repeated queries (e.g., --follow polling).
  • temp_store = MEMORY: temp tables and indexes in memory, not disk.
  • busy_timeout = 5000: wait up to 5s for locks instead of failing immediately. Prevents SQLITE_BUSY errors when CLI queries overlap with writer flushes.