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 1vqzKi-004ZOz-22 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 20:00:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqzKh-00G1c3-1b for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 20:00:07 +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 1vqzKh-00G1bv-0V for pgsql-hackers@lists.postgresql.org; Fri, 13 Feb 2026 20:00:07 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vqzKe-00000000Xdq-2r9H for pgsql-hackers@postgresql.org; Fri, 13 Feb 2026 20:00:06 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-436234ef0f0so853232f8f.1 for ; Fri, 13 Feb 2026 12:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771012803; x=1771617603; darn=postgresql.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=oTHUBn6nKfk/PfuQN3B86RUfkByiGz7gihOEeRosQuk=; b=Jng5KvG0FRMsMRpAoGbas/Gt/b3rdjGZbuNrPwGQQ/EvgEQX6Qy8Edgu1ujLzz0bg8 hnUXJSMCC0x1yh78x7UG6Id6jNb00vJxJZmN3b7M3IyZqtIGt6s3AaTwu73GTUOCP595 +Kt5YmGLs65rrhVpzViiGQI6ZA7rlufV6nHfhALGlpy/fHK42nx+7s9DRtcBoEbAMlll GKwYyBsFP76S5jXCXCyRYRR8LLZjXRZjXuodvd3SSz9UPtttjnynWnc3V+IW6Q/b3Ql9 v4EvtsdZ3CVjwg29b/xELH9UgimmC8JE31313NwNF/D3yaPrU6cxfBQo6vlf4IKy4Ip0 s9Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771012803; x=1771617603; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oTHUBn6nKfk/PfuQN3B86RUfkByiGz7gihOEeRosQuk=; b=qThWuNgfqeKXaq6PfwKjzvSXThZxGW5MEunflpOAjZbdnfET2Ob5U2j6jMumpLEXlU ZZaSbDE0IYcSUJX0dXUjrK26v00qtAyJFYz8tzow3OdG/rmzzkSuQEmVHqGMj1LAkZHh gPQi6G51PT1jnfSHYNmS+dDrJLmEiGCD1iBf3xHeIFGaBpaIeLeamiVFIzw3v0U7g/aa /O1WbHJDitH+abzrfdA2Xq7KUnY2GNTIGA3PHK5EO6xRUvJ5SKxFGij6jC144mlxZAU1 aXPILQAuXL1f8Sp/DGKvCH84Mq/G7AEM+NSOo+owdG/yBA74HkJHZBEDkmMEwO6dQonS BvNw== X-Gm-Message-State: AOJu0YwHaVi22SiIYhNXVTD8qZcY42GDcobWcBgAMwF9NxxREpHf6EmZ bSfvDNyKFlAK/ro7QvnXntDhLj+VxM2Gp24p1kAboVkL4wAUFbaanvag X-Gm-Gg: AZuq6aI2wsE4HfWT65Vhbf/eeuyBQ1WGKPxd6NhLabzqKW1zZALtvuIvRkz6O7vDX6f EfC3+gTgzjXIyZ//WYeXKbQ+LBUrLte5EjlShkPFUK/Ndoi+OmsbwHvFAlhSmeQoRNp9ayk5mqg ZbGfsV3UZ/7pNbGw9eiwBxg0YZ+j4ez/YDXiFOxWlXdxNFy0D8Ga1aB3FHAoEDynSlXoZf0rtj6 0B4SQuKVZFlSi0aMP2NRErkrZc8wVZ3vIeEPSi9C3ToG2wGLVgjJbF4csteKbV59CF7dnRpzHuC zG45Kut9kS9j95CYLif66u9M/9eSUXw/+XcohtByn5bJkEFMRfSUyjyQ+gzGK3QdV3zDl+Br7xG ecDgYTC7kBwRJSWfDm5DbZ+YXmbXFrfVvEczsH5Q0dUpk8SVR/yL/NPU+/Dcz4whUJhuc4ro6Xx Rs+hIdGMjg/XK3tKQv6fNLPSqW X-Received: by 2002:a05:6000:2083:b0:437:712a:fac9 with SMTP id ffacd0b85a97d-437978cf216mr6008502f8f.23.1771012802732; Fri, 13 Feb 2026 12:00:02 -0800 (PST) Received: from [192.168.0.50] ([89.149.93.164]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43796a5ac7csm7129816f8f.7.2026.02.13.12.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Feb 2026 12:00:02 -0800 (PST) Content-Type: multipart/alternative; boundary="------------iqwljct00uroWIpBw4jEEx2r" Message-ID: Date: Fri, 13 Feb 2026 22:00:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG: Former primary node might stuck when started as a standby To: "Hayato Kuroda (Fujitsu)" Cc: pgsql-hackers , Aleksander Alekseev References: <74ea5e7e-9aa0-4d7a-85df-71a9d200a8d8@gmail.com> <180bf13e-235d-46a9-9788-7d6cee40bcdc@gmail.com> Content-Language: en-US From: Alexander Lakhin In-Reply-To: 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. --------------iqwljct00uroWIpBw4jEEx2r Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Dear Kuroda-san, 13.02.2026 04:03, Hayato Kuroda (Fujitsu) wrote: > Dear Alexander, > > I checked your test and reproduced the issue with it. > Was it possible that INSERT happened in-between wait_for_replay_catchup and > teardown_node? In this case we may not ensure WAL records generated in the time > window were reached, right? > Similar stuff won7t happen in 009_twophase.pl because it does not have the bg activities. From my old records, 009_twophase.pl failed exactly due to background ( namely, bgwriter's) activity. I modified bgwriter.c to reproduce the failure easier: --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -67,7 +67,7 @@ int            BgWriterDelay = 200;   * Interval in which standby snapshots are logged into the WAL stream, in   * milliseconds.   */ -#define LOG_SNAPSHOT_INTERVAL_MS 15000 +#define LOG_SNAPSHOT_INTERVAL_MS 1  /*   * LSN and timestamp at which we last issued a LogStandbySnapshot(), to avoid @@ -306,7 +306,7 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)           */          rc = WaitLatch(MyLatch,                         WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, -                       BgWriterDelay /* ms */ , WAIT_EVENT_BGWRITER_MAIN); +                       1 /* ms */ , WAIT_EVENT_BGWRITER_MAIN);          /*           * If no latch event and BgBufferSync says nothing's happening, extend @@ -339,6 +339,5 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)              StrategyNotifyBgWriter(-1);          } -        prev_hibernate = can_hibernate;      }  } multiplied the test to increase probability of the failure: for i in {1..20}; do cp -r src/test/recovery/ src/test/recovery_$i/; sed "s|src/test/recovery|src/test/recovery_$i|" -i src/test/recovery_$i/Makefile; done and executed it in a loop: for i in {1..100}; do echo "ITERATION $i"; parallel --halt now,fail=1 -j20 --linebuffer --tag PROVE_TESTS="t/009*" NO_TEMP_INSTALL=1 timeout 60 make check -s -C src/test/recovery_{} ::: `seq 20` || break; done It failed for me on iterations 27, 4, 22 as below: ITERATION 22 ... 18      t/009_twophase.pl .. ok 18      All tests successful. 18      Files=1, Tests=30, 12 wallclock secs ( 0.01 usr  0.01 sys + 0.26 cusr  0.58 csys =  0.86 CPU) 18      Result: PASS 5       make: *** wait: No child processes.  Stop. 5       make: *** Waiting for unfinished jobs.... 5       make: *** wait: No child processes.  Stop. parallel: This job failed: PROVE_TESTS=t/009* NO_TEMP_INSTALL=1 timeout 60 make check -s -C src/test/recovery_5 src/test/recovery_5/tmp_check/log/009_twophase_london.log contains: 2026-02-13 21:03:28.248 EET [3987222] LOG:  new timeline 2 forked off current database system timeline 1 before current recovery point 0/3029190 ... (Without "timeout 60", the test just hangs — we can see the same in [1], the test was killed with SIGTERM after 15000 seconds...) [1] https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=skink&dt=2026-02-04%2013%3A36%3A40&stg=recovery-check Best regards, Alexander --------------iqwljct00uroWIpBw4jEEx2r Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Dear Kuroda-san,

