Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMwIA-0004OG-0y for pgsql-general@arkaria.postgresql.org; Fri, 10 Apr 2020 16:14:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMwI8-00048D-PT for pgsql-general@arkaria.postgresql.org; Fri, 10 Apr 2020 16:14:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMwI8-000486-Hk for pgsql-general@lists.postgresql.org; Fri, 10 Apr 2020 16:14:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jMwI6-0003F5-Vx for pgsql-general@postgresql.org; Fri, 10 Apr 2020 16:14:04 +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 03AGDx8r004148; Fri, 10 Apr 2020 12:13:59 -0400 From: Tom Lane To: Laurenz Albe cc: Virendra Kumar , Pgsql-general General Subject: Re: Different Lock Behavior With Create and Drop Foreign Key In-reply-to: <3a4e7019df93301b82a98ddbfa73d31170d03a45.camel@cybertec.at> References: <834603375.3470346.1586482852542.ref@mail.yahoo.com> <834603375.3470346.1586482852542@mail.yahoo.com> <3a4e7019df93301b82a98ddbfa73d31170d03a45.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Fri, 10 Apr 2020 07:27:37 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4146.1586535239.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 10 Apr 2020 12:13:59 -0400 Message-ID: <4147.1586535239@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laurenz Albe writes: > On Fri, 2020-04-10 at 01:40 +0000, Virendra Kumar wrote: >> [ $subject ] > That is because foreign keys are implemented with system triggers, some = of which > are defined on the target table. > Now CREATE TRIGGER does not require an ACCESS EXCLUSIVE lock, but DROP T= RIGGER does. Yeah. The documentation could be clearer about this though. The relevant bit on the ALTER TABLE page is Addition of a foreign key constraint requires a SHARE ROW EXCLUSIVE lock on the referenced table, in addition to the lock on the table receiving the constraint. which, at least to my eyes, isn't very clear that SHARE ROW EXCLUSIVE is the lock level used for *both* tables. regards, tom lane