Re: Can two “SELECT FOR UPDATE” statements on the same table cause a deadlock? - Mailing list pgsql-general

From Tom Lane
Subject Re: Can two “SELECT FOR UPDATE” statements on the same table cause a deadlock?
Date
Msg-id 16757.1349921393@sss.pgh.pa.us
Whole thread Raw
In response to Can two “SELECT FOR UPDATE” statements on the same table cause a deadlock?  (Steve A <golfmat1@yahoo.com>)
List pgsql-general
Steve A <golfmat1@yahoo.com> writes:
> In a nutshell, I'm curious about the order in which PG will lock rows during a SELECT FOR UPDATE. If two simultaneous
SELECTFOR UPDATE statements select intersecting rows from the same table, can PG be relied upon to lock the rows in a
consistentmanner that always avoids deadlock (e.g. in order of ascending primary key)? 

Only if you use ORDER BY in each such query to constrain the rows to be
locked in the same order.  You probably want to spend some time perusing
the fine manual very carefully:
http://www.postgresql.org/docs/9.2/static/sql-select.html#SQL-FOR-UPDATE-SHARE

            regards, tom lane


pgsql-general by date:

Previous
From: Steve A
Date:
Subject: Can two “SELECT FOR UPDATE” statements on the same table cause a deadlock?
Next
From: Sean Chittenden
Date:
Subject: Re: 'full_page_writes=off' , VACUUM and crashing streaming slaves...