Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vqUiX-00BsBv-2D for pgsql-general@arkaria.postgresql.org; Thu, 12 Feb 2026 11:18:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqUiX-008Cnv-04 for pgsql-general@arkaria.postgresql.org; Thu, 12 Feb 2026 11:18:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vqUiW-008Cnn-29 for pgsql-general@lists.postgresql.org; Thu, 12 Feb 2026 11:18:41 +0000 Received: from mout01.posteo.de ([185.67.36.65]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vqUiT-00000000H5B-48Yf for pgsql-general@postgresql.org; Thu, 12 Feb 2026 11:18:40 +0000 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 75399240027 for ; Thu, 12 Feb 2026 12:18:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posteo.de; s=2017; t=1770895114; bh=RuOLN1/gApCHh2dW/gbnTU25jVxdC/hpJiGP++L7vmE=; h=Content-Type:Message-ID:Date:MIME-Version:Subject:To:Cc:From: From; b=WCe8YNOnYoCblPNhPGosr3r4hKzIBAGickw+dII4DfZDXskFlqBBglKmDPiJZz4QQ iwJvW1PECG9zDzRtQWelWCjtPMSk0a1bJ2uWM3hVTYs9+EBeGKOa1IwaqDokuQCrVr Afqfuum2v4GPcKBB70ToRKjd/zWoLdKVfjAUJME/+8jlRjl6eMrrJDtEKRy+R9yV2j fgY24ajwcgnfP2MdfhAf+Z3f4Qnelbr65jNSyuzQEjSW/lKf6q1qny3l1Aq+FWjHpI mfr+ol8ZbCK0EdXqxJo5U1CH/bFv+Q7GdXLjYHyjmdqOsh6QfB8x5FN1MQDMMiNAcR idjG4keDgOanA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4fBXqF6YLXz9rxL; Thu, 12 Feb 2026 12:18:32 +0100 (CET) Content-Type: multipart/alternative; boundary="------------xw9oP2bYBV8MqVnR0qcX4w2Q" Message-ID: <777cfa1c-fd1f-479f-b9b8-217b0f7a40b7@posteo.de> Date: Thu, 12 Feb 2026 11:18:34 +0000 MIME-Version: 1.0 Subject: Re: Guarantee order of batched pg_advisory_xact_lock To: Tom Lane Cc: pgsql-general@postgresql.org References: <93fb937f-9f4d-4bd7-b7e6-51d5f98859d9@posteo.de> <14506.1770844674@sss.pgh.pa.us> <101916.1770850197@sss.pgh.pa.us> Content-Language: en-US From: Nico Heller In-Reply-To: <101916.1770850197@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------xw9oP2bYBV8MqVnR0qcX4w2Q Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit I just checked for hash collisions with the following query today: SELECT COUNT(*), hashtextextended(key, 0) FROM (   SELECT key FROM table1   UNION   SELECT key FROM table2   UNION   ... ) keys (key) GROUP BY hashtextextended(key, 0) HAVING COUNT(*) > 1 Where table1, table2, ... are all the tables we are acquire keys from to use for the mentioned query. Sadly, no results were returned. Thus, I can rule out hash collisions. Any other thoughts? Here is an error log from the JDBC driver: org.postgresql.util.PSQLException: ERROR: deadlock detected Detail: Process 60780 waits for ExclusiveLock on advisory lock [24605,3030106527,494580150,1]; blocked by process 65280.  Process 65280 waits for ExclusiveLock on advisory lock [24605,1321834016,1311356115,1]; blocked by process 60780. On 2/11/26 23:49, Tom Lane wrote: > Nico Heller writes: >> So it would probably be better to ORDER BY the hashtextended result >> instead of :keysToLock, right? > Yeah, that seems like it'd work, if you have no other dependencies > on the locking order. > > regards, tom lane --------------xw9oP2bYBV8MqVnR0qcX4w2Q Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

I just checked for hash collisions with the following query today:

SELECT COUNT(*), hashtextextended(key, 0) FROM
(
  SELECT key FROM table1
  UNION
  SELECT key FROM table2
  UNION
  ...
) keys (key)
GROUP BY hashtextextended(key, 0)
HAVING COUNT(*) > 1

Where table1, table2, ... are all the tables we are acquire keys from to use for the mentioned query.

Sadly, no results were returned. Thus, I can rule out hash collisions.

Any other thoughts? Here is an error log from the JDBC driver:


org.postgresql.util.PSQLException: ERROR: deadlock detected Detail: Process 60780 waits for ExclusiveLock on advisory lock [24605,3030106527,494580150,1]; blocked by process 65280.
                                                                                                                 Process 65280 waits for ExclusiveLock on advisory lock [24605,1321834016,1311356115,1]; blocked by process 60780.



On 2/11/26 23:49, Tom Lane wrote:
Nico Heller <nico.heller@posteo.de> writes:
So it would probably be better to ORDER BY the hashtextended result 
instead of :keysToLock, right?
Yeah, that seems like it'd work, if you have no other dependencies
on the locking order.

			regards, tom lane
--------------xw9oP2bYBV8MqVnR0qcX4w2Q--