日志序列号在 postgres 中真的是单调的吗?

Is log sequence number really monotonic in postgres?

阅读 postgreSQL 文档时:

WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype pg_lsn. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.

我们可以相信这个序列号是严格单调的吗?是否存在将此偏移量重置为先前位置的时间点(由于 WAL 存档或其他类型的操作)?

严格单调但LSN指向某个段文件中的物理偏移量。

Isn't there a point in time where this offset resetting to a previous position (due to WAL archive, or another type of operations ) ?

有这么一个时间点但是在另一个segment文件中

此处仅供参考,是 PG 代码中的一个宏,它从 LSN (https://github.com/postgres/postgres/blob/master/src/include/access/xlog_internal.h) 中提取段号:

/*
 * Compute a segment number from an XLogRecPtr.
 ........
 */
#define XLByteToSeg(xlrp, logSegNo, wal_segsz_bytes) \
    logSegNo = (xlrp) / (wal_segsz_bytes)

来自 postgres documentation on wal internals(强调我的)

WAL records are appended to the WAL logs as each new record is written. The insert position is described by a Log Sequence Number (LSN) that is a byte offset into the logs, increasing monotonically with each new record. LSN values are returned as the datatype pg_lsn. Values can be compared to calculate the volume of WAL data that separates them, so they are used to measure the progress of replication and recovery.

WAL logs are stored in the directory pg_wal under the data directory, as a set of segment files, normally each 16 MB in size (but the size can be changed by altering the --wal-segsize initdb option). Each segment is divided into pages, normally 8 kB each (this size can be changed via the --with-wal-blocksize configure option). The log record headers are described in access/xlogrecord.h; the record content is dependent on the type of event that is being logged. Segment files are given ever-increasing numbers as names, starting at 000000010000000000000000. The numbers do not wrap, but it will take a very, very long time to exhaust the available stock of numbers.