From 04fbe29a8369d44c25002a398098a4dc41b233ae Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 20 Jul 2007 16:29:53 +0000 Subject: [PATCH] Fix WAL replay of truncate operations to cope with the possibility that the truncated relation was deleted later in the WAL sequence. Since replay normally auto-creates a relation upon its first reference by a WAL log entry, failure is seen only if the truncate entry happens to be the first reference after the checkpoint we're restarting from; which is a pretty unusual case but of course not impossible. Fix by making truncate entries auto-create like the other ones do. Per report and test case from Dharmendra Goyal. --- src/backend/storage/smgr/smgr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index 240329ae66..7137d2dc08 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.104 2007/07/08 22:23:16 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.105 2007/07/20 16:29:53 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -811,6 +811,14 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record) reln = smgropen(xlrec->rnode); + /* + * Forcibly create relation if it doesn't exist (which suggests that + * it was dropped somewhere later in the WAL sequence). As in + * XLogOpenRelation, we prefer to recreate the rel and replay the + * log as best we can until the drop is seen. + */ + smgrcreate(reln, false, true); + /* Can't use smgrtruncate because it would try to xlog */ /*