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

Skip to content

Commit b2ab1e6

Browse files
committed
Ensure that before truncating CLOG, we force a checkpoint even if no
recent WAL activity has occurred. Without this, it's possible that a later crash might leave tuples on disk with un-updated commit status bits.
1 parent c87469e commit b2ab1e6

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

src/backend/access/transam/clog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.10 2002/09/02 02:47:01 momjian Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/access/transam/clog.c,v 1.11 2002/09/26 22:58:33 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -809,8 +809,8 @@ TruncateCLOG(TransactionId oldestXact)
809809
if (!ScanCLOGDirectory(cutoffPage, false))
810810
return; /* nothing to remove */
811811

812-
/* Perform a CHECKPOINT */
813-
CreateCheckPoint(false);
812+
/* Perform a forced CHECKPOINT */
813+
CreateCheckPoint(false, true);
814814

815815
/*
816816
* Scan CLOG shared memory and remove any pages preceding the cutoff

src/backend/access/transam/xlog.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.106 2002/09/04 20:31:13 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.107 2002/09/26 22:58:33 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2743,7 +2743,7 @@ StartupXLOG(void)
27432743
* checkpoint to become prevCheckPoint...
27442744
*/
27452745
ControlFile->checkPoint = checkPointLoc;
2746-
CreateCheckPoint(true);
2746+
CreateCheckPoint(true, true);
27472747
XLogCloseRelationCache();
27482748
}
27492749

@@ -2901,7 +2901,7 @@ ShutdownXLOG(void)
29012901

29022902
CritSectionCount++;
29032903
CreateDummyCaches();
2904-
CreateCheckPoint(true);
2904+
CreateCheckPoint(true, true);
29052905
ShutdownCLOG();
29062906
CritSectionCount--;
29072907

@@ -2910,9 +2910,12 @@ ShutdownXLOG(void)
29102910

29112911
/*
29122912
* Perform a checkpoint --- either during shutdown, or on-the-fly
2913+
*
2914+
* If force is true, we force a checkpoint regardless of whether any XLOG
2915+
* activity has occurred since the last one.
29132916
*/
29142917
void
2915-
CreateCheckPoint(bool shutdown)
2918+
CreateCheckPoint(bool shutdown, bool force)
29162919
{
29172920
CheckPoint checkPoint;
29182921
XLogRecPtr recptr;
@@ -2955,21 +2958,21 @@ CreateCheckPoint(bool shutdown)
29552958
LWLockAcquire(WALInsertLock, LW_EXCLUSIVE);
29562959

29572960
/*
2958-
* If this isn't a shutdown, and we have not inserted any XLOG records
2959-
* since the start of the last checkpoint, skip the checkpoint. The
2960-
* idea here is to avoid inserting duplicate checkpoints when the
2961-
* system is idle. That wastes log space, and more importantly it
2961+
* If this isn't a shutdown or forced checkpoint, and we have not inserted
2962+
* any XLOG records since the start of the last checkpoint, skip the
2963+
* checkpoint. The idea here is to avoid inserting duplicate checkpoints
2964+
* when the system is idle. That wastes log space, and more importantly it
29622965
* exposes us to possible loss of both current and previous checkpoint
29632966
* records if the machine crashes just as we're writing the update.
2964-
* (Perhaps it'd make even more sense to checkpoint only when the
2965-
* previous checkpoint record is in a different xlog page?)
2967+
* (Perhaps it'd make even more sense to checkpoint only when the previous
2968+
* checkpoint record is in a different xlog page?)
29662969
*
29672970
* We have to make two tests to determine that nothing has happened since
29682971
* the start of the last checkpoint: current insertion point must
29692972
* match the end of the last checkpoint record, and its redo pointer
29702973
* must point to itself.
29712974
*/
2972-
if (!shutdown)
2975+
if (!shutdown && !force)
29732976
{
29742977
XLogRecPtr curInsert;
29752978

src/backend/bootstrap/bootstrap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.143 2002/09/25 20:31:40 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.144 2002/09/26 22:58:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -390,7 +390,7 @@ BootstrapMain(int argc, char *argv[])
390390

391391
case BS_XLOG_CHECKPOINT:
392392
CreateDummyCaches();
393-
CreateCheckPoint(false);
393+
CreateCheckPoint(false, false);
394394
SetSavedRedoRecPtr(); /* pass redo ptr back to
395395
* postmaster */
396396
proc_exit(0); /* done */
@@ -445,7 +445,7 @@ BootstrapMain(int argc, char *argv[])
445445
Int_yyparse();
446446

447447
SetProcessingMode(NormalProcessing);
448-
CreateCheckPoint(true);
448+
CreateCheckPoint(true, true);
449449
SetProcessingMode(BootstrapProcessing);
450450

451451
/* clean up processing */

src/backend/tcop/utility.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.177 2002/09/04 20:31:26 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.178 2002/09/26 22:58:33 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -831,11 +831,9 @@ ProcessUtility(Node *parsetree,
831831
break;
832832

833833
case T_CheckPointStmt:
834-
{
835-
if (!superuser())
836-
elog(ERROR, "permission denied");
837-
CreateCheckPoint(false);
838-
}
834+
if (!superuser())
835+
elog(ERROR, "permission denied");
836+
CreateCheckPoint(false, false);
839837
break;
840838

841839
case T_ReindexStmt:

src/include/access/xlog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: xlog.h,v 1.38 2002/09/26 22:46:29 tgl Exp $
9+
* $Id: xlog.h,v 1.39 2002/09/26 22:58:34 tgl Exp $
1010
*/
1111
#ifndef XLOG_H
1212
#define XLOG_H
@@ -204,7 +204,7 @@ extern void XLOGPathInit(void);
204204
extern void BootStrapXLOG(void);
205205
extern void StartupXLOG(void);
206206
extern void ShutdownXLOG(void);
207-
extern void CreateCheckPoint(bool shutdown);
207+
extern void CreateCheckPoint(bool shutdown, bool force);
208208
extern void SetThisStartUpID(void);
209209
extern void XLogPutNextOid(Oid nextOid);
210210
extern void SetSavedRedoRecPtr(void);

0 commit comments

Comments
 (0)