{
  "slug": "log-sequence-number",
  "term": "Log sequence number",
  "aliases": [
    "LSN"
  ],
  "definition": "A log sequence number is an engine-defined identifier that orders log-related records or operations, without universally encoding their physical log positions.",
  "note": "PostgreSQL represents an LSN as a byte offset in WAL. Insert, write and durable-flush positions have different meanings: knowing an LSN does not establish that its record is durable. In PostgreSQL, subtracting compatible positions gives bytes, not transaction count or elapsed time; retain the engine, timeline and observed progress stage when comparing positions. XFS instead encodes a 32-bit cycle and 32-bit block position; the latter counts 512-byte basic blocks. [xfs-design] [log-format] Raw encoded subtraction across cycles is not a byte-distance calculation.\n\nAn equal numeric LSN after a history fork is not proof of equal WAL contents. Cluster identity and timeline ancestry are separate from this byte position. [pg-timelines]\n\nLogical order: Deuteronomy assigns operation LSNs before execution and logs completed operations at separate physical log positions. Concurrent nonconflicting operations can reach the log out of LSN order. Its stable-log frontier therefore covers a completed prefix, not merely the highest LSN present on disk. [deuteronomy]",
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "related": [
    "write-ahead-log",
    "database-checkpoint",
    "replication-lag",
    "synchronous-replication",
    "asynchronous-replication",
    "compensation-log-record",
    "page-lsn",
    "xfs-relogging",
    "postgresql-timeline",
    "timeline-history-file",
    "llama",
    "stasis"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "citations": [
    {
      "id": "pg-internals",
      "title": "PostgreSQL 18: WAL Internals",
      "url": "https://www.postgresql.org/docs/18/wal-internals.html",
      "accessed": "2026-10-12"
    },
    {
      "id": "pg-functions",
      "title": "PostgreSQL 18: Backup Control Functions, Table 9.97 and notes",
      "url": "https://www.postgresql.org/docs/18/functions-admin.html#FUNCTIONS-ADMIN-BACKUP",
      "accessed": "2026-10-12"
    },
    {
      "id": "hesela-wal",
      "title": "WAL, checkpoints and torn pages: three different recovery guarantees",
      "url": "https://hesela.com/analyses/wal-checkpoints-torn-pages/",
      "accessed": "2026-10-12"
    },
    {
      "id": "pg-lsn",
      "title": "PostgreSQL 18: pg_lsn type",
      "url": "https://www.postgresql.org/docs/18/datatype-pg-lsn.html",
      "accessed": "2026-10-12"
    },
    {
      "id": "pg-timelines",
      "title": "PostgreSQL 18: timeline history and recovery branches",
      "url": "https://www.postgresql.org/docs/18/continuous-archiving.html#BACKUP-TIMELINES",
      "accessed": "2026-10-12"
    },
    {
      "id": "hesela-replication",
      "title": "Replication acknowledgements: received, durable, applied",
      "url": "https://hesela.com/analyses/replication-acknowledgements-durability-lag/",
      "accessed": "2026-10-12"
    },
    {
      "id": "xfs-design",
      "title": "Linux v6.16: XFS Logging Design, log space accounting and re-logging",
      "url": "https://github.com/torvalds/linux/blob/v6.16/Documentation/filesystems/xfs/xfs-delayed-logging-design.rst",
      "accessed": "2026-10-16"
    },
    {
      "id": "log-format",
      "title": "Linux v6.16: xfs_log_format.h, CYCLE_LSN and BLOCK_LSN",
      "url": "https://github.com/torvalds/linux/blob/v6.16/fs/xfs/libxfs/xfs_log_format.h",
      "accessed": "2026-10-16"
    },
    {
      "id": "hesela-xfs",
      "title": "Hesela: XFS delayed logging and commit boundaries",
      "url": "https://hesela.com/analyses/xfs-delayed-logging-commit-boundaries/",
      "accessed": "2026-10-16"
    },
    {
      "id": "deuteronomy",
      "title": "Levandoski, Lomet, Mokbel and Zhao. Deuteronomy: Transaction Support for Cloud Data. CIDR 2011, pp. 123-133; sections 4.5-4.5.2.",
      "url": "https://www.cidrdb.org/cidr2011/Papers/CIDR11_Paper14.pdf",
      "accessed": "2026-11-15"
    }
  ],
  "updated": "2026-11-15"
}
