Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vbt6P-00089N-4H for pgsql-performance@arkaria.postgresql.org; Thu, 31 Oct 2013 14:20:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vbt6O-0001HP-Jl for pgsql-performance@arkaria.postgresql.org; Thu, 31 Oct 2013 14:20:00 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vbt6N-0001HF-PJ for pgsql-performance@postgresql.org; Thu, 31 Oct 2013 14:19:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vbt6D-0003CJ-Pg for pgsql-performance@postgresql.org; Thu, 31 Oct 2013 14:19:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id r9VEJmfq022671; Thu, 31 Oct 2013 10:19:48 -0400 From: Tom Lane To: Ben Hoyt cc: David Johnston , pgsql-performance@postgresql.org Subject: Re: Re: Adding foreign key constraint holds exclusive lock for too long (on production database) In-reply-to: References: <1383092289576-5776315.post@n5.nabble.com> <13822.1383093005@sss.pgh.pa.us> Comments: In-reply-to Ben Hoyt message dated "Thu, 31 Oct 2013 21:01:40 +1300" Date: Thu, 31 Oct 2013 10:19:48 -0400 Message-ID: <22670.1383229188@sss.pgh.pa.us> X-Pg-Spam-Score: -1.0 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Ben Hoyt writes: >> It appears the possible explanations for Ben's problem are: >> 1. For some reason this query is a lot slower than the one he came up >> with; > Anyway, it's definitely #1 that's happening, as I build the > RI_Initial_Check() query by hand, and it takes just as long as the ADD > CONSTRAINT. Huh. Maybe an optimizer failing? Could we see the full text of both queries and EXPLAIN ANALYZE results for them? > So I guess this is really a side effect of the quirky way we're > dumping and restoring only one schema, and dropping/re-adding > constraints on deployment because of this. Is this a really strange > thing to do -- deploying only one schema (the "static" data) and > dropping/re-adding constraints -- or are there better practices here? Doesn't seem unreasonable. One thought is that maybe you need to insert a manual ANALYZE after reloading the data? regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance