sqlite-snapshot-handle · shipping · also sqlite3_snapshot, SQLite Snapshot API

SQLite snapshot handle

A SQLite snapshot handle records a historical WAL-mode database state that a connection may reopen while the required history remains available.

Related Observatory article: Read on hesela.com

A handle identifies a WAL view, not a standalone database copy. It can outlive the history; snapshot_open can return SQLITE_ERROR_SNAPSHOT after checkpointing overwrites that history. [1] [3]

Capture requires autocommit off, WAL mode, no write transaction on the named schema and a transaction written to the current WAL. These APIs require SQLITE_ENABLE_SNAPSHOT at build time. [2]

Failed capture prerequisites leave the output pointer undefined; do not use or free it as a valid handle. Require SQLITE_OK before use; capture can also return SQLITE_NOMEM. [2]

If snapshot_get itself starts the read transaction, writers and checkpointers cannot invalidate its handle until that read ends. The documentation gives no such guarantee when a read was already open. An active read alone does not prove handle validity. [2]

Reopening requires autocommit off and a connection aware of WAL mode. Replacing an existing read requires no active SELECT statements. [3]

sqlite3_snapshot_cmp orders valid handles from the same database obtained since the last WAL deletion. Its sign is relative ordering, not a timestamp or global commit sequence. [5]

If a WAL remains after all database connections close, a new connection initially exposes only the last transaction in that WAL to snapshot_open, even when older valid transactions remain. sqlite3_snapshot_recover attempts to discover valid snapshots by rescanning that WAL; it cannot recreate missing history. The call requires WAL mode and no open read transaction on the target database. [6]

sqlite3_snapshot_free releases the allocated handle, not the application's read transaction. [4]

Relations

related
SQLite WAL end mark, Checkpoint starvation, SQLite Online Backup API

Citations

  1. SQLite C API: historical database snapshot object (accessed 2026-11-28)
  2. SQLite C API: snapshot capture prerequisites and conditional read-transaction protection (accessed 2026-11-28)
  3. SQLite C API: reopening a historical snapshot and error-state boundaries (accessed 2026-11-28)
  4. SQLite C API: destroying a snapshot object (accessed 2026-11-28)
  5. SQLite C API: snapshot comparison scope and WAL deletion boundary (accessed 2026-11-28)
  6. SQLite C API: discovering valid snapshots in a retained WAL (accessed 2026-11-28)
Sources & caveats
  • Primary API documentation reviewed on 2026-11-28. Documentation synthesis, not a native snapshot-API experiment, backup validation or performance measurement.

JSON: /data/terms/sqlite-snapshot-handle.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. SQLite snapshot handle. Hesela. 2026-11-28. https://hesela.dev/terms/sqlite-snapshot-handle/