Re: Locking referenced table when creating and dropping tables with foreign key constraints - Mailing list pgsql-general

From Tom Lane
Subject Re: Locking referenced table when creating and dropping tables with foreign key constraints
Date
Msg-id 19744.1265069986@sss.pgh.pa.us
Whole thread Raw
In response to Locking referenced table when creating and dropping tables with foreign key constraints  (frank joerdens <fiskadoro@gmail.com>)
List pgsql-general
frank joerdens <fiskadoro@gmail.com> writes:
> It seems that whenever I create a new empty table with a foreign key
> constraint, the transaction will acquire an exclusive lock on the
> referenced table, locking out other writers (not sure if even readers
> as well), and I don't quite see why that is necessary

It involves an ALTER TABLE ADD TRIGGER command, which necessarily locks
out writers to avoid race conditions.  I think at the moment it may take
an exclusive lock and thereby lock out readers as well.  There has been
some talk of trying to reduce the lock strength needed for ALTER
operations, but you should not expect that it'll ever be possible to
do that without blocking writers.

            regards, tom lane

pgsql-general by date:

Previous
From: "Hardwick, Joe"
Date:
Subject: statement_timeout problem
Next
From: Tom Lane
Date:
Subject: Re: statement_timeout problem