diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ff73816708..a518a7182d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -9521,13 +9521,13 @@ GetWALAvailability(XLogRecPtr targetLSN) if (XLogRecPtrIsInvalid(targetLSN)) return WALAVAIL_INVALID_LSN; - currpos = GetXLogWriteRecPtr(); - /* - * calculate the oldest segment currently reserved by all slots, - * considering wal_keep_segments and max_slot_wal_keep_size + * Calculate the oldest segment currently reserved by all slots, + * considering wal_keep_segments and max_slot_wal_keep_size. Initialize + * oldestSlotSeg to the current segment. */ - XLByteToSeg(targetLSN, targetSeg, wal_segment_size); + currpos = GetXLogWriteRecPtr(); + XLByteToSeg(currpos, oldestSlotSeg, wal_segment_size); KeepLogSeg(currpos, &oldestSlotSeg); /* @@ -9546,6 +9546,9 @@ GetWALAvailability(XLogRecPtr targetLSN) else oldestSegMaxWalSize = 1; + /* the segment we care about */ + XLByteToSeg(targetLSN, targetSeg, wal_segment_size); + /* * No point in returning reserved or extended status values if the * targetSeg is known to be lost. @@ -9622,7 +9625,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) } /* don't delete WAL segments newer than the calculated segment */ - if (XLogRecPtrIsInvalid(*logSegNo) || segno < *logSegNo) + if (segno < *logSegNo) *logSegNo = segno; }