From 0d9bf706052f366df629c588c8f037569d311b15 Mon Sep 17 00:00:00 2001 From: "ZizhuanLiu(X-MAN)" <44973863@qq.com> Date: Sat, 13 Jun 2026 19:16:36 +0800 Subject: [PATCH v3] Keep the return value of XLogInsertRecord() for XLOG_SWITCH record consistent with other records patch v4 --- src/backend/access/transam/xlog.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d69d03b..cc79df2 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1027,8 +1027,14 @@ XLogInsertRecord(XLogRecData *rdata, */ if (inserted) { - EndPos = StartPos + SizeOfXLogRecord; - if (StartPos / XLOG_BLCKSZ != EndPos / XLOG_BLCKSZ) + EndPos = StartPos + MAXALIGN(SizeOfXLogRecord); + + /* + * If the XLOG_SWITCH record crosses a page boundary and actually has + * a part on the next page, we need to consider the page header. This + * is consistent with XLogBytePosToEndRecPtr(). + */ + if (StartPos / XLOG_BLCKSZ != (EndPos - 1) / XLOG_BLCKSZ) { uint64 offset = XLogSegmentOffset(EndPos, wal_segment_size); -- 2.43.0