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 1vzIn2-000sgC-21 for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2026 18:23:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzImz-00BKax-2B for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2026 18:23:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vzImz-00BKao-1D for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2026 18:23:41 +0000 Received: from sonic306-21.consmr.mail.ne1.yahoo.com ([66.163.189.83]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzImr-00000001bAR-3ikE for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2026 18:23:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1772994210; bh=kSy0iSeq7V9LU3UvJi40adCOVBxjhBUK5OsKXB/+wTE=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject:Reply-To; b=d0dlp7cr9F94TkZTPFKZRsEwh9nYh/ApMu8H2qukf5094gtVSD7rUA5X//KN7OBE3Q9dqnBtVxlYE/p7VYxHQilWf6ubMXbNxyGPPKhjxpTNEbgnCwUHTRriADu5sm1vFdJlfKI7p+z2KhfL4oeJtuDK3VH3mnyCnQ3gFtpVqR/5ZBit04pYBRJb+u1XzbAKzq+qm7E5RmMEWHs+JC5M5PbKgYHvEf4STPYnSI9+WlfIarz7INoEQVokclq6C87vErSoYbtnFViVQpjANFjOiWq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ApZ.ZM0ljFgIZVlIJa j3rwh8grDIdoQ.Pu4zKTmBR7wwEkuzpk83kd.qG3y9.ZLoPTbjQm0PZrqZnRtYezYAam1S.aonOe c3XXmW5xIXKI5q_2Secfn6EX2NOJoxbuojUZQ3JCAtxCn8vvdtA_M0g03G9j25WAdbIYNtpua6zb mLJnXQL6cgNtILProMN5ItVF4yEcxzYzYapZMhgQwxKBdA5dgzYplsfpELOph7ZiIJ7hx1yMbQGb MVQh1dtSI.y9j8uHciO4HA39kOKz_PX2Kl.O1n_OjAQkJGQSlFh_RXkYcIYdF7v0jjQAOV7JUjV9 R2rfFocThJ692sCbfM0k_6YODy7nXXDjNmyVTqHHK.MrUZDuYh3yDZ.oqGH7PXjqAfKYo4FPKI1. cM.HnkLb9SqhN3brcjd8lyx78Pe_YB.alfisT6p_x58GOcwk9V6n0Zx8MRfnBRKOCGu53pA0hfBW fwnSagVNYyD7LHzJFisX4UuoAsXmvRGgm2EG_ESM7aD7uSAd0el6ma4dQ6PbLgi0VPeHgVpevQ7U f2iJcrYyz9mTtxPxMJCoaGNJEu0tW9jsF_f.LsmiS4.cAP68jK.LAxMErUNHtUaU4uJbv6Sw1Ve0 snR4vpK4Xl_1h8ZNZKtM79wg_8F5CxGteXuIY9EvrX.Bn5by1d_wtEOUw1iz96Xgg0eoqIwT4KIE b0yalcuI_1U4hwOsUDxmb X-Sonic-MF: X-Sonic-ID: 4be4f08e-f6e5-49a5-9346-5ce4c11bd9c5 Received: from sonic.gate.mail.ne1.yahoo.com by sonic306.consmr.mail.ne1.yahoo.com with HTTP; Sun, 8 Mar 2026 18:23:30 +0000 Date: Sun, 8 Mar 2026 18:23:27 +0000 (UTC) From: felix.quintgz@yahoo.com To: pgsql-general@lists.postgresql.org Message-ID: <1656643760.2116109.1772994207524@mail.yahoo.com> In-Reply-To: References: <1164079167.6346688.1772982934392@mail.yahoo.com> Subject: Re: Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailer: WebService/1.1.25198 YMailNodin Content-Length: 1890 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I've found some references indicating that it does this, but the lock on th= e parent table had to be shared to prevent the deletion of the row from the= parent table. What makes me suspect it's a lock on the parent table is the word "ShareLoc= k" in the logs. A SELECT ... FOR UPDATE statement shouldn't place that type= of lock on the table it's selecting. On Sunday, March 8, 2026 at 12:19:35 PM GMT-4, Shaheed Haque wrote: On Sun, 8 Mar 2026 at 15:15, wrote: This is pure speculation. It's possible that using SELECT FOR UPDATE also locks the rows in the paren= t tables referenced in the field list. I believe this happened in older versions of PostgreSQL. Interesting. In the query, paiyroll_endpoint.op_id and paiyroll_endpoint.cl= ient_id ARE foreign keys to other tables. But I don't see any reference to locking rows in parent tables in the docs = around=C2=A0https://www.postgresql.org/docs/current/explicit-locking.html#L= OCKING-ROWS. A quick poke around did not reveal any documentation that conf= irms this one way or another. And to my admittedly in-expert thinking, it s= eems surprising=C2=A0that the parent might need to be locked? =C2=A0On Saturday, March 7, 2026 at 04:25:01 AM GMT-5, Shaheed Haque wrote: =C2=A0[I originally posted this over at=C2=A0https://forum.djangoproject.co= m/t/unexpected-deadlock-across-two-separate-rows-using-postgres-17-and-sele= ct-for-update/44294/1, but that thread ran into a dead end. Apologies for t= he cross-post] Hi, I'm trying to understand/fix a rare deadlock in my application. Given my li= mited knowledge, what seems odd to me is that the deadlock involves two pro= cesses=C2=A0running exactly the same code/query, each of which (tries to) a= void issues by locking exactly one row for update. In Django-speak, the cod= e does this: