diff -rcN postgresql/src/backend/access/transam/xlog.c postgresql_with_patch/src/backend/access/transam/xlog.c *** postgresql/src/backend/access/transam/xlog.c 2011-06-30 10:04:48.000000000 +0900 --- postgresql_with_patch/src/backend/access/transam/xlog.c 2011-07-01 03:51:53.000000000 +0900 *************** *** 558,563 **** --- 558,566 ---- static bool InRedo = false; + /* Reach min recovery ending position in the control file */ + static bool reachedControlMinRecoveryPoint = false; + /* Have we launched bgwriter during recovery? */ static bool bgwriterLaunched = false; *************** *** 6284,6289 **** --- 6287,6304 ---- /* use volatile pointer to prevent code rearrangement */ volatile XLogCtlData *xlogctl = XLogCtl; + /* + * get minRecoveryPoint before the value is changed for + * getting backup on standby server. + * + */ + XLogRecPtr prevminRecoveryPoint = ControlFile->minRecoveryPoint; + bool standbybackup = false; + + if (prevminRecoveryPoint.xlogid != 0 || prevminRecoveryPoint.xrecoff != 0) + standbybackup = true; + + /* * Update pg_control to show that we are recovering and to show the * selected checkpoint as the place we are starting from. We also mark *************** *** 6592,6597 **** --- 6607,6634 ---- /* Pop the error context stack */ error_context_stack = errcontext.previous; + /* + * Check whether to reach minRecoveryPoint when getting backup + * on standby server. + */ + if (standbybackup) + { + if (XLByteEQ(prevminRecoveryPoint, EndRecPtr)) + { + reachedControlMinRecoveryPoint = true; + elog(DEBUG1, "end of backup reached in the control file"); + + LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); + + if (XLByteLT(ControlFile->minRecoveryPoint, EndRecPtr)) + ControlFile->minRecoveryPoint = EndRecPtr; + MemSet(&ControlFile->backupStartPoint, 0, sizeof(XLogRecPtr)); + UpdateControlFile(); + + LWLockRelease(ControlFileLock); + } + } + /* * Update shared recoveryLastRecPtr after this record has been * replayed. *************** *** 6951,6957 **** */ if (!reachedMinRecoveryPoint && XLByteLE(minRecoveryPoint, EndRecPtr) && ! XLogRecPtrIsInvalid(ControlFile->backupStartPoint)) { reachedMinRecoveryPoint = true; ereport(LOG, --- 6988,6995 ---- */ if (!reachedMinRecoveryPoint && XLByteLE(minRecoveryPoint, EndRecPtr) && ! (XLogRecPtrIsInvalid(ControlFile->backupStartPoint) || ! reachedControlMinRecoveryPoint == true)) { reachedMinRecoveryPoint = true; ereport(LOG,