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.94.2) (envelope-from ) id 1usOv0-004a3P-KL for pgsql-general@arkaria.postgresql.org; Sat, 30 Aug 2025 16:59:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1usOuz-00G491-UN for pgsql-general@arkaria.postgresql.org; Sat, 30 Aug 2025 16:59:10 +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.94.2) (envelope-from ) id 1usOuz-00G488-Cj for pgsql-general@lists.postgresql.org; Sat, 30 Aug 2025 16:59:10 +0000 Received: from buffalo.tulip.relay.mailchannels.net ([23.83.218.24]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1usOuw-002hLW-2B for pgsql-general@postgresql.org; Sat, 30 Aug 2025 16:59:09 +0000 X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 462101831EF; Sat, 30 Aug 2025 16:59:02 +0000 (UTC) Received: from pdx1-sub0-mail-a249.dreamhost.com (trex-blue-3.trex.outbound.svc.cluster.local [100.102.95.70]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E3F0B1827AC; Sat, 30 Aug 2025 16:59:01 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1756573141; a=rsa-sha256; cv=none; b=eGiE7Ubf0Ff7TyeoKHhP2UgQTUgZMCZMNnqP7zltipHmxrtNXUs0tBoC/TAowFsy/G567B Uk8cmICwK5MKBk4XrbtjUyhzN3Ee55FCDmYI22QIZqiraKLLzdFGy0xwB413Nv1HmM4w3y 6JHjNkcWxBlRQUj6sM35D4pf63+6mzrRaIbeidg2JOjSkHE3MMUJ+Gse3go0jDLCoDZMs5 CUmwAidg+JfLxs2jS39wyISwmtZZYSCEzcyeBsoS2Vf6AaxzW/Mt6z86+SGewFHkAJqJhs 7c+Gbr6DxXtgvRYosQ2JOrNSm0FKLWPkpMYbCI903Kyg691czeaZ0yNTA7uNLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1756573141; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QrLQvHaDLXRlDhIRIoP1G1uyT/6ftCme4qmBi8ANyFM=; b=X+BnTMumYaFPfPsm1zfhe0R/uLZWbxZOwZ5q6wlXyRhLw0VNe46Tsv7NnNmrINVt8rwEeR qSFI9B/XlAP65cnWl7E5mzzJEZnMTALLdxOSk8k8EHIJ32hLSeyHwMoTRUNC7dXApaExVX cD/JAhDQrNUN0JxbNOgz9OrQLMqWiIozo59tgoRRPPqp7AFxLpiMEtXPoretJNDcXjn6MW nYmtWQs4Z5BEY3bcIVHtGphhO0kHn7/GEmuE6+lClHQJyKvD5e7hZPoVnPFUY4kYRz27ll rpb3QAGCx8Y1OmGIdPagSnugP6/0rsTifqG8amHcR68xufQMyEG+iTdChEGJXA== ARC-Authentication-Results: i=1; rspamd-7b4c58cfff-4bvr6; auth=pass smtp.auth=dreamhost smtp.mailfrom=nico@cryptonector.com X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com X-MailChannels-Auth-Id: dreamhost X-Ruddy-Stop: 70ddd97d6178bfcf_1756573142164_3420851506 X-MC-Loop-Signature: 1756573142164:125657298 X-MC-Ingress-Time: 1756573142164 Received: from pdx1-sub0-mail-a249.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.102.95.70 (trex/7.1.3); Sat, 30 Aug 2025 16:59:02 +0000 Received: from ubby (syn-075-081-095-064.res.spectrum.com [75.81.95.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a249.dreamhost.com (Postfix) with ESMTPSA id 4cDhDj38qtz3P; Sat, 30 Aug 2025 09:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cryptonector.com; s=dreamhost; t=1756573141; bh=QrLQvHaDLXRlDhIRIoP1G1uyT/6ftCme4qmBi8ANyFM=; h=Date:From:To:Cc:Subject:Content-Type; b=CNhTQgj4GLe3xJFGfPZHz0ri3qtuTQeUHoiMs5fnhXT4jC7Arb1fynd31pAJGTPa3 wSffsJMV5se6doaKC9UGjZxhlUrIScKLL2qtzEuJvD3cLSuXdDrsvpTt/6I6sjseW1 +vZbKi4WrzzFB5CyMNICDD4FvDD9tD5TmBa20J7Jjo7L3Jik/YCYQ082S6l78MrFGG oDTNxedC6RWyUz6aes4EKLOpb+7SUejNctMlZl+VjVvZL2SH36DIbinU4CxH1vHpD7 fXK9/ebRXCg+H/bSIsjVi42K7Ufv4tUfSkvMSWmeH+RWoA3m5ORM3beYOg4YYs/EZP Fe/SQsIkYcRBw== Date: Sat, 30 Aug 2025 11:58:59 -0500 From: Nico Williams To: Sagar Tiwari Cc: pgsql-general@postgresql.org Subject: Re: Saw some strange behavior when using `INSERT ON CONFLICT` inside a transaction. Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Aug 30, 2025 at 01:13:35PM +0530, Sagar Tiwari wrote: > Repro steps: > * I created the table: > ``` > create table t (col TEXT primary key); > ``` > > * Open two database consoles and use the following queries in them: > > ``` > 1 begin; > 2 select txid_current(); > 3 insert into t (col) values ('test') on conflict (col) do nothing; > 4 commit; > ``` > > I ran 1 and 2 in both. It worked for both. > And then I ran query 3 in the first console. It worked. > After that I ran query 3 in the second console. It got stuck! > When I commit the tx in first console, the stuck query in second console > finishes > The transaction isolation level is 'read committed'. The transaction that loses the race to do the insert (step 3) has to block somewhere waiting for the winning transaction to commit or rollback. The losing transaction could have continued speculatively and block in the commit (step 4) instead of in the insert, but it still had to block. Does it matter that it blocks in the insert instead of the commit?