Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id E4F88632B5D for ; Mon, 6 Apr 2009 10:54:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 93522-08 for ; Mon, 6 Apr 2009 10:54:05 -0300 (ADT) 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 8DED5632A8B for ; Mon, 6 Apr 2009 10:54:05 -0300 (ADT) 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 n36Ds0iY027086; Mon, 6 Apr 2009 09:54:00 -0400 (EDT) To: "Albe Laurenz" cc: "roopasatish *EXTERN*" , pgsql-performance@postgresql.org Subject: Re: probelm with alter table add constraint...... In-reply-to: References: <5da3d2700904052354g61f02031x822322e9ee512ad9@mail.gmail.com> Comments: In-reply-to "Albe Laurenz" message dated "Mon, 06 Apr 2009 12:47:11 +0200" Date: Mon, 06 Apr 2009 09:54:00 -0400 Message-ID: <27085.1239026040@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/127 X-Sequence-Number: 33494 "Albe Laurenz" writes: > roopasatish wrote: >> I have an issue with the add foreign key constraint which >> goes for waiting and locks other queries as well. >> >> ALTER TABLE ONLY holding_positions ADD CONSTRAINT >> holding_positions_stock_id_fkey FOREIGN KEY (stock_id) >> REFERENCES stocks (stock_id) MATCH SIMPLE >> ON UPDATE NO ACTION ON DELETE NO ACTION; >> >> The holding_positions table has no data in it as yet. > Look in pg_catalog.pg_locks for a second transaction that > holds a lock on the table holding_positions. This statement also needs to get lock on the referenced table "stocks". An open transaction that's referenced either table will block it. regards, tom lane