Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit18fb9d8

Browse files
Reduce checkpoints and WAL traffic on low activity database server
Previously, we skipped a checkpoint if no WAL had been written sincelast checkpoint, though this does not appear in user documentation.As of now, we skip a checkpoint until we have written at least oneenough WAL to switch the next WAL file. This greatly reduces thelevel of activity and number of WAL messages generated by a verylow activity server. This is safe because the purpose of a checkpointis to act as a starting place for a recovery, in case of crash.This patch maintains minimal WAL volume for replay in case of crash,thus maintaining very low crash recovery time.
1 parent9aceb6a commit18fb9d8

File tree

1 file changed

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

1 file changed

+15
-13
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7560,6 +7560,10 @@ CreateCheckPoint(int flags)
75607560
uint32freespace;
75617561
uint32_logId;
75627562
uint32_logSeg;
7563+
uint32redo_logId;
7564+
uint32redo_logSeg;
7565+
uint32insert_logId;
7566+
uint32insert_logSeg;
75637567
TransactionId*inCommitXids;
75647568
intnInCommit;
75657569

@@ -7636,33 +7640,31 @@ CreateCheckPoint(int flags)
76367640
LWLockAcquire(WALInsertLock,LW_EXCLUSIVE);
76377641

76387642
/*
7639-
* If this isn't a shutdown or forced checkpoint, and we have notinserted
7640-
*any XLOG records since the start of the last checkpoint, skip the
7643+
* If this isn't a shutdown or forced checkpoint, and we have notswitched
7644+
*to the next WAL file since the start of the last checkpoint, skip the
76417645
* checkpoint.The idea here is to avoid inserting duplicate checkpoints
76427646
* when the system is idle. That wastes log space, and more importantly it
76437647
* exposes us to possible loss of both current and previous checkpoint
76447648
* records if the machine crashes just as we're writing the update.
76457649
* (Perhaps it'd make even more sense to checkpoint only when the previous
76467650
* checkpoint record is in a different xlog page?)
76477651
*
7648-
* We have to make two tests to determine that nothing has happened since
7649-
* the start of the last checkpoint: current insertion point must match
7650-
* the end of the last checkpoint record, and its redo pointer must point
7651-
* to itself.
7652+
* While holding the WALInsertLock we find the current WAL insertion point
7653+
* and compare that with the starting point of the last checkpoint, which
7654+
* is the redo pointer. We use the redo pointer because the start and end
7655+
* points of a checkpoint can be hundreds of files apart on large systems
7656+
* when checkpoint writes are spread out over time.
76527657
*/
76537658
if ((flags& (CHECKPOINT_IS_SHUTDOWN |CHECKPOINT_END_OF_RECOVERY |
76547659
CHECKPOINT_FORCE))==0)
76557660
{
76567661
XLogRecPtrcurInsert;
76577662

76587663
INSERT_RECPTR(curInsert,Insert,Insert->curridx);
7659-
if (curInsert.xlogid==ControlFile->checkPoint.xlogid&&
7660-
curInsert.xrecoff==ControlFile->checkPoint.xrecoff+
7661-
MAXALIGN(SizeOfXLogRecord+sizeof(CheckPoint))&&
7662-
ControlFile->checkPoint.xlogid==
7663-
ControlFile->checkPointCopy.redo.xlogid&&
7664-
ControlFile->checkPoint.xrecoff==
7665-
ControlFile->checkPointCopy.redo.xrecoff)
7664+
XLByteToSeg(curInsert,insert_logId,insert_logSeg);
7665+
XLByteToSeg(ControlFile->checkPointCopy.redo,redo_logId,redo_logSeg);
7666+
if (insert_logId==redo_logId&&
7667+
insert_logSeg==redo_logSeg)
76667668
{
76677669
LWLockRelease(WALInsertLock);
76687670
LWLockRelease(CheckpointLock);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp