From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | Matt Mello <alien(at)spaceship(dot)com> |
Cc: | Jan Wieck <JanWieck(at)Yahoo(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: "deadlock detected" / cascading locks |
Date: | 2003-05-19 22:28:06 |
Message-ID: | 20030519152242.G42425-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, 19 May 2003, Matt Mello wrote:
> Jan, can you explain more to a newby like me what you mean by "the
> sessions set deferred modes differently?"
If a constraint is deferred in one transaction and not in another the
order the locks are grabbed could be different. For example you have two
constraints A and B, and two transactions T1 and T2. T1 sets constraint A
to be deferred, T2 has constraint A being immediate. T1 will get the lock
for B first (at end of statement) and then get lock A second (at end of
transaction). T2 will get lock A first (at end of statement) and B second
(at end of statement). This could cause deadlock if both transactions do
something that locks the same rows for A and B and T1 gets the B lock,
then T2 gets the A lock, then T2 waits on T1 for the B lock, then T1 waits
for T2 on the A lock when it goes to commit.
> And, do these locks cascade? If I choose to do an update on table A,
> and it has a foreign key to table B, which has a foreign key to table C,
> does the update-induced lock on A cause a lock on B /and/ C?
Not for checks since those don't change the table in question. It's
possible for locks to cascade through referential action effects (although
that effect is partially minimized by the bug fix mentioned for
update unless the referencing column is itself the one being referenced)
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2003-05-19 22:49:21 | Re: CASE |
Previous Message | Josh Berkus | 2003-05-19 22:04:58 | Re: Performance on temp table inserts |