13.02.2026 04:03, Hayato Kuroda (Fujitsu) wrote:
Dear Alexander,

I checked your test and reproduced the issue with it.
Was it possible that INSERT happened in-between wait_for_replay_catchup and
teardown_node? In this case we may not ensure WAL records generated in the time
window were reached, right?
Similar stuff won7t happen in 009_twophase.pl because it does not have the bg activities.

From my old records, 009_twophase.pl failed exactly due to background (
namely, bgwriter's) activity.

I modified bgwriter.c to reproduce the failure easier:
--- a/src/backend/postmaster/bgwriter.c
+++ b/src/backend/postmaster/bgwriter.c
@@ -67,7 +67,7 @@ int            BgWriterDelay = 200;
  * Interval in which standby snapshots are logged into the WAL stream, in
  * milliseconds.
  */
-#define LOG_SNAPSHOT_INTERVAL_MS 15000
+#define LOG_SNAPSHOT_INTERVAL_MS 1
 
 /*
  * LSN and timestamp at which we last issued a LogStandbySnapshot(), to avoid
@@ -306,7 +306,7 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)
          */
         rc = WaitLatch(MyLatch,
                        WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
-                       BgWriterDelay /* ms */ , WAIT_EVENT_BGWRITER_MAIN);
+                       1 /* ms */ , WAIT_EVENT_BGWRITER_MAIN);
 
         /*
          * If no latch event and BgBufferSync says nothing's happening, extend
@@ -339,6 +339,5 @@ BackgroundWriterMain(const void *startup_data, size_t startup_data_len)
             StrategyNotifyBgWriter(-1);
         }
 
-        prev_hibernate = can_hibernate;
     }
 }

multiplied the test to increase probability of the failure:
for i in {1..20}; do cp -r src/test/recovery/ src/test/recovery_$i/; sed "s|src/test/recovery|src/test/recovery_$i|" -i src/test/recovery_$i/Makefile; done

and executed it in a loop:
for i in {1..100}; do echo "ITERATION $i"; parallel --halt now,fail=1 -j20 --linebuffer --tag PROVE_TESTS="t/009*" NO_TEMP_INSTALL=1 timeout 60 make check -s -C src/test/recovery_{} ::: `seq 20` || break; done

It failed for me on iterations 27, 4, 22 as below:
ITERATION 22
...
18      t/009_twophase.pl .. ok
18      All tests successful.
18      Files=1, Tests=30, 12 wallclock secs ( 0.01 usr  0.01 sys +  0.26 cusr  0.58 csys =  0.86 CPU)
18      Result: PASS
5       make: *** wait: No child processes.  Stop.
5       make: *** Waiting for unfinished jobs....
5       make: *** wait: No child processes.  Stop.
parallel: This job failed:
PROVE_TESTS=t/009* NO_TEMP_INSTALL=1 timeout 60 make check -s -C src/test/recovery_5

src/test/recovery_5/tmp_check/log/009_twophase_london.log contains:
2026-02-13 21:03:28.248 EET [3987222] LOG:  new timeline 2 forked off current database system timeline 1 before current recovery point 0/3029190
...

(Without "timeout 60", the test just hangs — we can see the same in [1],
the test was killed with SIGTERM after 15000 seconds...)

[1] https://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=skink&dt=2026-02-04%2013%3A36%3A40&stg=recovery-check

Best regards,
Alexander
--------------iqwljct00uroWIpBw4jEEx2r--