Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xcfdk-0003Oz-0q for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Oct 2014 19:14:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xcfdj-0006qN-FA for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Oct 2014 19:14:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xcfdh-0006o9-U5 for pgsql-bugs@postgresql.org; Fri, 10 Oct 2014 19:14:10 +0000 Received: from mout.kundenserver.de ([212.227.126.187]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xcfdd-0002nj-FD for pgsql-bugs@postgresql.org; Fri, 10 Oct 2014 19:14:08 +0000 Received: from anarazel.de (p5DDC517B.dip0.t-ipconnect.de [93.220.81.123]) by mrelayeu.kundenserver.de (node=mreue006) with ESMTP (Nemesis) id 0Lowee-1Y8ib83M9c-00etBA; Fri, 10 Oct 2014 21:14:02 +0200 Received: by anarazel.de (Postfix, from userid 1000) id F2E4510099E; Fri, 10 Oct 2014 21:14:01 +0200 (CEST) Date: Fri, 10 Oct 2014 21:14:01 +0200 From: Andres Freund To: cg@osss.net Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #11638: Transaction safety fails when constraints are dropped and analyze is done Message-ID: <20141010191401.GA18020@awork2.anarazel.de> References: <20141010181433.25463.5856@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141010181433.25463.5856@wrigleys.postgresql.org> X-Provags-ID: V02:K0:7b7mUBrtOnVH9CGry/z9lo+Bnxa9vlydWfdZOnt3xeV oSYk1+uPbfKus5DW5icwasr2k/i2xIlej7Izo7HNp9RNoEGY0G x3uK5xqmcEenw5xAAqz2lpBvMng3q2oH3X6w761E99zepsyqXQ wunUJAGQjvdos6x7IlPXgHCIiPm/VpI6M7LAEDfz6a55vTLJsZ luqbegfZ7/IrnZJYZ7es34LoRtAm3yNPcVdHfgWNqAico3hn1x e/BnqTuewnXijk0GgsDMWazbQmi6UpKzu9Wja5fuSfqykC1cf4 a0e5NZ9Dx37OB7fMpYEfCWHTrOpzer2TXxrXFyJWYpmro8NbcR ICdMIPR4eWWXxNneRDxTfWGO1D0ctCJK0j8OY5mqQ X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Hi, On 2014-10-10 18:14:33 +0000, cg@osss.net wrote: > The following bug has been logged on the website: > > Bug reference: 11638 > Logged by: Casey Allen Shobe > Email address: cg@osss.net > PostgreSQL version: 9.3.5 > Operating system: Linux (RHEL 5) > Description: > > Discovered on 8.4.5, reproducible on 9.3.5. > > The paste pretty much explains it all: > http://pgsql.privatepaste.com/162682d176 Please attach - the paste will expire in a couple days. That makes researching issues later quite annoying. > When, within a transaction: > * I drop a foreign key (or any) constraint. > * Load some data to the table which won't fit the constraint. > * Analyze the table. > * Attempt to re-add the constraint which fails and should roll back the > whole transaction. > > The constraint is still missing after rollback. > > If I take out the analyze step, it works as expected. Yuck. This is ugly. The problem is this nice bit: void vac_update_relstats(Relation relation, BlockNumber num_pages, double num_tuples, BlockNumber num_all_visible_pages, bool hasindex, TransactionId frozenxid, { MultiXactId minmulti) ... if (pgcform->relhastriggers && relation->trigdesc == NULL) { pgcform->relhastriggers = false; dirty = true; } ... /* If anything changed, write out the tuple. */ if (dirty) heap_inplace_update(rd, ctup); } That's, like, a *seriously* bad idea. The current xact doesn't see a trigger, so we remove relhastriggers (and similarly other relhas* stuff). The kicker is that we do so *nontransactionally*. That's fine enough for VACUUM because that doesn't run in a transaction. But vac_update_relstats is also run for ANALYZE. I've no time to think this through right now, but my current thinking is that we should use a transactional update for ANALYZE. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs