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 1wA6KL-0023y5-1n for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 13:18:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wA6KJ-00Ha17-0n for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 13:18:43 +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 1wA6KI-00Ha0x-2z for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 13:18:43 +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 1wA6KG-000000016bM-2P0t for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 13:18:43 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 2E3A8EC041B; Tue, 7 Apr 2026 09:18:39 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 07 Apr 2026 09:18:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.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 :references:reply-to:subject:subject:to:to; s=fm2; t=1775567919; x=1775654319; bh=RImI4TN8pe/U9x7+gSeWjxG680Lf36GpSyEWRP6ceLA=; b= XV6CRnejy82vlKhmTckMYemqgD6FKDNAP4V3E9gE0hN9GN6x55lAAGKD2WZ007bI p7SNfg2IAkNcOVip7bHbJ1Dbt6/7nee9vNYJjpBUkZ5cdKPFQ3mZr9fh50zrzBvE stTcOOGO2AWD1903KxDexrY0Zftk4PTTPYROHTcm5mMMNsinTE2tIx6fWYpqDjwp oXPxyqg7qnV2DHOOr5yuIKuRr0DFVV1fw7By+S2d+AcBrGPvHfDFuQsZLtq2bQ+A Q79DRTNFh0MqeUfAzFJMAfx7NcQPIabDtiS5TOPq9AQgaRxoGKEuTnAgTb6ILGEO TzEM48YskPqu9mF9xN7Szw== 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=1775567919; x= 1775654319; bh=RImI4TN8pe/U9x7+gSeWjxG680Lf36GpSyEWRP6ceLA=; b=i CxZ+flmbS3Q3Y9FO8737agtXLinhmNIi3tiJhX3yhIj01kxs7F6yDsIbqnmEyQEJ ZY2x3noNlUw8s/vsb827xjn49OgQiXJctFSox6ysZrrgvJ8YXRoJWfW453B50/6A Lni1BfL/40cMPnRzByqcVfE1OHCXud+k6meNoEV3+XIvZ1sV3qogcUzyZO4SRMDd HY6FH6L1frXgCQmkLT4Vcu15ZVDTxBqVHgCJX6ar4ccegSKXAy2pIKm8GQyIqglS rb2OO+sORGq4yb/g+D5o0CItY6DPMPVo1HwZlOXr7Gy5RpuNSxDOXkTwH471uv92 QmDB83Kx6l1SXT0dv7nCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddvtdejgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtugfgjgesmheksfertddtjeenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepjedujeeffffhhffgvdetfeetkeevfeelgfeljeejjeethfetheeuhfevtdff veeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopedufedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorh hgpdhrtghpthhtoheprggvkhhorhhothhkohhvsehgmhgrihhlrdgtohhmpdhrtghpthht ohepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilhdrtghomhdprhgtphhtth hopehlihdrvghvrghnrdgthhgrohesghhmrghilhdrtghomhdprhgtphhtthhopehthhho mhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthhopeiguhhnvghnghiihh houhesghhmrghilhdrtghomhdprhgtphhtthhopehhlhhinhhnrghkrgesihhkihdrfhhi pdhrtghpthhtoheprghlvhhhvghrrhgvsehkuhhrihhlvghmuhdruggvpdhrtghpthhtoh epphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Apr 2026 09:18:38 -0400 (EDT) Date: Tue, 7 Apr 2026 09:18:37 -0400 From: Andres Freund To: Xuneng Zhou Cc: Alexander Korotkov , Tom Lane , Heikki Linnakangas , Peter Eisentraut , Thomas Munro , =?utf-8?Q?=C3=81lvaro?= Herrera , Chao Li , pgsql-hackers , Michael Paquier , jian he , Tomas Vondra , Yura Sokolov Subject: Re: Implement waiting for wal lsn replay: reloaded Message-ID: References: <1957514.1775526774@sss.pgh.pa.us> <1959506.1775527693@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ags3ltqh73mz7p2n" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ags3ltqh73mz7p2n Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi, On 2026-04-07 21:05:40 +0800, Xuneng Zhou wrote: > I’ve posted two patches. The first fixes the duplication issue > reported by Andres and is fairly straightforward. The second turned > out to be more complex than expected, and I’m still working through > possible solutions. Feedback or alternative approaches would be very > helpful. > I also spent some time drafting a patch to address the memory ordering > issue and will post it later. I propose quickly applying a minimal patch like the attached, to get the test performance back to normal. Will do so unless somebody protests within in one CI cycle and one coffee. Greetings, Andres Freund --ags3ltqh73mz7p2n Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-Minimal-fix-for-WAIT-FOR-.-MODE-standby_flush.patch" From 0a9c10fe36c6b2d08d1f4fbd0825b76bdd389c10 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Tue, 7 Apr 2026 09:11:07 -0400 Subject: [PATCH v1] Minimal fix for WAIT FOR ... MODE 'standby_flush' The investigation into the negative test performance impact of 7e8aeb9e483 lead to discovering that there are a few issues with WAIT FOR. This commit is just a minimal fix to prevent hangs in standby_flush mode, due to WAIT FOR ... 'standby_flush' seeing a 0 LSN if a newly started walreceiver does not receive any writes, because the stanby is already caught up. There are several other issues and this is isn't necessarily the best fix. But this way we get the hangs out of the way. Reported-by: Tom Lane Discussion: https://postgr.es/m/zqbppucpmkeqecfy4s5kscnru4tbk6khp3ozqz6ad2zijz354k@w4bdf4z3wqoz --- src/backend/replication/walreceiver.c | 2 -- src/backend/replication/walreceiverfuncs.c | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index a437273cf9a..09fde92bfd7 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -242,8 +242,6 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len) SpinLockRelease(&walrcv->mutex); - pg_atomic_write_u64(&WalRcv->writtenUpto, 0); - /* Arrange to clean up at walreceiver exit */ on_shmem_exit(WalRcvDie, PointerGetDatum(&startpointTLI)); diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 4e03e721872..bd5d47be964 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -321,6 +321,7 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, walrcv->flushedUpto = recptr; walrcv->receivedTLI = tli; walrcv->latestChunkStart = recptr; + pg_atomic_write_u64(&walrcv->writtenUpto, recptr); } walrcv->receiveStart = recptr; walrcv->receiveStartTLI = tli; -- 2.53.0.1.gb2826b52eb --ags3ltqh73mz7p2n--