diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 70edafa..df386a3 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -9129,7 +9129,12 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
 	{
 		XLogRecPtr	slotSegNo;
 
-		XLByteToSeg(keep, slotSegNo);
+		/*
+		 * If we are just at the beginning of a segment, the previous segment
+		 * might required by the next replication connection. So preserve
+		 * extra one segment for the case.
+		 */
+		XLByteToSeg(keep - 1, slotSegNo);
 
 		if (slotSegNo <= 0)
 			segno = 1;
