Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDbHy-00021j-3k for pgsql-general@arkaria.postgresql.org; Sat, 29 Jan 2022 00:08:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nDbHu-0001tD-Vo for pgsql-general@arkaria.postgresql.org; Sat, 29 Jan 2022 00:08:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDbHu-0001sx-HP for pgsql-general@lists.postgresql.org; Sat, 29 Jan 2022 00:08:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nDbHr-00033E-Of for pgsql-general@lists.postgresql.org; Sat, 29 Jan 2022 00:08:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 20T08EMl2858895; Fri, 28 Jan 2022 19:08:14 -0500 From: Tom Lane To: Mladen Gogala cc: pgsql-general@lists.postgresql.org Subject: Re: pg_try_advisory_lock is waiting? In-reply-to: <54e6a2bc-3546-88c7-0382-c74f23e4b668@gmail.com> References: <54e6a2bc-3546-88c7-0382-c74f23e4b668@gmail.com> Comments: In-reply-to Mladen Gogala message dated "Fri, 28 Jan 2022 18:05:18 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2858893.1643414894.1@sss.pgh.pa.us> Date: Fri, 28 Jan 2022 19:08:14 -0500 Message-ID: <2858894.1643414894@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Mladen Gogala 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