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 1wIHSU-007wPd-2K for pgsql-general@arkaria.postgresql.org; Thu, 30 Apr 2026 02:48:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wIHST-005SvQ-37 for pgsql-general@arkaria.postgresql.org; Thu, 30 Apr 2026 02:48:57 +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 1wIHST-005SvF-20 for pgsql-general@lists.postgresql.org; Thu, 30 Apr 2026 02:48:57 +0000 Received: from pmg-2.outbound.snap.net.nz ([202.37.100.107]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wIHSQ-00000003uTR-2t6D for pgsql-general@lists.postgresql.org; Thu, 30 Apr 2026 02:48:57 +0000 Received: from pmg-2.snap.net.nz (localhost.localdomain [127.0.0.1]) by pmg-2.snap.net.nz (Proxmox) with ESMTP id 4B7C23A57D0; Thu, 30 Apr 2026 14:48:45 +1200 (NZST) Received: from smtp.snap.net.nz (smtp.snap.net.nz [202.37.100.140]) by pmg-2.snap.net.nz (Proxmox) with ESMTP id 8791B27A821; Thu, 30 Apr 2026 14:48:43 +1200 (NZST) Received: from x24.msqr.us (msqr.us [123.255.47.99]) by rupert.snap.net.nz (Postfix) with ESMTPS id 7EB58124D; Thu, 30 Apr 2026 14:48:43 +1200 (NZST) Received: from smtpclient.apple (unifi.localdomain [192.168.1.1]) (authenticated bits=0) by x24.msqr.us (8.18.2/8.16.1) with ESMTPSA id 63U2mgaF029766 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 30 Apr 2026 14:48:42 +1200 (NZST) (envelope-from postgresql.org@msqr.us) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=msqr.us; s=20121026; t=1777517323; bh=IjreiE1WxS7LU9vtslRVS7hxNZcG/6bx1VOJYIydbp8=; h=From:Subject:Date:In-Reply-To:Cc:To:References; b=ElHTINsZG9qU+0Gcoj40PSC3JY4CNa30TqKy7tYlWVcw6U4gWFQZR2xGPaW+rntcm c2shqFsmLWP0DMVAux1BKxFet2u504SfpzBc7sUemqnjAD8rUpaOk5GZAN/zRT1zeV 15vZR866UxQi/SY+hwBYJJOqD0d+gTuoSrGBZ6MI= X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 1.5.2 at msqr.us From: Matt Magoffin Message-Id: <8BCF50C4-D36B-4453-9B09-AA717AE6F563@msqr.us> Content-Type: multipart/alternative; boundary="Apple-Mail=_A528BCC8-165A-45C7-85E9-621E633890D6" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.6\)) Subject: Re: Confirmation on concurrent SELECT FOR UPDATE with ON CONFLICT DO NOTHING Date: Thu, 30 Apr 2026 14:48:32 +1200 In-Reply-To: Cc: pgsql-general@lists.postgresql.org To: Adrian Klaver References: <087DA595-FB65-49F4-89E9-AE9F5CBF6E4C@msqr.us> X-Mailer: Apple Mail (2.3826.700.81.1.6) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_A528BCC8-165A-45C7-85E9-621E633890D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 30 Apr 2026, at 11:37=E2=80=AFAM, Adrian Klaver = wrote: >=20 > So in your first case the INSERT is never done and there is no lock = for the INSERT in any case. Thanks for the info, Adrian. And so for my 2nd case, where the INSERT is = blocked by the DELETE statement, I see the docs say The FOR UPDATE lock mode is also acquired by any DELETE on a = row=E2=80=A6 But I am not finding the info that talks about why the INSERT =E2=80=A6 = ON CONFLICT DO NOTHING does block until the DELETE finishes. I guess in = my mind the SELECT =E2=80=A6 FOR UPDATE and DELETE were acquiring the = same kind of row lock, so the behaviour of the INSERT would be the same = across both cases. I suppose what I=E2=80=99d be keen to confirm is that the blocking = behaviour I get with the DELETE is expected behaviour, that I can count = on. Do you know if that is true? Cheers, Matt= --Apple-Mail=_A528BCC8-165A-45C7-85E9-621E633890D6 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On 30 Apr = 2026, at 11:37=E2=80=AFAM, Adrian Klaver = <adrian.klaver@aklaver.com> wrote:

So in = your first case the INSERT is never done and there is no lock for the = INSERT in any case.

Thanks for the = info, Adrian. And so for my 2nd case, where the INSERT is blocked by the = DELETE statement, I see the docs say

The FOR = UPDATE lock mode is also acquired by any DELETE on a = row=E2=80=A6

But I am not finding the info that = talks about why the INSERT =E2=80=A6 ON CONFLICT DO NOTHING does block = until the DELETE finishes. I guess in my mind the SELECT =E2=80=A6 FOR = UPDATE and DELETE were acquiring the same kind of row lock, so the = behaviour of the INSERT would be the same across both = cases.

I suppose what I=E2=80=99d be keen to = confirm is that the blocking behaviour I get with the DELETE is expected = behaviour, that I can count on. Do you know if that is = true?

Cheers,
Matt
= --Apple-Mail=_A528BCC8-165A-45C7-85E9-621E633890D6--