diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index e729180..685a90b 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -3909,6 +3909,7 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
 	struct dirent *xlde;
 	char		switchseg[MAXFNAMELEN];
 	XLogSegNo	endLogSegNo;
+	char		path[MAXPGPATH];
 
 	XLByteToPrevSeg(switchpoint, endLogSegNo, wal_segment_size);
 
@@ -3948,9 +3949,14 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
 			 * - but seems safer to let them be archived and removed later.
 			 */
 			if (!XLogArchiveIsReady(xlde->d_name))
-				RemoveXlogFile(xlde->d_name, InvalidXLogRecPtr, switchpoint);
+			{
+				snprintf(path, sizeof(path), XLOGDIR "/%s", xlde->d_name);
+				if (unlink(path) == 0)
+					XLogArchiveCleanup(xlde->d_name);
+			}
 		}
 	}
+	(void) fsync_fname(XLOGDIR, true);
 
 	FreeDir(xldir);
 }
