Re: "deadlock detected" documentation - Mailing list pgsql-sql

From Tom Lane
Subject Re: "deadlock detected" documentation
Date
Msg-id 10096.1053017383@sss.pgh.pa.us
Whole thread Raw
In response to Re: "deadlock detected" documentation  (Matt Mello <alien@spaceship.com>)
Responses Re: "deadlock detected" documentation
List pgsql-sql
Matt Mello <alien@spaceship.com> writes:
> There are no triggers or rules except for the foreign keys.
> The txn table has several foreign keys.

You are probably getting deadlocks on the rows referenced by the foreign
keys, then.  As of the current release, each UPDATEd row will cause the
foreign-key triggers to grab a row lock (SELECT FOR UPDATE lock) on the
referenced row in the other table.  If you have concurrent updates
touching rows that reference the same other-table rows, it's possible to
get a deadlock depending on the order in which the updates happen to
occur.

There is no particularly good SQL-level workaround for this; the only
one I can think of is to do the updates one row at a time (or at least
one foreign-key value at a time), which sucks.

There is a patch in CVS tip that alleviates the problem substantially
by not taking a foreign-table lock when the foreign key value isn't
being changed by the UPDATE, which is commonly the case (although I'm
not entirely sure that it will help you, since you do seem to be
updating the referencing column).  If you want to try it, I believe Jan
Wieck posted a 7.3 version of the patch a month or so ago.
        regards, tom lane


pgsql-sql by date:

Previous
From: Ian Barwick
Date:
Subject: Re: Inquiry From Form [pgsql]
Next
From: Matt Mello
Date:
Subject: Re: "deadlock detected" documentation