On Tuesday, May 31, 2011 01:56:05 AM Cédric Villemain wrote:
> I remove my own explanations as we conclude on the same thing.
> Attached is the fix by adding a (!reindex)  in the index.c if().
Thats imo wrong because it will break a plain REINDEX?

I think one possible correct fix would be the attached:


Andres
From c22d067cfe233428631b52f7bed2d0013e7f4712 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Tue, 31 May 2011 02:02:19 +0200
Subject: [PATCH] Fix file existing errors uppon recreation of an unlogged
 tables indexes _init fork

The error could only occur if a relation got truncated that got a new
relfilenode in the same transaction before because in that case
heap_truncate_one_rel gets called instead of setting a new relfilenode
for all relevant relations.

To fix that drop the relations _init fork in
storage.c:RelationTruncate as the other forks are handled there as
well.

BEGIN;CREATE UNLOGGED TABLE foo (a int PRIMARY KEY);TRUNCATE foo; ROLLBACK;
---
 src/backend/catalog/storage.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index 57987be..7da63ba 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -252,6 +252,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 {
 	bool		fsm;
 	bool		vm;
+	bool		initfork;
 
 	/* Open it at the smgr level if not already done */
 	RelationOpenSmgr(rel);
@@ -273,6 +274,11 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 	if (vm)
 		visibilitymap_truncate(rel, nblocks);
 
+	/* the init fork will be recreated in index_build */
+	initfork = smgrexists(rel->rd_smgr, INIT_FORKNUM);
+	if (initfork)
+		smgrdounlink(rel->rd_smgr, INIT_FORKNUM, false);
+
 	/*
 	 * We WAL-log the truncation before actually truncating, which means
 	 * trouble if the truncation fails. If we then crash, the WAL replay
-- 
1.7.5.rc1.16.g9db1.dirty

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to