LSN - Log Sequence Number

A 64-bit integer used to determine a position in WAL

An LSN (Log Sequence Number) is an unsigned 64-bit integer used to determine a position in WAL. Internally it is represented by the pointer type XLogRecPtr. Externally it's represented as two hexadecimal numbers of up to eight digits each separated by a slash.

Beginning with PostgreSQL 9.4, LSNs are represented as a discrete PostgreSQL data type, pg_lsn, which is used in many WAL-related functions.

To calculate the difference (in bytes) between two LSNs, from PostgreSQL 9.4 simply subtract one value from the other, casting to pg_lsn if necessary. The function pg_wal_lsn_diff() (PostgreSQL 9.6 and earlier: pg_xlog_location_diff()) can also be used for this.

  • PostgreSQL documentation: pg_lsn

Categories

PostgreSQL internals, WAL