]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add assertions checking for the startup process in WAL replay routines
authorMichael Paquier <michael@paquier.xyz>
Wed, 5 Nov 2025 01:41:50 +0000 (10:41 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 5 Nov 2025 01:41:50 +0000 (10:41 +0900)
These assertions may prove to become useful to make sure that no process
other than the startup process calls the routines where these checks are
added, as we expect that these do not interfere with a WAL receiver
switched to a "stopping" state by a startup process.

The assumption that only the startup process can use this code has
existed for many years, without a check enforcing it.

Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/aQmGeVLYl51y1m_0@paquier.xyz

src/backend/access/transam/xlog.c
src/backend/access/transam/xlogrecovery.c

index 8c0d9dbfa8b61cbd995f9ba62bce5b89d7c0121c..9900e3e0179f711d085f8fe2593bf2c7235c50fa 100644 (file)
@@ -9518,6 +9518,8 @@ GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli)
 void
 XLogShutdownWalRcv(void)
 {
+       Assert(AmStartupProcess() || !IsUnderPostmaster);
+
        ShutdownWalRcv();
        ResetInstallXLogFileSegmentActive();
 }
index 0a5ae5050c461d2b2ee2fdef84e6872fbacfae5e..93c50831b260960593bdc15c77f4d8b69a4af9c3 100644 (file)
@@ -3148,6 +3148,8 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
        XLogReaderState *xlogreader = XLogPrefetcherGetReader(xlogprefetcher);
        XLogPageReadPrivate *private = (XLogPageReadPrivate *) xlogreader->private_data;
 
+       Assert(AmStartupProcess() || !IsUnderPostmaster);
+
        /* Pass through parameters to XLogPageRead */
        private->fetching_ckpt = fetching_ckpt;
        private->emode = emode;
@@ -3319,6 +3321,8 @@ XLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, int reqLen,
        int                     r;
        instr_time      io_start;
 
+       Assert(AmStartupProcess() || !IsUnderPostmaster);
+
        XLByteToSeg(targetPagePtr, targetSegNo, wal_segment_size);
        targetPageOff = XLogSegmentOffset(targetPagePtr, wal_segment_size);