diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-11-15 20:36:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-11-15 20:36:40 +0000 |
commit | 6cc4451b5c47eac02e09c3342281da469374432d (patch) | |
tree | a97187cef1c3c2a95b7094fd46d68b0f448d7f33 /src/backend/access/transam/xlog.c | |
parent | 7a550cb95cf3a541deed15df1d5e25f36af636e5 (diff) | |
download | postgresql-6cc4451b5c47eac02e09c3342281da469374432d.tar.gz |
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.
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 16 |
1 files changed, 15 insertions, 1 deletions
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); @@ -5887,6 +5896,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). */ |