additional_logs_1.patch

application/octet-stream

Filename: additional_logs_1.patch
Type: application/octet-stream
Part: 0
Message: Re: WAL segments removed from primary despite the fact that logical replication slot needs it.

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/access/transam/xlog.c 27 12
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a31fbbff78..09f49ac1a3 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6805,24 +6805,39 @@ CreateCheckPoint(int flags)
 	if (PriorRedoPtr != InvalidXLogRecPtr)
 		UpdateCheckPointDistanceEstimate(RedoRecPtr - PriorRedoPtr);
 
-	/*
-	 * Delete old log files, those no longer needed for last checkpoint to
-	 * prevent the disk holding the xlog from growing full.
-	 */
-	XLByteToSeg(RedoRecPtr, _logSegNo, wal_segment_size);
-	KeepLogSeg(recptr, &_logSegNo);
-	if (InvalidateObsoleteReplicationSlots(_logSegNo))
 	{
+		char		lastoff[MAXFNAMELEN];
+
 		/*
-		 * Some slots have been invalidated; recalculate the old-segment
-		 * horizon, starting again from RedoRecPtr.
+		 * Delete old log files, those no longer needed for last checkpoint to
+		 * prevent the disk holding the xlog from growing full.
 		 */
 		XLByteToSeg(RedoRecPtr, _logSegNo, wal_segment_size);
+		elog(LOG, "attempting to remove WAL segments older than log file %s before first KeepLogSeg, slotMinLSN: %X/%X",
+			lastoff, XLogGetReplicationSlotMinimumLSN());
 		KeepLogSeg(recptr, &_logSegNo);
+
+		XLogFileName(lastoff, 0, _logSegNo, wal_segment_size);
+
+		elog(LOG, "attempting to remove WAL segments older than log file %s according to first KeepLogSeg, slotMinLSN: %X/%X",
+			lastoff, XLogGetReplicationSlotMinimumLSN());
+		if (InvalidateObsoleteReplicationSlots(_logSegNo))
+		{
+			/*
+			 * Some slots have been invalidated; recalculate the old-segment
+			 * horizon, starting again from RedoRecPtr.
+			 */
+			XLByteToSeg(RedoRecPtr, _logSegNo, wal_segment_size);
+			KeepLogSeg(recptr, &_logSegNo);
+		}
+		_logSegNo--;
+		XLogFileName(lastoff, 0, _logSegNo, wal_segment_size);
+
+		elog(LOG, "attempting to remove WAL segments older than log file %s after invalidating required slots, slotMinLSN: %X/%X",
+			lastoff, lastoff, XLogGetReplicationSlotMinimumLSN());
+		RemoveOldXlogFiles(_logSegNo, RedoRecPtr, recptr,
+			checkPoint.ThisTimeLineID);
 	}
-	_logSegNo--;
-	RemoveOldXlogFiles(_logSegNo, RedoRecPtr, recptr,
-					   checkPoint.ThisTimeLineID);
 
 	/*
 	 * Make more log segments if needed.  (Do this after recycling old log