Re: Frequent 'deadlock detected' in 7.4 ... or just my bad code?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Frequent 'deadlock detected' in 7.4 ... or just my bad code?
Date: 2004-04-05 15:13:54
Message-ID: 11570.1081178034@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

"Marc G. Fournier" <scrappy(at)postgresql(dot)org> writes:
> Now, the scripts are wrap'd in a BEGIN/END ... if a file fails to be
> loaded, I want the whole thing to rollback ... the deadlock itself, I'm
> presuming, is because two servers are trying to update the same
> $ip_id/$port/$company_id record, at the same time ...

Actually, the problem is more likely that two servers try to update two
different rows in opposite orders. It's not possible to deadlock when
only one lock is involved.

You could work around this by ensuring that all sessions update rows in
a consistent order; for instance, at the beginning of a transaction sort
your intended updates by primary key and then apply in that order.

regards, tom lane

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Anjan Dave 2004-04-05 16:50:50 Use 7.4.1's pg_dump in 7.2.4?
Previous Message Marc G. Fournier 2004-04-05 14:53:05 Frequent 'deadlock detected' in 7.4 ... or just my bad code?