|From:||Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>|
|To:||Florian Weimer <fweimer(at)bfk(dot)de>|
|Cc:||kakarukeys <kakarukeys(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org|
|Subject:||Re: adding foreign key constraint locks up table|
|Views:||Raw Message | Whole Thread | Download mbox | Resend email|
Florian Weimer <fweimer(at)bfk(dot)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
|Next Message||Greg Smith||2010-12-29 02:20:02||Re: Regression: 8.3 2 seconds -> 8.4 100+ seconds|
|Previous Message||Kevin Grittner||2010-12-28 15:07:33||Re: adding foreign key constraint locks up table|