diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7d34218..3fd4b4e 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5838,8 +5838,16 @@ StartupXLOG(void) } /* Save the selected TimeLineID in shared memory, too */ - XLogCtl->ThisTimeLineID = ThisTimeLineID; - XLogCtl->PrevTimeLineID = PrevTimeLineID; + { + /* use volatile pointer to prevent code rearrangement */ + volatile XLogCtlData *xlogctl = XLogCtl; + + SpinLockAcquire(&xlogctl->info_lck); + XLogCtl->ThisTimeLineID = ThisTimeLineID; + XLogCtl->lastReplayedTLI = ThisTimeLineID; + XLogCtl->PrevTimeLineID = PrevTimeLineID; + SpinLockRelease(&xlogctl->info_lck); + } /* * We are now done reading the old WAL. Turn off archive fetching if it