Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 332B41337B4F for ; Tue, 28 Dec 2010 11:08:35 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 95947-04 for ; Tue, 28 Dec 2010 15:08:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id D1BA61337999 for ; Tue, 28 Dec 2010 11:08:27 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oBSF8KuS019239; Tue, 28 Dec 2010 10:08:21 -0500 (EST) To: Florian Weimer cc: kakarukeys , pgsql-performance@postgresql.org Subject: Re: adding foreign key constraint locks up table In-reply-to: <82ei926j3p.fsf@mid.bfk.de> References: <75218696-61be-4730-89f6-dd6058fa9eda@a28g2000prb.googlegroups.com> <82ei926j3p.fsf@mid.bfk.de> Comments: In-reply-to Florian Weimer message dated "Tue, 28 Dec 2010 14:57:14 +0000" Date: Tue, 28 Dec 2010 10:08:20 -0500 Message-ID: <19238.1293548900@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/324 X-Sequence-Number: 41776 Florian Weimer writes: >> Whenever I try to create a new table "bbb" with foreign key pointing >> to "aaa". The operation locks, and reading "aaa" is not possible. The >> query also never seems to finish. What that sounds like to me is there's some long-running (probably idle) open transaction that's holding AccessShare lock on aaa. The ALTER is blocked waiting for that xact to finish and release its lock. Everything else queues up behind the ALTER. A bit of looking in pg_locks would find the culprit, if this theory is right. > Do you mean that the ALTER query and subsequent queries are shown as > "waiting" in pg_stat_activity? In this case, I'm also wondering why > this is inecessary. ALTER ADD FOREIGN KEY must lock both tables to add triggers to them. regards, tom lane