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)
Ответы: Re: adding foreign key constraint locks up table  (Florian Weimer)
Список: pgsql-performance

Скрыть дерево обсуждения

adding foreign key constraint locks up table  (kakarukeys, )
 Re: adding foreign key constraint locks up table  (Gurjeet Singh, )
  Re: adding foreign key constraint locks up table  ("Kevin Grittner", )
   Re: adding foreign key constraint locks up table  (Gurjeet Singh, )
    Re: adding foreign key constraint locks up table  ("Kevin Grittner", )
 Re: adding foreign key constraint locks up table  (Lew, )
 Re: adding foreign key constraint locks up table  (kakarukeys, )
  Re: adding foreign key constraint locks up table  (Gurjeet Singh, )
 Re: adding foreign key constraint locks up table  (Florian Weimer, )
  Re: adding foreign key constraint locks up table  (Tom Lane, )
   Re: adding foreign key constraint locks up table  (Florian Weimer, )
    Re: adding foreign key constraint locks up table  (Tom Lane, )
 Re: adding foreign key constraint locks up table  (kakarukeys, )
  Re: adding foreign key constraint locks up table  (Robert Haas, )
 Re: adding foreign key constraint locks up table  (kakarukeys, )

Florian Weimer <> 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 по дате сообщения:

От: Tom Lane
Дата:
Сообщение: Re: adding foreign key constraint locks up table
От: Greg Smith
Дата:
Сообщение: Re: Regression: 8.3 2 seconds -> 8.4 100+ seconds