Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U3Vs7-0000fX-IJ for pgsql-bugs@arkaria.postgresql.org; Thu, 07 Feb 2013 18:06:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U3Vs6-0007yI-DV for pgsql-bugs@arkaria.postgresql.org; Thu, 07 Feb 2013 18:06:54 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U3Vs5-0007yC-Cd for pgsql-bugs@postgresql.org; Thu, 07 Feb 2013 18:06:53 +0000 Received: from outmail148142.authsmtp.co.uk ([62.13.148.142]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U3Vs2-0000gO-Ml for pgsql-bugs@postgresql.org; Thu, 07 Feb 2013 18:06:52 +0000 Received: from mail-c232.authsmtp.com (mail-c232.authsmtp.com [62.13.128.232]) by punt7.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id r17I6mc5049067 for ; Thu, 7 Feb 2013 18:06:48 GMT Received: from [172.47.23.103] (70-36-143-10.dsl.dynamic.sonic.net [70.36.143.10]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id r17I6gQ0024893 for ; Thu, 7 Feb 2013 18:06:45 GMT Message-ID: <5113ED30.1070903@agliodbs.com> Date: Thu, 07 Feb 2013 10:06:40 -0800 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Why does FK creation still take an access exclusive lock on the referenced table? X-Enigmail-Version: 1.5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Server-Quench: 226eed32-7151-11e2-b10b-0025903375e2 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdyZgscClZXSx8a IioLCC5HRQ8+YBZL BAkbIhBDJB8DSAtK Gl5dNUZcKlAHXFUf XCRcFVRTTyskC3x3 awtSfQRVaEpIVQFv Hk9JXFFUCgRsAgIA BgEcUQZyOUdHfwd2 MidiXnJfVE15O0R/ RkcaF28AMDI0a2IC V0Fddh5VcVZIY01E agJiVHMPZGwHZXln QgJpKQ8xLH1TLylO Ci8uZVkITE8XHzk6 DwseHDErVVEMRCh7 JhpuI1UXEV0Kekgi Ol88QlMGPlcWDQZd V0ZLSDNZKhEbSiQm Fw5cVkMScnVBSC1Y D0pA X-Authentic-SMTP: 61633136333939.1019:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 70.36.143.10/23 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Pg-Spam-Score: -2.6 (--) 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 Folks, I'd thought this was fixed with some of the ALTER changes in 9.2, but apparently not (9.2.2): SESSION1: sampledata=# create table test1 ( id int not null primary key ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test1_pkey" for table "test1" CREATE TABLE Time: 55.224 ms ^ sampledata=# create table test2 ( id int not null primary key, test1 int ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test2_pkey" for table "test2" CREATE TABLE Time: 40.841 ms sampledata=# insert into test1 select i from generate_series(1,10) as gs(i); sampledata=# begin; BEGIN Time: 0.088 ms sampledata=# alter table test2 add constraint test1_fk foreign key ( test1 ) references test1(id); ALTER TABLE Time: 2.185 ms sampledata=# SESSION2: sampledata=# select * from test1; ... wait forever ^C sampledata=# select locktype, mode, relname from pg_locks join pg_class on relation=oid; locktype | mode | relname ----------+---------------------+---------------------------- relation | AccessShareLock | test1_pkey relation | AccessShareLock | test2_pkey relation | AccessShareLock | pg_class_relname_nsp_index relation | AccessShareLock | pg_class_oid_index relation | AccessShareLock | pg_class relation | AccessShareLock | pg_locks relation | AccessShareLock | test2 relation | AccessExclusiveLock | test2 relation | AccessShareLock | test1 relation | RowShareLock | test1 relation | AccessExclusiveLock | test1 I understand why establishing an FK needs an ExclusiveLock on the referenced table, but it doesn't need an AccessExclusiveLock. This causes lots of deployment issues for users. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs