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.94.2) (envelope-from ) id 1raO70-009X0l-J8 for pgsql-general@arkaria.postgresql.org; Wed, 14 Feb 2024 22:52:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1raO6y-0095eL-79 for pgsql-general@arkaria.postgresql.org; Wed, 14 Feb 2024 22:52:16 +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.94.2) (envelope-from ) id 1raO6x-0095eD-Sr for pgsql-general@lists.postgresql.org; Wed, 14 Feb 2024 22:52:15 +0000 Received: from hammy.handig-eekhoorn.at ([2a01:4f8:10b:f6e0:5054:ff:fe77:fb6]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1raO6u-006mYe-Ew for pgsql-general@postgresql.org; Wed, 14 Feb 2024 22:52:14 +0000 Received: from hammy.handig-eekhoorn.at (localhost.localdomain [127.0.0.1]) by hammy.handig-eekhoorn.at (Proxmox) with ESMTP id 51A0120CF7 for ; Wed, 14 Feb 2024 23:52:08 +0100 (CET) Received: from margarita.erven.at (80-109-180-71.cable.dynamic.surfer.at [80.109.180.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by hammy.handig-eekhoorn.at (Proxmox) with ESMTPS id 30A36202FD for ; Wed, 14 Feb 2024 23:52:08 +0100 (CET) Received: from [192.168.27.99] (unknown [192.168.27.99]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by margarita.erven.at (Postfix) with ESMTPSA id CB525DFC for ; Wed, 14 Feb 2024 23:52:07 +0100 (CET) Message-ID: <78ae159b-db92-4f03-995e-27ca75d17622@erven.at> Date: Wed, 14 Feb 2024 23:52:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Hannes Erven Subject: RowLock and multiple transactions Content-Language: en-US To: pgsql-general Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, when "SELECT .. WHERE .. FOR NO KEY UPDATE" is used synchronize access, and the transaction holding the lock completes, how does PostgreSQL decide /which one/ of multiple waiting transactions will the lock be granted to next? In my testing (on Ubuntu 16.1-1.pgdg20.04+1, 64bit) with a real-world application (that acquires multiple locks on a number of relations) it seems that it is always the transaction that attempted to lock _last_ ... ? I thought that would most probably be random, or if it was not, the order would have been explained in the docs? Thank you for any insights... Best regards -hannes