Return value of XLogInsertRecord() for XLOG_SWITCH record

cca5507 <cca5507@qq.com>

From: cca5507 <cca5507@qq.com>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-13T08:47:38Z
Lists: pgsql-hackers

Attachments

Hi,

I find that the return value of XLogInsertRecord() for XLOG_SWITCH record
is inconsistent with other records.

For XLOG_SWITCH record:

```
		/*
		 * Even though we reserved the rest of the segment for us, which is
		 * reflected in EndPos, we return a pointer to just the end of the
		 * xlog-switch record.
		 */
		if (inserted)
		{
			EndPos = StartPos + SizeOfXLogRecord;
			if (StartPos / XLOG_BLCKSZ != EndPos / XLOG_BLCKSZ)
			{
				uint64		offset = XLogSegmentOffset(EndPos, wal_segment_size);

				if (offset == EndPos % XLOG_BLCKSZ)
					EndPos += SizeOfXLogLongPHD;
				else
					EndPos += SizeOfXLogShortPHD;
			}
		}
```

It is equivalent to XLogBytePosToRecPtr(), but all other records use XLogBytePosToEndRecPtr().

No actual problem found yet, but I think it's better to keep them consistent. Thoughts?

--
Regards,
ChangAo Chen

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Undo thinko in commit e78d1d6d4.

  2. Fix orphaned processes when startup process fails during PM_STARTUP