Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8b69d8

Browse files
committed
Revert "Reduce checkpoints and WAL traffic on low activity database server"
This reverts commit 18fb9d8. Per discussion, it does not seem like a good idea to allow committed changes to go un-checkpointed indefinitely, as could happen in a low-traffic server; that makes us entirely reliant on the WAL stream with no redundancy that might aid data recovery in case of disk failure. This re-introduces the original problem of hot-standby setups generating a small continuing stream of WAL traffic even when idle, but there are other ways to address that without compromising crash recovery, so we'll revisit that issue in a future release cycle.
1 parent 8b23db9 commit b8b69d8

File tree

1 file changed

+13
-15
lines changed
  • src/backend/access/transam

1 file changed

+13
-15
lines changed

src/backend/access/transam/xlog.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7646,10 +7646,6 @@ CreateCheckPoint(int flags)
76467646
uint32 freespace;
76477647
uint32 _logId;
76487648
uint32 _logSeg;
7649-
uint32 redo_logId;
7650-
uint32 redo_logSeg;
7651-
uint32 insert_logId;
7652-
uint32 insert_logSeg;
76537649
TransactionId *inCommitXids;
76547650
int nInCommit;
76557651

@@ -7726,31 +7722,33 @@ CreateCheckPoint(int flags)
77267722
LWLockAcquire(WALInsertLock, LW_EXCLUSIVE);
77277723

77287724
/*
7729-
* If this isn't a shutdown or forced checkpoint, and we have not switched
7730-
* to the next WAL file since the start of the last checkpoint, skip the
7725+
* If this isn't a shutdown or forced checkpoint, and we have not inserted
7726+
* any XLOG records since the start of the last checkpoint, skip the
77317727
* checkpoint. The idea here is to avoid inserting duplicate checkpoints
77327728
* when the system is idle. That wastes log space, and more importantly it
77337729
* exposes us to possible loss of both current and previous checkpoint
77347730
* records if the machine crashes just as we're writing the update.
77357731
* (Perhaps it'd make even more sense to checkpoint only when the previous
77367732
* checkpoint record is in a different xlog page?)
77377733
*
7738-
* While holding the WALInsertLock we find the current WAL insertion point
7739-
* and compare that with the starting point of the last checkpoint, which
7740-
* is the redo pointer. We use the redo pointer because the start and end
7741-
* points of a checkpoint can be hundreds of files apart on large systems
7742-
* when checkpoint writes are spread out over time.
7734+
* We have to make two tests to determine that nothing has happened since
7735+
* the start of the last checkpoint: current insertion point must match
7736+
* the end of the last checkpoint record, and its redo pointer must point
7737+
* to itself.
77437738
*/
77447739
if ((flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY |
77457740
CHECKPOINT_FORCE)) == 0)
77467741
{
77477742
XLogRecPtr curInsert;
77487743

77497744
INSERT_RECPTR(curInsert, Insert, Insert->curridx);
7750-
XLByteToSeg(curInsert, insert_logId, insert_logSeg);
7751-
XLByteToSeg(ControlFile->checkPointCopy.redo, redo_logId, redo_logSeg);
7752-
if (insert_logId == redo_logId &&
7753-
insert_logSeg == redo_logSeg)
7745+
if (curInsert.xlogid == ControlFile->checkPoint.xlogid &&
7746+
curInsert.xrecoff == ControlFile->checkPoint.xrecoff +
7747+
MAXALIGN(SizeOfXLogRecord + sizeof(CheckPoint)) &&
7748+
ControlFile->checkPoint.xlogid ==
7749+
ControlFile->checkPointCopy.redo.xlogid &&
7750+
ControlFile->checkPoint.xrecoff ==
7751+
ControlFile->checkPointCopy.redo.xrecoff)
77547752
{
77557753
LWLockRelease(WALInsertLock);
77567754
LWLockRelease(CheckpointLock);

0 commit comments

Comments
 (0)