Re: adding foreign key constraint locks up table

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: adding foreign key constraint locks up table
Дата
Msg-id 19238.1293548900@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: adding foreign key constraint locks up table  (Florian Weimer <fweimer@bfk.de>)
Ответы Re: adding foreign key constraint locks up table  (Florian Weimer <fweimer@bfk.de>)
Список pgsql-performance
Florian Weimer <fweimer@bfk.de> 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

В списке pgsql-performance по дате отправления:

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: Re: adding foreign key constraint locks up table
Следующее
От: Greg Smith
Дата:
Сообщение: Re: Regression: 8.3 2 seconds -> 8.4 100+ seconds