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 1vizso-003Mym-30 for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jan 2026 18:58:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vizsl-00EC0a-2S for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Jan 2026 18:58:16 +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 1vizsl-00EC0P-0i for pgsql-hackers@lists.postgresql.org; Thu, 22 Jan 2026 18:58:15 +0000 Received: from fout-a1-smtp.messagingengine.com ([103.168.172.144]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vizsi-001xFy-2k for pgsql-hackers@lists.postgresql.org; Thu, 22 Jan 2026 18:58:15 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id E44F4EC0128; Thu, 22 Jan 2026 13:58:10 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 22 Jan 2026 13:58:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm1; t=1769108290; x= 1769194690; bh=ChmnOY9mrTLOqTV4rQVlyi+9d5GllSNR+B24543xWMc=; b=S VBGTnWMosXS51epfudR6jNalAEAXIo7VsAiMD0WL0h9OlHGYzOe0yGc6iJGxr9EN 71xFZiTxcolLP47nGQ7foB0oWbFvzkb5uLU9RubsgOtwE/CHm3Lqi4s8t7jY8trG vm8PyJ43tDyzCapUf5HmSWD8Drtn1KTkvNpG3qt4VugGEYaKW3V6QOIVzXy+adav YhuwSBBTBNivqztXeMlM2XBjAGjbuz+FtbKIdMkoCdsCdMIDVk07HE+w9IndK3TM tyMjKzHG0K0ZMZvwVySbvpWMbqdILmPD7kKlTGAuzkWfoEFUpFriTa6cg21AKsX5 5lpwpDSdFLsHFE9vXyrRg== 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 :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1769108290; x=1769194690; bh=C hmnOY9mrTLOqTV4rQVlyi+9d5GllSNR+B24543xWMc=; b=iT/i/eFuzsxzu9opD SYq+U4obTRF1ybE2hMIvDX4i40CdBCeBVuNKE5OTnXS9No2j/aZw5My8oDOe6ujp 3ejRoN3cNSteKtE2/kz+RGVKLdL5A19odBDNIJ6ITIJUyKp2p9Axjcsp6+fbqaIh vBOOBW9kID61o5yrcjl8wojGzjosfl9NglUCietmbUthOmWt5MGrwpiLZPI//tIx TwDhCYkNLJ56LaZqVHbvsgJtTGLJA7ADjq0jZ7O/94DhXXG1e+49e2nnojs3tHAt 9xpXbEbnnTNTzYAKrZUyhx7NX25k0PTboJSz8sWhlxjWu0xk1pdaVfG6iMBRqTP2 g0+ag== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddugeeileegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeetuedvheffkeevgfeuheevteevkefggedttdeufeeuheduuddthfef fffhjeefffenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv sehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopeegpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegrnhgurhgvshesrghnrghrrgiivghlrdguvgdprhgtphhtthho pegrhhestgihsggvrhhtvggtrdgrthdprhgtphhtthhopehmihhhrghilhhnihhkrghlrg ihvghusehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshes lhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Jan 2026 13:58:10 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1769108285; bh=djXz+a9ScdC5hIXDaQ42tUZiP2erONRlfu+iR18KR/Q=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=vhqqMnECb4zNYHRs2TxW+GHHzgulIts4sZxRmAi/S6U0LqZptQtPme3yPbCH+Pzk8 QynUI34aov8cpvAjVJqEuNTwcXl88Jyx/7xOXOXItt4FDsgygt6q58xPqJeSzsFgzs TC3JCQPTNvjkq2MEBLOXFL7erEB2yk7WMRLQkpitzQIvCqXHNXotaieu5i1qANbO3S yOAoOqO4C7G/q/C3RMSY0Bj1y1hiZlV7+pbTl1+BOy5ZNJGWsnhaaZBpLDrEjn3sqn vPLFuyT81dNWFagtvG+7spd7m+WG4AB/wXpfMNgnlqryxUaNyuO2gLDRmTRZpdTq88 7bSoNuOoSEKyw== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id A424564; Thu, 22 Jan 2026 19:58:05 +0100 (CET) Date: Thu, 22 Jan 2026 19:58:05 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Antonin Houska Cc: Mihail Nikalayeu , Andres Freund , pgsql-hackers@lists.postgresql.org Subject: Re: Race conditions in logical decoding Message-ID: <202601221804.nbrvjquik7qp@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <124728.1769077978@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-Jan-22, Antonin Houska wrote: > Mihail Nikalayeu wrote: > > > Hello, Andres. > > > > On Tue, Jan 20, 2026 at 6:50 PM Andres Freund wrote: > > > I don't think that's enough - during non-timetravel visibility semantics, you > > > can only look at the clog if the transaction isn't marked as in-progress in > > > the procarray. ISTM that we need to do that here too? > > > > Do you mean replace > > > if (unlikely(!TransactionIdDidCommit(builder->committed.xip[i]))) > > to > > > if (unlikely(TransactionIdIsInProgress(builder->committed.xip[i]) || !TransactionIdDidCommit(builder->committed.xip[i]))) > > This way the synchronous replication gets stuck, as it did when I tried to use > XactLockTableWait(): subscriber cannot confirm replication of certain LSN > because publisher is not able to even finalize the commit (due to the waiting > for the subscriber's confirmation), and therefore publisher it's not able to > decode the data and send it to the subscriber. The layering here is wild, but if I understand it correctly, these XIDs are all added to an array by SnapBuildAddCommittedTxn(), which in turn is only called by SnapBuildCommitTxn(), which is only called by DecodeCommit(), which is only called by xact_decode() when it sees a XLOG_XACT_COMMIT or XLOG_XACT_COMMIT_PREPARED record by reading WAL. Crucially, RecordTransactionCommit() writes the WAL first, then marks everything as committed in CLOG, and finally does the waiting for the synchronous replica to ACK the commit if necessary. However, the transaction is only removed from procarray after RecordTransactionCommit has returned. This means that DecodeCommit() could add a transaction to the SnapBuilder (that needs to be waited for) while that transaction is still shown as running in ProcArray. This sounds problematic in itself, so I'm wondering whether we should do anything (namely, wait) on DecodeCommit() instead of hacking SnapBuildBuildSnapshot() to patch it up by waiting after the fact. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/