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 1vlDPB-008wOG-2a for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jan 2026 21:48:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vlDPA-0042J4-1H for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jan 2026 21:48:52 +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 1vlDP9-0042Il-2H for pgsql-hackers@lists.postgresql.org; Wed, 28 Jan 2026 21:48:52 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vlDP6-002oFw-1n for pgsql-hackers@lists.postgresql.org; Wed, 28 Jan 2026 21:48:50 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 3407E1D000BB; Wed, 28 Jan 2026 16:48:48 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Wed, 28 Jan 2026 16:48:48 -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=1769636927; x= 1769723327; bh=VNlHFJd1vbAj1yN4QH1W3AQ64vGMVIlG/QQaWY2fCjg=; b=I r9HOlv+BCFqzB+GvIUuvvqb4pcMPeBn25RwcXOtpNLmXkG3+A9QAUfEo9Ad6RBf6 3gtgU5BBqkzn+pRmx+mJ/aVm8bylZnJfZvBuM3zBTk5Y8GgEgBs/FOSKS3qF/mJF 9w/toLSKHC7fZT5MLdKbAonzLuZw+MCqLufpourrKKYO9LlCm9mOZGRl4BFdcOcu BP92zU+ddx77BePzya0CFyr3EDbRdRdEx5a0DKx1t/u6Dk26cyd2ntgOasYKE1Bv DK0z2c6Q/4KrtXxkqRmzkLN0PMa73LZQGkdOOrOjn5rQgYiLM4NuF53aboO6+iMB Rnxwf8PfH0mfRBA4KLgEg== 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=fm3; t=1769636927; x=1769723327; bh=V NlHFJd1vbAj1yN4QH1W3AQ64vGMVIlG/QQaWY2fCjg=; b=lbpvu1/IVQigx+xtt lr+2ih192k3w+A9qCGxBZO0MfIcS61m3PxretVu9dnOXeYBLHUw3lVppnjE7OJsF qg0FfNeKwRP6Pbo5jw8doT+LnG9F8d/mn4UKeRJVuYOFKacL4BURmAZPiT7v/1zy 0WwH+00OOFPRNI6Cgdb7GXx84uXNYSB5yb3cQRb2y2SY9V90EAZV3xIKPWTZ9/uz k1F91sks5jaDTqdZ1Q2Kw7C1ZirJpB/bk74drbfvCQu5/FobLSrt07eZViJH/nxI RZplsrmr6Cus5cCEO1+s/1TDve7jRXl76hWB0Fm7ODAIWjkufsJsVxzoLVNlmW8u 7UzwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduieeggeefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheplmhlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvqeenucggtf frrghtthgvrhhnpeetuedvheffkeevgfeuheevteevkefggedttdeufeeuheduuddthfef fffhjeefffenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgv sehkuhhrihhlvghmuhdruggvpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegrhhestgihsggvrhhtvggtrdgrthdprhgtphhtthhopehpghhs qhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Jan 2026 16:48:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1769636925; bh=tWL9I6LnyqvsOPBLtCDetIs09KRe6vvC14UAi/+/4X4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=T4nC+DrgLesW7nDNHmpRJOuDHq5eRE4WCpU++9edLK5TesefIalMYk2NMpNxu+DfR WosgYS1mkLLkCS3HPsmTrt5rQB5UvZ8GYJgIuce6/OHjjIIwk8m9J1X04glfpf3hzC l1T9dzUMKNA5cojCEwHIIQJeRFFHY2EDftiAwd0YRkkkNhjlYRyPJPgbFSdRj4yUcS 8i8kdfDgRyb1WWB4LeJT+mk9javAFuSNPNCbjGEQNIAhi7W/254O+/Yv5IJ7SWM766 SyeOhD+LE5pZOsj4dqcwanD3gTWsczv3gLW8FZcOXgDMvUYvV+l6P1LYsbSgCgfMPw Y0zlMusI9vQzQ== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id D6FAE7A; Wed, 28 Jan 2026 22:48:45 +0100 (CET) Date: Wed, 28 Jan 2026 22:48:45 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Antonin Houska Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Race conditions in logical decoding Message-ID: <202601282119.cosfxnhvtqpo@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3805.1769150012@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2026-Jan-23, Antonin Houska wrote: > > This way you wait repeatedly for one transaction until it is marked > > committed; and once it does, you don't test it again. > > Sure, that's much beter. Thanks. Actually, I wonder if it would make sense to sleep just once after testing all the transactions for whether they are marked committed (not once per transaction); and after sleeping, we only test again those that were not marked committed in the previous iteration. I think you would end up doing less tests overall. Something like this /* * Although it's very unlikely, it's possible that a commit WAL record was * decoded but CLOG is not aware of the commit yet. Should the CLOG update * be delayed even more, visibility checks that use this snapshot could * work incorrectly. Therefore we check the CLOG status here. */ { TransactionId *stillrunning; int nstillrunning = builder->committed.xcnt; stillrunning = palloc(sizeof(TransactionId) * builder->committed.xcnt); nstillrunning = builder->committed.xcnt; memcpy(stillrunning, builder->committed.xip, sizeof(TransactionId) * nstillrunning); for (;;) { int next = 0; if (nstillrunning == 0) break; for (int i = 0; i < nstillrunning; i++) { if (!TransactionIdDidCommit(stillrunning[i])) stillrunning[next++] = stillrunning[i]; } if (next == 0) break; nstillrunning = next; (void) WaitLatch(MyLatch, WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, 10L, WAIT_EVENT_SNAPBUILD_CLOG); ResetLatch(MyLatch); CHECK_FOR_INTERRUPTS(); } pfree(stillrunning); } -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Use it up, wear it out, make it do, or do without"