Re: Different Lock Behavior With Create and Drop Foreign Key

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Virendra Kumar <viru_7683(at)yahoo(dot)com>, Pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Different Lock Behavior With Create and Drop Foreign Key
Date: 2020-04-10 16:13:59
Message-ID: 4147.1586535239@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> 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 TRIGGER 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2020-04-10 16:32:37 Huge number of pg_temp and pg_toast_temp schemas
Previous Message Laurenz Albe 2020-04-10 05:27:37 Re: Different Lock Behavior With Create and Drop Foreign Key