Minor bug fix for pg_stop_backup() to prevent it waiting longer than
necessary in certain circumstances.

Was originally part of recovery_infrastructure patch.

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support
Index: src/backend/access/transam/xlog.c
===================================================================
RCS file: /home/sriggs/pg/REPOSITORY/pgsql/src/backend/access/transam/xlog.c,v
retrieving revision 1.319
diff -c -r1.319 xlog.c
*** src/backend/access/transam/xlog.c	23 Sep 2008 09:20:35 -0000	1.319
--- src/backend/access/transam/xlog.c	8 Oct 2008 13:17:24 -0000
***************
*** 6639,6651 ****
  	LWLockRelease(WALInsertLock);
  
  	/*
! 	 * Force a switch to a new xlog segment file, so that the backup is valid
  	 * as soon as archiver moves out the current segment file. We'll report
  	 * the end address of the XLOG SWITCH record as the backup stopping point.
  	 */
  	stoppoint = RequestXLogSwitch();
  
  	XLByteToSeg(stoppoint, _logId, _logSeg);
  	XLogFileName(stopxlogfilename, ThisTimeLineID, _logId, _logSeg);
  
  	/* Use the log timezone here, not the session timezone */
--- 7002,7026 ----
  	LWLockRelease(WALInsertLock);
  
  	/*
! 	 * Request switch to a new xlog segment file, so that the backup is valid
  	 * as soon as archiver moves out the current segment file. We'll report
  	 * the end address of the XLOG SWITCH record as the backup stopping point.
  	 */
  	stoppoint = RequestXLogSwitch();
  
  	XLByteToSeg(stoppoint, _logId, _logSeg);
+ 
+ 	/*
+ 	 * If we didn't actually switch xlog files then there is nothing in
+ 	 * this file for us to wait for, so set stopxlogfilename to be the
+ 	 * previous file instead. We still report the same ending location.
+ 	 * If we don't do this pg_stop_backup() will wait until we next switch
+ 	 * log files, which could be archive_timeout, or it could be much
+ 	 * longer if archive_timeout is not enabled.
+ 	 */
+ 	if ((stoppoint.xrecoff % XLogSegSize) == 0)
+ 		PrevLogSeg(_logId, _logSeg);
+ 
  	XLogFileName(stopxlogfilename, ThisTimeLineID, _logId, _logSeg);
  
  	/* Use the log timezone here, not the session timezone */
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to