Postgresql 中文操作指南

8.20. pg_lsn Type #

pg_lsn 数据类型可用于存储指向 WAL 中位置的 LSN(日志连续号)数据。此类型是对 XLogRecPtr 和 PostgreSQL 的内部系统类型的表示。

The pg_lsn data type can be used to store LSN (Log Sequence Number) data which is a pointer to a location in the WAL. This type is a representation of XLogRecPtr and an internal system type of PostgreSQL.

在内部,LSN 是一个 64 位整数,表示写前日志流中的字节位置。它以两个十六进制数字打印,每个数字最多 8 位,中间用斜杠分隔;例如 16/B374D848pg_lsn 类型支持标准比较运算符,例如 =>。可以用 - 运算符减去两个 LSN;结果是分隔这些写前日志位置的字节数。同样也可以用 +(pg_lsn,numeric)-(pg_lsn,numeric) 运算符中减去 LSN 中的字节数。请注意,计算出的 LSN 应在 pg_lsn 类型的范围内,即 0/0FFFFFFFF/FFFFFFFF 之间。

Internally, an LSN is a 64-bit integer, representing a byte position in the write-ahead log stream. It is printed as two hexadecimal numbers of up to 8 digits each, separated by a slash; for example, 16/B374D848. The pg_lsn type supports the standard comparison operators, like = and >. Two LSNs can be subtracted using the - operator; the result is the number of bytes separating those write-ahead log locations. Also the number of bytes can be added into and subtracted from LSN using the +(pg_lsn,numeric) and -(pg_lsn,numeric) operators, respectively. Note that the calculated LSN should be in the range of pg_lsn type, i.e., between 0/0 and FFFFFFFF/FFFFFFFF.