On Tuesday, May 31, 2011 02:35:58 AM Andres Freund wrote: > On Tuesday, May 31, 2011 02:14:00 AM Andres Freund wrote: > > 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: > My version was wrong as well because it did not observe RelationTruncate's > nblocks argument. That function is used to "shorten" the relation in > vacuum. So dropping the init fork there is not a good idea. > > So I think it is the simpler version of simply checking the existance of > the fork before creating is ok. Gna. gnargl. Coffe. Bed. ;)
There was an accidental hunk I added while removing some whitespace. That would not have been good on a real commit. Argh.
From 1dbef0a907ec5e87da61a7ffb505ba082f2e11f8 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 simply check for the existance of the fork before recreating it. To reproduce: BEGIN;CREATE UNLOGGED TABLE foo (a int PRIMARY KEY);TRUNCATE foo; ROLLBACK; --- src/backend/catalog/index.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index a0898e0..d833a09 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1743,7 +1743,8 @@ index_build(Relation heapRelation, /* * If this is an unlogged index, we need to write out an init fork for it. */ - if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) + if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED + && !smgrexists(indexRelation->rd_smgr, FSM_FORKNUM)) { RegProcedure ambuildempty = indexRelation->rd_am->ambuildempty; -- 1.7.5.rc1.16.g9db1.dirty
From 1dbef0a907ec5e87da61a7ffb505ba082f2e11f8 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 simply check for the existance of the fork before recreating it. To reproduce: BEGIN;CREATE UNLOGGED TABLE foo (a int PRIMARY KEY);TRUNCATE foo; ROLLBACK; --- src/backend/catalog/index.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index a0898e0..d833a09 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1743,7 +1743,8 @@ index_build(Relation heapRelation, /* * If this is an unlogged index, we need to write out an init fork for it. */ - if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED) + if (heapRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED + && !smgrexists(indexRelation->rd_smgr, FSM_FORKNUM)) { RegProcedure ambuildempty = indexRelation->rd_am->ambuildempty; -- 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