Re: Different Lock Behavior With Create and Drop Foreign Key
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Virendra Kumar <viru_7683@yahoo.com>,
Pgsql-general General <pgsql-general@postgresql.org>
Date: 2020-04-10T16:13:59Z
Lists: pgsql-general
Laurenz Albe <laurenz.albe@cybertec.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
Commits
-
Doc: clarify locking requirements for ALTER TABLE ADD FOREIGN KEY.
- f333d35428c1 13.0 landed
- aa4416dcd924 11.8 landed
- a88e5886c59c 12.3 landed
- 61a9b814c553 10.13 landed
- 2cab4ad81bcb 9.5.22 landed
- 1d676ffd41be 9.6.18 landed