Re: adding foreign key constraint locks up table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Florian Weimer <fweimer@xxxxxx> writes:
>> Whenever I try to create a new table "bbb" with foreign key pointing
>> to "aaa". The operation locks, and reading "aaa" is not possible. The
>> query also never seems to finish.

What that sounds like to me is there's some long-running (probably idle)
open transaction that's holding AccessShare lock on aaa.  The ALTER is
blocked waiting for that xact to finish and release its lock.
Everything else queues up behind the ALTER.  A bit of looking in
pg_locks would find the culprit, if this theory is right.

> Do you mean that the ALTER query and subsequent queries are shown as
> "waiting" in pg_stat_activity?  In this case, I'm also wondering why
> this is inecessary.

ALTER ADD FOREIGN KEY must lock both tables to add triggers to them.

			regards, tom lane

-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux