*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 5110,5125 **** exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
  	UpdateMinRecoveryPoint(InvalidXLogRecPtr, true);
  
  	/*
! 	 * We should have the ending log segment currently open.  Verify, and then
! 	 * close it (to avoid problems on Windows with trying to rename or delete
! 	 * an open file).
  	 */
! 	Assert(readFile >= 0);
! 	Assert(readId == endLogId);
! 	Assert(readSeg == endLogSeg);
! 
! 	close(readFile);
! 	readFile = -1;
  
  	/*
  	 * If the segment was fetched from archival storage, we want to replace
--- 5110,5123 ----
  	UpdateMinRecoveryPoint(InvalidXLogRecPtr, true);
  
  	/*
! 	 * If the ending log segment is currently open, close it (to avoid
! 	 * problems on Windows with trying to rename or delete an open file).
  	 */
! 	if (readFile >= 0)
! 	{
! 		close(readFile);
! 		readFile = -1;
! 	}
  
  	/*
  	 * If the segment was fetched from archival storage, we want to replace
***************
*** 5974,5979 **** StartupXLOG(void)
--- 5972,5980 ----
  	EndOfLog = EndRecPtr;
  	XLByteToPrevSeg(EndOfLog, endLogId, endLogSeg);
  
+ 	Assert(readId == endLogId);
+ 	Assert(readSeg == endLogSeg);
+ 
  	/*
  	 * Complain if we did not roll forward far enough to render the backup
  	 * dump consistent.  Note: it is indeed okay to look at the local variable