Re: Can SELECT … NOWAIT “deadlock”?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Toni Cárdenas <toni(at)tcardenas(dot)me>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Can SELECT … NOWAIT “deadlock”?
Date: 2019-08-20 13:59:07
Message-ID: 5514.1566309547@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

=?UTF-8?Q?Toni_C=C3=A1rdenas?= <toni(at)tcardenas(dot)me> writes:
> Imagine the same `SELECT ... NOWAIT` statement, which returns rows R1 and
> R2, is run from concurrent connections S1 and S2.

> 1. S1 obtains and locks R1.
> 2. S2 obtains and locks R2.
> 3. S1 tries to obtain R2, but it's locked by S2.
> 4. S2 tries to obtain R1, but it's locked by S1.
> 5. The lock on R1 is released due to S1 failing.

> The question is whether step 4 can actually happen between step 3 and 5, or
> else steps 3 and 5 are performed atomically with respect to concurrent
> selects.

I see no reason to think that 3 and 5 would appear to be atomic.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2019-08-20 14:02:07 Re: pg_dump problems: [archiver (db)] query failed: ERROR: relation "pg_opfamily" does not exist
Previous Message Adrian Klaver 2019-08-20 13:32:42 Re: pg_dump problems: [archiver (db)] query failed: ERROR: relation "pg_opfamily" does not exist