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 1vzMIl-000vhi-0d for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2026 22:08: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 1vzMIi-00Bezz-1b for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2026 22:08:40 +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 1vzMIi-00Bezr-0J for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2026 22:08:40 +0000 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzMIf-00000001BiP-2lYF for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2026 22:08:39 +0000 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-46701f2077cso536958b6e.0 for ; Sun, 08 Mar 2026 15:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773007717; cv=none; d=google.com; s=arc-20240605; b=FacGjyv+GWwE5/R3yZdGr0sz9zOHuZnuw37ZI6gn9HMyMVXVxy1Zk7wzpRtq4Bga1U yw3NppzOOAyJNqfJPlEcLnFSwG/1tZoiXH+CA+SPyG0mBxc7/zABcRPOV+91Qs0FOXRx KvyXLAASdXO4DMUj/JbJ7pXuEcfKV5j//IX8+8itqgYR5nGB9ygpwtCb3Nu6UAdgpHEn x4ATGFs7ROJAfSRqruEMNf2Oxg64aZ/RTBDElHoh8WMnb0qhA97O7hWKGoQx9nrizUhs Si0uei09R9jEKccMWJhXeurRZIRJPElIADevPg6zD86c6nUu683sAGfJuUPFQYChUROQ EEvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=8+7BU7zm9UiaM8zyyekVmfEpzpo868CbEPGA15Y9Zhs=; fh=pYlkZbsn/WOPctNgubLE5p+7czOJWMZ4WXLc7+RHM5U=; b=NrSOd78eme4LE5SZhcGkZh2EApVQ9d/W3qKyhPb7KT0inCA8M6vNa0I8yvwTW/2/+N qXehyLRF+whQqiwrfhtLwN8IKWCwj8i+e771zcxJVe+eAAgo/Srpty/SE3WHHHgsxh6B Gt6qf0kTf8AMYVdmx1eY3VwDcIpbjxJrA2CKMdAtD3tiAM7TbKfoNakfPyAYdw8NseN7 Np4S3o1dSqzT/vGLvPpzfvTV3intkWAO5y8d8u2MMRY2aNuK9sI/i0xu8+swMr36UmAh K+xFZI5wb7/FKaYYfVNbfNpRD9sTWCE6/yJ4ynf1hlLr7OukE6fnO5EiLQUBeOtF0AB/ K3Gw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773007717; x=1773612517; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=8+7BU7zm9UiaM8zyyekVmfEpzpo868CbEPGA15Y9Zhs=; b=ND5jkqFaslpjf5Iz4sLCNFgFmKXAa7cGf6d1umbE8Qz6S6Hx0fzzPwSKnjwQd2VeJ8 /QLE1TGyQh9x4Pl4WdJwOe7o78PVmfgsm/fQ317D0rzzM+1G0NqHw84ow9UQSpiYODny 5z+HkmyufburkBiHqrw6Mlc8KKuIKyQQsxxp4nd1xQ3CUnxu0ZgFLWo0VvIxULjag2Wf goFyu9GFcHXG8l2raWnaCJ+tYl/EoP3+/de9mWYd8Y6aHeZGHxcjEgMe5WK1gdllH0h8 WDnAKF57r+5bGEzY25WQmqOf0Esu5FpZxdIxcPmoNFvzSpmDSVH4X4bwKQKosFsW9+KB 9qCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773007717; x=1773612517; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8+7BU7zm9UiaM8zyyekVmfEpzpo868CbEPGA15Y9Zhs=; b=Ls/iL4QRUp5wIBB3OsDKOpZXxFvfQUWXo4CFzFP2Zf1xCepSFaWzQb7CBlow056GOt IsGOPqG1oa3DX9Ch3WKgkjn1yEb/XcQ56XM8ak3GwGL9xbWIVFxZxqmER8MsbsItNaGV 4f2qmNlkkJNsU0v6Qbz/lEjtTCeEOR4AURSk66ei59XJ2sGLzlLSUMjoMJmgZ8ntkgn8 SJr29i5BWD4f04C2nMiFMglAygu1pDDFgtnzAtY1+FSEf3Y2YkhPYIGwslJmpWTrQKtJ RpRY5QnbE11uqtSRyKMtDdIT4nWTvotW7C7AyP6UgeAH2RJ9ONWJfq/Pe3ppD31CTNk2 vkLg== X-Gm-Message-State: AOJu0YyE7BzkRpe9fnnyzRu/fthxBVNPt497Q+tDOxJrjLm6+Nqazkz6 vmGIiJIbp5Cb4hwwGVSSobRne2xcCiec9IemJy2Y2dgUMtXKpTMYIiKyqU74YwABzl7/wFL4+Qt DsdpoLbGHY2BY1mYX2zCq7I9uNQOd63Q= X-Gm-Gg: ATEYQzxQQxkno/4axDGz8KLipuQesAMan50fQ0QipGHBfEtQEmnoSSrUm9PJ2xOgn67 zG7vlXVu1dQyQf0cIWUYbvjDFq57r2qQu5ynbsw+4ejl6vGjq9ZHacCgLfXr3EEumAup1Ht3Doa dCAd97yxowDXZxI5kljfr9JSOrsgdQWOEbfUcbZcFQoHlCf2bAXcuDoWeshKtCeiuatYt8SfXwx 4zKwQoIDL6ah1R/TgBDVssHbR5ZlQDvvCrCQzyjhvyyaHDOdb07rl0c/BB3GMqedq7qH0NP619c F5DFKQ4aAsPXsHCPzAsUl88Jebtw+HYLzlpBQ5PE X-Received: by 2002:a4a:e911:0:b0:67b:ab9c:7565 with SMTP id 006d021491bc7-67bab9c77a9mr2703034eaf.22.1773007716998; Sun, 08 Mar 2026 15:08:36 -0700 (PDT) MIME-Version: 1.0 References: <1164079167.6346688.1772982934392@mail.yahoo.com> <1656643760.2116109.1772994207524@mail.yahoo.com> In-Reply-To: <1656643760.2116109.1772994207524@mail.yahoo.com> From: Greg Sabino Mullane Date: Sun, 8 Mar 2026 18:08:01 -0400 X-Gm-Features: AaiRm50ShaH27FPRVFcWk0eLXH5OSzodusUhzikHeALRn0OdGweuOgK7btZAJCU Message-ID: Subject: Re: Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update() To: felix.quintgz@yahoo.com Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000027e3f1064c8a8769" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000027e3f1064c8a8769 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Mar 8, 2026 at 2:23=E2=80=AFPM wrote: > What makes me suspect it's a lock on the parent table is the word > "ShareLock" in the logs. A SELECT ... FOR UPDATE statement shouldn't plac= e > that type of lock on the table it's selecting. > This looks 100% like a normal, multi-row deadlock situation. The CONTEXT shows it is a row-level problem: CONTEXT: while locking tuple (7,15) in relation =E2=80=9Cpaiyroll_endpoint= =E2=80=9D The ShareLocks are on the transaction, because each backend is waiting for the other to finish their transaction, and thus release the lock(s) it may have. If you implement Tom's suggestion, I think you will find that this is a classic failing to lock the rows in the same order problem. Cheers, Greg --00000000000027e3f1064c8a8769 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Mar 8, 2026 at 2:23= =E2=80=AFPM <felix.quintgz@ya= hoo.com> wrote:
What makes me suspect it's a lock on the parent table is the wor= d "ShareLock" in the logs. A SELECT ... FOR UPDATE statement shou= ldn't place that type of lock on the table it's selecting.
<= div>
This looks 100% like a nor= mal, multi-row deadlock situation. The CONTEXT shows it is a row-level prob= lem:

CONTEX= T: while locking tuple (7,15) in relation =E2=80=9Cpaiyroll_endpoint=E2=80= =9D

The ShareLocks are on the transaction, = because each backend is waiting for the other to finish their transaction, = and thus release the lock(s) it may have.

If you i= mplement Tom's suggestion, I think you will find that this is a classic= failing to lock the rows in the same order problem.

Cheers,
Greg

--00000000000027e3f1064c8a8769--