diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 6bc1a6b46d..91203faeee 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2383,6 +2383,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) int npages; int startidx; uint32 startoffset; + XLogSegNo first_seg_to_finish = 0; + int num_segs_to_finish = 0; + int i; /* We should always be inside a critical section here */ Assert(CritSectionCount > 0); @@ -2545,7 +2548,13 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) LogwrtResult.Flush = LogwrtResult.Write; /* end of page */ if (XLogArchivingActive()) - XLogArchiveNotifySeg(openLogSegNo); + { + if (num_segs_to_finish == 0) + first_seg_to_finish = openLogSegNo; + + Assert(openLogSegNo == first_seg_to_finish + num_segs_to_finish); + num_segs_to_finish++; + } XLogCtl->lastSegSwitchTime = (pg_time_t) time(NULL); XLogCtl->lastSegSwitchLSN = LogwrtResult.Flush; @@ -2616,6 +2625,9 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible) LogwrtResult.Flush = LogwrtResult.Write; } + for (i = 0; i < num_segs_to_finish; i++) + XLogArchiveNotifySeg(first_seg_to_finish + i); + /* * Update shared-memory status *