diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index befb507..fbd3fd2 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7563,6 +7563,10 @@ CreateCheckPoint(int flags) uint32 freespace; uint32 _logId; uint32 _logSeg; + uint32 insert_logId; + uint32 insert_logSeg; + uint32 ckpt_logId; + uint32 ckpt_logSeg; TransactionId *inCommitXids; int nInCommit; @@ -7629,19 +7633,14 @@ CreateCheckPoint(int flags) LWLockAcquire(WALInsertLock, LW_EXCLUSIVE); /* - * If this isn't a shutdown or forced checkpoint, and we have not inserted - * any XLOG records since the start of the last checkpoint, skip the + * If this isn't a shutdown or forced checkpoint, and we have not switched + * to the next WAL file since the start of the last checkpoint, skip the * checkpoint. The idea here is to avoid inserting duplicate checkpoints * when the system is idle. That wastes log space, and more importantly it * exposes us to possible loss of both current and previous checkpoint * records if the machine crashes just as we're writing the update. * (Perhaps it'd make even more sense to checkpoint only when the previous * checkpoint record is in a different xlog page?) - * - * We have to make two tests to determine that nothing has happened since - * the start of the last checkpoint: current insertion point must match - * the end of the last checkpoint record, and its redo pointer must point - * to itself. */ if ((flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_FORCE)) == 0) @@ -7649,13 +7648,10 @@ CreateCheckPoint(int flags) XLogRecPtr curInsert; INSERT_RECPTR(curInsert, Insert, Insert->curridx); - if (curInsert.xlogid == ControlFile->checkPoint.xlogid && - curInsert.xrecoff == ControlFile->checkPoint.xrecoff + - MAXALIGN(SizeOfXLogRecord + sizeof(CheckPoint)) && - ControlFile->checkPoint.xlogid == - ControlFile->checkPointCopy.redo.xlogid && - ControlFile->checkPoint.xrecoff == - ControlFile->checkPointCopy.redo.xrecoff) + XLByteToSeg(curInsert, insert_logId, insert_logSeg); + XLByteToSeg(ControlFile->checkPoint, ckpt_logId, ckpt_logSeg); + if (insert_logId == ckpt_logId && + insert_logSeg == ckpt_logSeg) { LWLockRelease(WALInsertLock); LWLockRelease(CheckpointLock);