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 1wZeWx-001CA6-0D for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jun 2026 00:53:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZeWu-003gPg-2y for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jun 2026 00:53:20 +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 1wZeWu-003gPY-1A for pgsql-hackers@lists.postgresql.org; Wed, 17 Jun 2026 00:53:20 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wZeWr-00000000jCP-1lp5 for pgsql-hackers@lists.postgresql.org; Wed, 17 Jun 2026 00:53:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1781657593; bh=qMXPOOjhjdDDuXfD3P+c86/O+l0GXKiMXUBQKdz2810=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=2L4SlbLLvuVHTOuPXHJjHbH5bSBw8dyeR5+fNurBb765UQmKqik9SlgBiiN9Qo6on mZMeaYlslIa/IQsumb0EO2OFz/asZTJtQe+X6cc5XhTwiMp9cphP4KdRJ4dm3k4oIx hSrRSX3oZu5PPWz0YC+Q/8gHJV9wfbbZ/BKQDoDDwAvATCw/FtnfG9/jNR4HNXTJY2 SxZDs3STMdqrVasPNFwrLyeL/ki5kMmXK9o3Aol9zRtbH90IPTWPleDUicdyhy2e4I NqzRJG8OhI8qr3FrCNDS0Isr+Kcc/itiPUhZMBG2qb8wqCGBZxL6P1TXvJNGh1tV6p icMR6rZS5oQkw== Received: from [172.30.48.14] (debian11-template.l.postgrespro.ru [192.168.2.254]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: s.tatarintsev@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id B2FB05FF54; Wed, 17 Jun 2026 03:53:12 +0300 (MSK) Content-Type: multipart/mixed; boundary="------------ZoWItoPiIj0nPe0KRx0MNJOy" Message-ID: Date: Wed, 17 Jun 2026 07:53:12 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: 004_timeline_switch TAP test may fail To: Ewan Young Cc: pgsql-hackers References: Content-Language: en-US From: Sergey Tatarintsev In-Reply-To: X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 3.0.0.9059, bases: 2026/06/16 22:51:00 #28243679 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------ZoWItoPiIj0nPe0KRx0MNJOy Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi! Thanks for review! v2 patch attached comment changed, count(1) replaced with count(*). > Hi Sergey, > > Thanks for the report and patch. I think the analysis is right, and the > fix is in the right place. > > The gap traces back to commit 7185eddf, which deliberately dropped the > wait_for_catchup() and switched the primary from teardown_node() to a > clean stop(), on the grounds that a clean stop flushes all WAL to both > standbys before exiting. That's true, but only for standbys whose > walsender is *connected* at shutdown time -- and ->start() only waits > for the postmaster to accept connections, not for the standby's > walreceiver to have connected back to the primary. So if a standby > hasn't connected yet when the primary stops, the clean-shutdown flush > skips it, and we're back to the exact "standbys received different > amounts of WAL -> timeline fork on reconnect" failure that 7185eddf was > meant to fix. > > Polling pg_stat_replication until both walsenders are present closes > that hole: it re-establishes the precondition the clean-stop design > silently assumed. And connection is enough here -- the walsender > shutdown path sends all WAL up to the shutdown checkpoint regardless of > catchup state -- so there's no need to additionally check > state = 'streaming'. > > One small thing: the rest of this file uses count(*), so I'd write count(*) = 2 > rather than count(1) = 2 just for local consistency. And the comment reads a > little better as something like "Wait until both standbys have > connected to the primary", > since by this point they've already started -- what we're waiting for is the > connection. > > Regards, > Ewan > > On Tue, Jun 16, 2026 at 4:01 PM Sergey Tatarintsev > wrote: >> Hi hackers! >> >> I found that after commit 7185eddf0522b3146ed1ff6e063e8e129e77c706 we >> got little omission >> in TAP test 004_timeline_switch: >> ... >> my $node_standby_1 = PostgreSQL::Test::Cluster->new('standby_1'); >> ... >> $node_primary->stop; >> >> There is no guarantee that standby_1 and standby_2 was successfully >> connected to primary and start >> streaming before primary stopped. >> >> I think we must ensure that primary knows about standby_1 and standby_2 >> >> -- >> With best regards, >> Sergey Tatarintsev, >> PostgresPro -- With best regards, Sergey Tatarintsev, PostgresPro --------------ZoWItoPiIj0nPe0KRx0MNJOy Content-Type: text/x-patch; charset=UTF-8; name="v2-0001-Fix-004_timeline_switch-TAP-test-wait-for-standbys-s.patch" Content-Disposition: attachment; filename*0="v2-0001-Fix-004_timeline_switch-TAP-test-wait-for-standbys-s"; filename*1=".patch" Content-Transfer-Encoding: base64 RnJvbSBkZDQ0OTM5NjA2MGM3MWMzNGJjYjAzZTVjMWM1ZGUwY2IwODY4ZGEwIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBTZXJnZXkgVGF0YXJpbnRzZXYgPHMudGF0YXJpbnRz ZXZAcG9zdGdyZXNwcm8ucnU+CkRhdGU6IFR1ZS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