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 1vyq6C-000T38-1x for pgsql-general@arkaria.postgresql.org; Sat, 07 Mar 2026 11:45:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vyq6B-008Vhb-0M for pgsql-general@arkaria.postgresql.org; Sat, 07 Mar 2026 11:45:35 +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 1vyq6A-008VhS-2Y for pgsql-general@lists.postgresql.org; Sat, 07 Mar 2026 11:45:35 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vyq68-00000000zcS-3ByV for pgsql-general@lists.postgresql.org; Sat, 07 Mar 2026 11:45:34 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 627BjTI0624994; Sat, 7 Mar 2026 06:45:29 -0500 From: Tom Lane To: Shaheed Haque cc: pgsql-general list Subject: Re: Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update() In-reply-to: References: Comments: In-reply-to Shaheed Haque message dated "Sat, 07 Mar 2026 09:24:32 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30225.1772883929.1@sss.pgh.pa.us> Date: Sat, 07 Mar 2026 06:45:29 -0500 Message-ID: <30226.1772883929@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Shaheed Haque writes: > How can there be a deadlock between updates to different rows (as per the > bolded WHERE clauses)? In isolation, there couldn't be ... but you've told us nothing of what these transactions did beforehand. The simplest explanation is that each one is already holding a lock on the row the other one wants. Maybe you are not committing between row updates? If you have no better debugging ideas, try setting log_statements = all and then examining everything the transactions did up to the failure. regards, tom lane