Re: Tracking down a deadlock - Mailing list pgsql-general

From Bill Moseley
Subject Re: Tracking down a deadlock
Date
Msg-id 20090504050240.GA27504@hank.org
Whole thread Raw
In response to Re: Tracking down a deadlock  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Tracking down a deadlock
Re: Tracking down a deadlock
List pgsql-general
On Sun, May 03, 2009 at 09:08:29PM -0400, Tom Lane wrote:
> > There are no other updates to that account table in the transaction, so I'm
> > confused how that is causing a deadlock.
>
> Is there more than one row with the target id?

No.  It's a single SERIAL primary key.


> Does the account table have any foreign-key references to or from it?

Many.  I had dropped all constraints, except foreign keys, from the account
table to see if that would help.  (Didn't).  One CHECK constraint involved
checking the sum of two columns in the account table which seemed like a
potential place for a deadlock.  But I didn't think the foreign keys would be a
problem.

About 8 tables reference the account table, and the account table has about 5
columns that reference other tables.


> It's sometimes possible to get a deadlock associated with trying to lock
> FK-referenced rows that several updated rows have in common.

The transaction has a number of selects and inserts not related to the
account table.  There is an insert into a log table that references the account
table, though, that happens right before the update to the account table.
I can't picture the deadlock, but I'm only familiar with the obvious examples.

What's the approach for dealing with this kind of deadlock (assuming the
FK-related as you suggest)?  I assume at this point I need to try explicit
locking earlier in the transaction.  Any suggestions which lock to use and on
what?  SHARE ROW EXCLUSIVE on the account table before issuing the update?




--
Bill Moseley.
moseley@hank.org
Sent from my iMutt

pgsql-general by date:

Previous
From: PostGre Newbie
Date:
Subject: Re: Online Backups PostGre
Next
From: Allan Kamau
Date:
Subject: Calculating product from rows - (aggregate product )