From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mladen Gogala <gogala.mladen@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: pg_try_advisory_lock is waiting?
Date: Fri, 28 Jan 2022 19:08:14 -0500
Message-ID: <2858894.1643414894@sss.pgh.pa.us> (raw)
In-Reply-To: <54e6a2bc-3546-88c7-0382-c74f23e4b668@gmail.com>
References: <54e6a2bc-3546-88c7-0382-c74f23e4b668@gmail.com>
Mladen Gogala <gogala.mladen@gmail.com> writes:
> I tried the following:
> _*1st Session:*_
> mgogala=# begin transaction;
> BEGIN
> mgogala=*# update emp set sal=sal*1 where empno=7934;
> UPDATE 1
> mgogala=*#
> _*2nd Session:*_
> mgogala=# begin transaction;
> BEGIN
> mgogala=*# select pg_try_advisory_lock(0) from (select ename from emp
> where empno=7934 for update) as tbl;
> To my infinite surprise, "pg_advisory_lock" is waiting.
I doubt it. I think the FOR UPDATE in the sub-select is blocked
because the other session has an uncommitted update on the row
it wants to lock. This command won't reach the pg_try_advisory_lock
call until that row lock comes free.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, gogala.mladen@gmail.com
Subject: Re: pg_try_advisory_lock is waiting?
In-Reply-To: <2858894.1643414894@sss.pgh.pa.us>
References: <54e6a2bc-3546-88c7-0382-c74f23e4b668@gmail.com> <2858894.1643414894@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox