Re: Frequent 'deadlock detected' in 7.4 ... or just my bad code? - Mailing list pgsql-admin

From Tom Lane
Subject Re: Frequent 'deadlock detected' in 7.4 ... or just my bad code?
Date
Msg-id 11570.1081178034@sss.pgh.pa.us
Whole thread Raw
In response to Frequent 'deadlock detected' in 7.4 ... or just my bad code?  ("Marc G. Fournier" <scrappy@postgresql.org>)
Responses Re: Frequent 'deadlock detected' in 7.4 ... or just my bad  ("Marc G. Fournier" <scrappy@postgresql.org>)
List pgsql-admin
"Marc G. Fournier" <scrappy@postgresql.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

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: Do Petabyte storage solutions exist?
Next
From: "Anjan Dave"
Date:
Subject: Use 7.4.1's pg_dump in 7.2.4?