{
  "slug": "sqlite-snapshot-handle",
  "term": "SQLite snapshot handle",
  "aliases": [
    "sqlite3_snapshot",
    "SQLite Snapshot API"
  ],
  "definition": "A SQLite snapshot handle records a historical WAL-mode database state that a connection may reopen while the required history remains available.",
  "note": "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. [snapshot-object] [snapshot-open]\n\nCapture 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. [snapshot-get]\n\nFailed 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. [snapshot-get]\n\nIf 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. [snapshot-get]\n\nReopening requires autocommit off and a connection aware of WAL mode. Replacing an existing read requires no active SELECT statements. [snapshot-open]\n\nsqlite3_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. [snapshot-cmp]\n\nIf 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. [snapshot-recover]\n\nsqlite3_snapshot_free releases the allocated handle, not the application's read transaction. [snapshot-free]",
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "related": [
    "sqlite-wal-end-mark",
    "checkpoint-starvation",
    "sqlite-online-backup"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "citations": [
    {
      "id": "snapshot-object",
      "title": "SQLite C API: historical database snapshot object",
      "url": "https://sqlite.org/c3ref/snapshot.html",
      "accessed": "2026-11-28"
    },
    {
      "id": "snapshot-get",
      "title": "SQLite C API: snapshot capture prerequisites and conditional read-transaction protection",
      "url": "https://sqlite.org/c3ref/snapshot_get.html",
      "accessed": "2026-11-28"
    },
    {
      "id": "snapshot-open",
      "title": "SQLite C API: reopening a historical snapshot and error-state boundaries",
      "url": "https://sqlite.org/c3ref/snapshot_open.html",
      "accessed": "2026-11-28"
    },
    {
      "id": "snapshot-free",
      "title": "SQLite C API: destroying a snapshot object",
      "url": "https://sqlite.org/c3ref/snapshot_free.html",
      "accessed": "2026-11-28"
    },
    {
      "id": "snapshot-cmp",
      "title": "SQLite C API: snapshot comparison scope and WAL deletion boundary",
      "url": "https://sqlite.org/c3ref/snapshot_cmp.html",
      "accessed": "2026-11-28"
    },
    {
      "id": "snapshot-recover",
      "title": "SQLite C API: discovering valid snapshots in a retained WAL",
      "url": "https://sqlite.org/c3ref/snapshot_recover.html",
      "accessed": "2026-11-28"
    }
  ],
  "updated": "2026-11-28",
  "provenance": [
    "Primary API documentation reviewed on 2026-11-28. Documentation synthesis, not a native snapshot-API experiment, backup validation or performance measurement."
  ]
}
