Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 62CE8B60CB5 for ; Thu, 2 Jun 2011 15:52:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 78558-01 for ; Thu, 2 Jun 2011 18:52:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.anarazel.de (mail.anarazel.de [217.115.131.40]) by mail.postgresql.org (Postfix) with ESMTP id 30186B60876 for ; Thu, 2 Jun 2011 15:52:47 -0300 (ADT) Received: by mail.anarazel.de (Postfix, from userid 108) id 8229644800A; Thu, 2 Jun 2011 20:52:45 +0200 (CEST) Received: from anarazel.de (f053040089.adsl.alicedsl.de [78.53.40.89]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id B9C84448009; Thu, 2 Jun 2011 20:52:40 +0200 (CEST) Received: by anarazel.de (Postfix, from userid 1000) id 87C2E1C0172; Thu, 2 Jun 2011 20:52:39 +0200 (CEST) From: Andres Freund To: pgsql-bugs@postgresql.org Subject: Re: Unlogged tables cannot be truncated twice Date: Thu, 2 Jun 2011 20:52:38 +0200 User-Agent: KMail/1.13.7 (Linux/2.6.39-rc6-andres-00108-gdf2cc6b; KDE/4.6.3; x86_64; ; ) Cc: Robert Haas , Alvaro Herrera , =?iso-8859-1?q?C=E9dric_Villemain?= , Greg Sabino Mullane References: <20110530160043.GC3012@core.home> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <201106022052.39070.andres@anarazel.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/25 X-Sequence-Number: 30404 On Thursday, June 02, 2011 07:31:33 PM Robert Haas wrote: > On Wed, Jun 1, 2011 at 1:15 PM, Robert Haas wrote: > > 2011/5/31 Andres Freund : > >> On Tuesday, May 31, 2011 03:27:22 Alvaro Herrera wrote: > >>> Excerpts from Andres Freund's message of lun may 30 20:47:49 -0400 20= 11: > >>> > 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=E9dric 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(). > >>> > > >=20 > >>> > > > Thats imo wrong because it will break a plain REINDEX? > >>> > >=20 > >>> > > > 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. > >>> > >=20 > >>> > > So I think it is the simpler version of simply checking the > >>> > > existance of the fork before creating is ok. > >>>=20 > >>> Hmm, I wonder if what we should be doing here is observe isreindex in > >>> index_build to avoid creating the init fork. Doing smgr access at th= at > >>> level seems wrong. > >>=20 > >> isreindex doesn't contain the necessary informormation as its set doing > >> a REINDEX even though a new relfilenode is created and thus the fork > >> needs to be created. > >>=20 > >> It doesn't seem terribly clean do do the !smgrexists(), I aggree with > >> you there. On the other hand we are calling smgrcreate() two lines down > >> anyway. I personally don't realy like the placement of that piece of > >> code very much. Doing it in index_build seems to be the wrong place. I > >> don't think there really is a good place for it right now. > >=20 > > I'm open to suggestions on how to rearrange this, but I think for > > right now the approach you proposed upthread (add a smgrexists() test) > > is probably the simplest way to fix this. >=20 > Done. Your patch tested for FSM_FORKNUM instead of INIT_FORKNUM, > which seemed wrong, so I changed it. I also added comments. Wow. I don't think I ever made so many stupid mistakes when doing a two lin= e=20 change. I abviously wasn't really awake that evening. As evidenced excessiv= ely=20 in that thread ;) Thanks, Andres