Re: "deadlock detected" documentation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matt Mello <alien(at)spaceship(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: "deadlock detected" documentation
Date: 2003-05-15 16:49:43
Message-ID: 10096.1053017383@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Matt Mello <alien(at)spaceship(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Matt Mello 2003-05-15 16:59:38 Re: "deadlock detected" documentation
Previous Message Ian Barwick 2003-05-15 16:41:42 Re: Inquiry From Form [pgsql]