Skip to main content

Module maintenance

Module maintenance 

Source
Expand description

Upkeep for a long-lived SQLite database: query-planner statistics and consistent snapshots.

Both work on any pool, so an application that keeps its own tables in the same file as the run store (as the aidaemon daemon does) maintains the whole file with one call.

use aidaemon_store_sqlite::maintenance::{optimize, snapshot, Optimize};

optimize(&pool, Optimize::AtOpen).await?;       // once, after migrations
optimize(&pool, Optimize::Periodic).await?;     // every few hours
snapshot(&pool, "backups/app.db".as_ref()).await?;

Enums§

Optimize
When optimize runs.

Constants§

ANALYSIS_LIMIT
Rows sampled per index when statistics are gathered. Bounds the cost of an analysis on a large table to milliseconds, as SQLite recommends for PRAGMA optimize; the estimates stay good enough to pick indexes.

Functions§

optimize
Gather the query planner’s statistics where they are missing or stale.
snapshot
Write a consistent, compacted copy of the database to destination with VACUUM INTO, while other connections keep reading and writing.