Re: Locking referenced table when creating and dropping tables with foreign key constraints

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: frank joerdens <fiskadoro(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, dev <dev(at)woome(dot)com>
Subject: Re: Locking referenced table when creating and dropping tables with foreign key constraints
Date: 2010-02-02 00:19:46
Message-ID: 19744.1265069986@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

frank joerdens <fiskadoro(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-02-02 00:31:18 Re: statement_timeout problem
Previous Message Hardwick, Joe 2010-02-01 21:25:53 statement_timeout problem