pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-bugs@postgresql.org
Cc: Cédric Villemain <cedric.villemain.debian@gmail.com>
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Greg Sabino Mullane <greg@endpoint.com>
Subject: Re: Unlogged tables cannot be truncated twice
Date: Tue, 31 May 2011 02:35:58 +0200
Message-ID: <201105310235.58484.andres@anarazel.de> (raw)
In-Reply-To: <201105310214.00791.andres@anarazel.de>
References: <20110530160043.GC3012@core.home>
	<BANLkTimj=TZEOz4Yffv+8e6KM-9Dkf4E_g@mail.gmail.com>
	<201105310214.00791.andres@anarazel.de>

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.

Andres

Attachments:

0001-Fix-file-existing-errors-uppon-recreation-of-an-unlo_v2.patch (text/x-patch, 1.9K) download From bd7240ab8b331c261d6a5215bee906f8c63f0019 Mon Sep 17 00:00:00 2001 From: Andres Freund <andres@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 ++- src/backend/catalog/storage.c | 2 -- 2 files changed, 2 insertions(+), 3 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; diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c index 57987be..68a7b30 100644 --- a/src/backend/catalog/storage.c +++ b/src/backend/catalog/storage.c @@ -265,8 +265,6 @@ RelationTruncate(Relation rel, BlockNumber nblocks) /* Truncate the FSM first if it exists */ fsm = smgrexists(rel->rd_smgr, FSM_FORKNUM); - if (fsm) - FreeSpaceMapTruncateRel(rel, nblocks); /* Truncate the visibility map too if it exists. */ vm = smgrexists(rel->rd_smgr, VISIBILITYMAP_FORKNUM); -- 1.7.5.rc1.16.g9db1.dirty

view thread (16+ messages)  latest in thread

Message-ID: <201105310235.58484.andres@anarazel.de>
Permalink:  ../201105310235.58484.andres@anarazel.de/
Also on:    postgresql.org/message-id/201105310235.58484.andres@anarazel.de

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@anarazel.de, cedric.villemain.debian@gmail.com, alvherre@commandprompt.com, greg@endpoint.com
  Subject: Re: Unlogged tables cannot be truncated twice
  In-Reply-To: <201105310235.58484.andres@anarazel.de>
  References: <20110530160043.GC3012@core.home> <BANLkTimj=TZEOz4Yffv+8e6KM-9Dkf4E_g@mail.gmail.com> <201105310214.00791.andres@anarazel.de> <201105310235.58484.andres@anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox