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 1wIJ4s-007xuc-1m for pgsql-general@arkaria.postgresql.org; Thu, 30 Apr 2026 04:32: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 1wIJ4r-005pPA-2g for pgsql-general@arkaria.postgresql.org; Thu, 30 Apr 2026 04:32:41 +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 1wIJ4q-005pOx-2T for pgsql-general@lists.postgresql.org; Thu, 30 Apr 2026 04:32:41 +0000 Received: from fout-a4-smtp.messagingengine.com ([103.168.172.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wIJ4n-00000003vFj-2Koj for pgsql-general@lists.postgresql.org; Thu, 30 Apr 2026 04:32:40 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id B4196EC00C3; Thu, 30 Apr 2026 00:32:35 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 30 Apr 2026 00:32:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1777523555; x=1777609955; bh=c13Bfnz/3NOxdkgpHFyKGei/cpnNIDF54WIteRU0Ueo=; b= B+xpTg4Egbv0xK+dDSDN9x8HedwUkHomJ3bp5S8DqQ3xtwVcEOBnD4ZX/4ZppUJx 5SGWBNhHYiGohklSNzHs4lhZFUlNawawa0g9+u1yb9DlE45LWT7Uy/Gxzws/NzU5 HfxtLb9JLzaIuh9hjQuZDGSSEJPSbng8p45y3fYiYPDQ9WcoIeX3LkRAcMgTuSsQ b5LkJRRa+4uRUCEWVg4GJIFwwg1+S0ZWCa2nrVfvByFyHxDD8z88J6ec/fIC2AQJ dhDERVY6iMS+K7lQp+L3UwNUFHerDRSr5u/eMaIsc7neqQZuXMyoMbW6w0Ej7EPW 0t5IH8ySdaFellWXXr6l8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1777523555; x= 1777609955; bh=c13Bfnz/3NOxdkgpHFyKGei/cpnNIDF54WIteRU0Ueo=; b=l O4stEaaJRUPMM+Dm79jGldeIA4aIMvvJvk6ueMF+PThwRpwlY0ARhvkYBzDxgaSE vZ+5RYOTW3XeRNYbVNr1dBP1F7IYFIoXqozcAeUeOMt8kr7ehSfntptppJfA65tW WkurfcIL0oFnInzQ1dfmkT0s6+TBQgtDSvBJC77ZW47uazm9b9NIzatG94677+1H LwZx6myNYleKLKpZ80GTeoUbPJNiygcZEBJl8JsEO3uxzwFI4iq2T74kVTqGGQt4 HAlGROkQnHqSBUo4FPDXNWg8cHP0k/ABFbn79fvWlKQpIjKmg9TZhXSL3wMdnyhZ SZ8Ol6Z7u99O2rSLgcdww== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdekieefjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertd dtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepfeegfeeiuedtgf fgteeggfehkeejheetieeliefgteeikeejvdeiveeigfehvedtnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphho uhhtpdhrtghpthhtohepphhoshhtghhrvghsqhhlrdhorhhgsehmshhqrhdruhhspdhrtg hpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhl rdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Apr 2026 00:32:34 -0400 (EDT) Message-ID: Date: Wed, 29 Apr 2026 21:32:34 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Confirmation on concurrent SELECT FOR UPDATE with ON CONFLICT DO NOTHING To: Matt Magoffin Cc: pgsql-general@lists.postgresql.org References: <087DA595-FB65-49F4-89E9-AE9F5CBF6E4C@msqr.us> <8BCF50C4-D36B-4453-9B09-AA717AE6F563@msqr.us> Content-Language: en-US From: Adrian Klaver In-Reply-To: <8BCF50C4-D36B-4453-9B09-AA717AE6F563@msqr.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/29/26 7:48 PM, Matt Magoffin wrote: > >> On 30 Apr 2026, at 11:37 AM, Adrian Klaver >> 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… > > But I am not finding the info that talks about why the INSERT … ON > CONFLICT DO NOTHING does block until the DELETE finishes. I guess in my > mind the SELECT … 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. This is beginning to get outside my level of understanding. As I see it in the first case the below applies: "SELECT FOR UPDATE will wait for a concurrent transaction that has run any of those commands on the same row, and will then lock and return the updated row (or no row, if the row was deleted). ..." where other commands are "UPDATE, DELETE, SELECT FOR UPDATE, SELECT FOR NO KEY UPDATE, SELECT FOR SHARE or SELECT FOR KEY SHARE". In your case you where doing an INSERT and the ON CONFLICT DO NOTHING meant a DELETE would not reached. In the second case you locked with an explicit DELETE in the first session which prevented the second session from determining whether the ON CONFLICT DO NOTHING actually applied until the first session committed. > > I suppose what I’d 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 -- Adrian Klaver adrian.klaver@aklaver.com