RE: Row locks, SKIP LOCKED, and transactions

2019-12-19 Thread Steven Winfield
> (Or you could use serializable mode, but that feels like using a hammer to > swat a fly.) Do you mean the serializable transaction isolation level? Because that doesn't work either. Here (finally) is a tiny repro case. You'll need 2 psql sessions (S1, S2): S1: CREATE TABLE t (id integer): S1

Re: Row locks, SKIP LOCKED, and transactions

2019-12-18 Thread Tom Lane
Steven Winfield writes: >> There are various ways you could deal with this, but I'd probably go for a >> simple scheme where you only have to consult a single row to know if you >> can claim it. You could still put the results into a separate table, but >> use job.state to find work, and set it t

RE: Row locks, SKIP LOCKED, and transactions

2019-12-18 Thread Steven Winfield
> Huh. SERIALIZABLE shouldn't allow two transactions to see no result row > for a given ID and then insert a result row for that ID. One of those > transactions should have to roll back, because otherwise it'd be > incompatible with both serial orderings of the two transactions. Sorry for the mi

RE: Row locks, SKIP LOCKED, and transactions

2019-12-18 Thread Steven Winfield
>> * I observe this even if I crank up the transaction isolation level to >> repeatable read and serializable. >> >> >> I'm wondering if row locks are not obeying the same transactional semantics >> as row data, >Gotta believe it is this: > >https://www.postgresql.org/docs/11/transaction-iso

Re: Row locks, SKIP LOCKED, and transactions

2019-12-17 Thread Thomas Munro
On Wed, Dec 18, 2019 at 5:12 AM Steven Winfield wrote: > * I observe this even if I crank up the transaction isolation level to > repeatable read and serializable. Huh. SERIALIZABLE shouldn't allow two transactions to see no result row for a given ID and then insert a result row for that ID. O

Re: Row locks, SKIP LOCKED, and transactions

2019-12-17 Thread Adrian Klaver
On 12/17/19 8:12 AM, Steven Winfield wrote: Hi all, I'm seeing some unexpected behaviour with SELECT ... FOR UPDATE SKIP LOCKED, and having finding it tricky to boil it down to a simple repro case as there's almost certainly a race condition somewhere (more later). So I thought I would ask if