Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iooB9-0003lw-SO for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Jan 2020 12:41:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iooB8-0001Ty-Ku for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Jan 2020 12:41:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iooB8-0001Tr-D1 for pgsql-bugs@lists.postgresql.org; Tue, 07 Jan 2020 12:41:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iooB6-0001V8-4A for pgsql-bugs@lists.postgresql.org; Tue, 07 Jan 2020 12:41:46 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 007Cfeg3004821; Tue, 7 Jan 2020 07:41:40 -0500 From: Tom Lane To: andy ye cc: pgsql-bugs@lists.postgresql.org Subject: Re: About postgresql pg_advisory_xact_lock use!!!! In-reply-to: <7F90A703-8E89-4D22-AA2B-41B643D4E1F9@gtssz.net> References: <7F90A703-8E89-4D22-AA2B-41B643D4E1F9@gtssz.net> Comments: In-reply-to andy ye message dated "Tue, 07 Jan 2020 17:22:16 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4819.1578400900.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 07 Jan 2020 07:41:40 -0500 Message-ID: <4820.1578400900@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk andy ye writes: > When I use the pg_advisory_xact_lock provided by postgresql, I often se= e that the lock part cannot be released and the service is blocked. I woul= d like to know what situations might cause this behavior. Thank you!!! I'd say the odds are just about 100% that you're not closing the transaction. Transaction-scope advisory locks are managed exactly like any ordinary lock in the system, so if we had a bug that allowed them to not be released at transaction end, there would be obvious consequences everywhere. regards, tom lane