From 6cc4451b5c47eac02e09c3342281da469374432d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 15 Nov 2007 20:36:40 +0000 Subject: Prevent re-use of a deleted relation's relfilenode until after the next checkpoint. This guards against an unlikely data-loss scenario in which we re-use the relfilenode, then crash, then replay the deletion and recreation of the file. Even then we'd be OK if all insertions into the new relation had been WAL-logged ... but that's not guaranteed given all the no-WAL-logging optimizations that have recently been added. Patch by Heikki Linnakangas, per a discussion last month. --- src/backend/access/transam/xlog.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/backend/access/transam/xlog.c') diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 6d4dc6940a..36adc20848 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.286 2007/10/12 19:39:59 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.287 2007/11/15 20:36:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -45,6 +45,7 @@ #include "storage/fd.h" #include "storage/pmsignal.h" #include "storage/procarray.h" +#include "storage/smgr.h" #include "storage/spin.h" #include "utils/builtins.h" #include "utils/pg_locale.h" @@ -5663,6 +5664,14 @@ CreateCheckPoint(int flags) UpdateControlFile(); } + /* + * Let smgr prepare for checkpoint; this has to happen before we + * determine the REDO pointer. Note that smgr must not do anything + * that'd have to be undone if we decide no checkpoint is needed. + */ + smgrpreckpt(); + + /* Begin filling in the checkpoint WAL record */ MemSet(&checkPoint, 0, sizeof(checkPoint)); checkPoint.ThisTimeLineID = ThisTimeLineID; checkPoint.time = time(NULL); @@ -5886,6 +5895,11 @@ CreateCheckPoint(int flags) */ END_CRIT_SECTION(); + /* + * Let smgr do post-checkpoint cleanup (eg, deleting old files). + */ + smgrpostckpt(); + /* * Delete old log files (those no longer needed even for previous * checkpoint). -- cgit v1.2.1