{
  "slug": "sqlite-data-version",
  "term": "SQLite data_version",
  "aliases": [
    "PRAGMA data_version",
    "PRAGMA schema.data_version"
  ],
  "definition": "SQLite data_version is a connection-local indicator of changes committed by other connections to a particular database.",
  "note": "Compare successive tokens on the same physical connection, database and uninterrupted attachment lifetime, not across pooled handles or reconnects. Own commits leave this PRAGMA unchanged. [sqlite-data-version]\n\nA retained WAL snapshot can keep returning old rows after another connection commits. A cache must not acknowledge a new monitor token using those older rows. Ending the read transaction permits a fresh snapshot. [sqlite-isolation] In controlled reconnect schedules, replacement handles reused the old number despite returning changed rows. An aux-only write changed aux.data_version but not main.data_version. [hesela-lifetime]\n\nDETACH followed by ATTACH starts another auxiliary-database lifetime. In controlled schedules, the same connection and pathname returned equal tokens despite changed rows after reattachment. Reset the baseline on successful reattachment; a schema alias is not an identity for all time. [sqlite-detach] [hesela-attachment]\n\nchanges() counts the most recent completed INSERT, UPDATE or DELETE on the caller, excluding auxiliary trigger changes; total_changes() accumulates completed row changes on that connection, including trigger work. Neither is a global committed-row ledger. [sqlite-changes] [sqlite-total] In controlled rollback cases, these counters stayed increased after the corresponding rows were restored. [hesela-observers]\n\nSQLITE_FCNTL_DATA_VERSION is a different interface that also detects same-connection modifications. These fixtures did not call that file-control API. [sqlite-file-control]",
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "related": [
    "sqlite-wal-end-mark",
    "sqlite-busy-snapshot",
    "sqlite-immutable",
    "write-ahead-log",
    "sqlite-integrity-check"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "citations": [
    {
      "id": "sqlite-data-version",
      "title": "SQLite: PRAGMA schema.data_version",
      "url": "https://www.sqlite.org/pragma.html#pragma_data_version",
      "accessed": "2026-10-20"
    },
    {
      "id": "sqlite-isolation",
      "title": "SQLite: Isolation and WAL snapshot lifetime",
      "url": "https://www.sqlite.org/isolation.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "sqlite-changes",
      "title": "SQLite: Count The Number Of Rows Modified",
      "url": "https://www.sqlite.org/c3ref/changes.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "sqlite-total",
      "title": "SQLite: Total Number Of Rows Modified",
      "url": "https://www.sqlite.org/c3ref/total_changes.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "hesela-observers",
      "title": "Hesela: controlled change-observer and rollback observations",
      "url": "https://hesela.dev/research/sqlite-change-observers/results.json",
      "accessed": "2026-10-20"
    },
    {
      "id": "hesela-lifetime",
      "title": "Hesela: controlled connection, schema and process observations",
      "url": "https://hesela.dev/research/sqlite-change-observers/lifetime-results.json",
      "accessed": "2026-10-20"
    },
    {
      "id": "hesela-analysis",
      "title": "SQLite WAL checkpoint starvation: change observers and application caches",
      "url": "https://hesela.com/analyses/sqlite-wal-checkpoint-starvation/#change-observers",
      "accessed": "2026-10-20"
    },
    {
      "id": "sqlite-file-control",
      "title": "SQLite: SQLITE_FCNTL_DATA_VERSION",
      "url": "https://www.sqlite.org/c3ref/c_fcntl_begin_atomic_write.html#sqlitefcntldataversion",
      "accessed": "2026-10-20"
    },
    {
      "id": "sqlite-detach",
      "title": "SQLite: DETACH and auxiliary database lifetime",
      "url": "https://www.sqlite.org/lang_detach.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "hesela-attachment",
      "title": "Hesela: same-connection attachment lifetime controls",
      "url": "https://hesela.dev/research/sqlite-change-observers/attachment-results.json",
      "accessed": "2026-10-20"
    }
  ],
  "provenance": [
    "Controlled results use SQLite 3.45.1 with recorded source ID; exact token values are not portable constants.",
    "Reconnection models physical-handle replacement, not a specific connection pool. No power-loss or concurrent-SQL stress test was performed.",
    "Attachment fixtures preserve one physical observer and test both same-file reattachment and a different database under the same alias; no connection pool or concurrent SQL was exercised."
  ],
  "updated": "2026-10-20"
}
