Re: Order of locking in postgres SELECT FOR UPDATE

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: pgeu-general(at)postgresql(dot)org
Subject: Re: Order of locking in postgres SELECT FOR UPDATE
Date: 2015-03-15 06:30:54
Message-ID: 1426401054.4565.3.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgeu-general

On Sat, 2015-03-14 at 10:59 -0600, Eric Springer wrote:
> I asked the question on Stack Overflow:
> http://stackoverflow.com/questions/29041327/order-of-locking-in-postgres-select-for-update
>
> but haven't got any answers, so reposting it here:
>
>
> Assuming both table a and b has a single row, the query:
>
> SELECT * FROM a, b FOR UPDATE
>
> should get two row-level locks (one on a, one on b). Is there any
> defined ordering in which the locks are acquired? And is there any way
> to require the lock from the table b to get acquired lock before the
> one from a (to avoid deadlocking with other transactions)?
>
>
I can't answer the specific question, but why not simply make two
separate SELECTs in the required order?

In response to

Browse pgeu-general by date

  From Date Subject
Next Message Albe Laurenz 2015-03-16 09:33:32 Re: Order of locking in postgres SELECT FOR UPDATE
Previous Message Eric Springer 2015-03-14 16:59:07 Order of locking in postgres SELECT FOR UPDATE