Re: Tracking down a deadlock

From: Bill Moseley <moseley(at)hank(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Tracking down a deadlock
Date: 2009-05-04 05:02:40
Message-ID: 20090504050240.GA27504@hank.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)hank(dot)org
Sent from my iMutt

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Allan Kamau 2009-05-04 08:02:22 Calculating product from rows - (aggregate product )
Previous Message Tom Lane 2009-05-04 01:08:29 Re: Tracking down a deadlock