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 1vqbv6-00EJU3-2t for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Feb 2026 19:00:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqbv5-00AXIF-0j for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Feb 2026 19:00:08 +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 1vqbv4-00AXI5-2g for pgsql-hackers@lists.postgresql.org; Thu, 12 Feb 2026 19:00:07 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vqbv3-00000000Mbg-1Z8S for pgsql-hackers@postgresql.org; Thu, 12 Feb 2026 19:00:07 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4807068eacbso1279735e9.2 for ; Thu, 12 Feb 2026 11:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770922803; x=1771527603; 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=/nUv4N6fZRs22bJV/3wxpppkZymr94Xrp/2NIhtCdmo=; b=XeWY1HSk51eEYjyshj0KXH4JHxVXK7/1KVki9tQCKQ7q8wkCSY/1ZMPf6Y1ef6r9/j Elt61XQuqkcRlGRxujRfZ0P9+OwFXRZASqf4OjLkgb3k6PKfzpRTzaO2x20f7DrZ8Aq2 haMsM7GCr7xK2dA7oLmWwDqIV6m4EeSJDUMcQ5baZgq2YAkD4WbZSDK4Qmm5SSm98YjF A9rVcUHJ+foD+BYy1oUydphMkOJcntADx+NetjOg6sqIXjavdOFD0zU2eC7FbVqcgKQK f3PHJ1D8NXFw69JOXBMBJQayrqUCuHfPrNXSie465xu6MD2k3LxilI7Uq1LasL3zYA76 PAmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770922803; x=1771527603; 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=/nUv4N6fZRs22bJV/3wxpppkZymr94Xrp/2NIhtCdmo=; b=tZZgId9WTVOBznojSmME6sT1deggKKsLoLfLxQTGqRsxp598AAMBQvccI5aWeE2bYc qKtToYdKJILGQqbD8wb6zjB9IjR3Me9T1/VshBnWlKBYw8Kpo2gN1h8a8614yUis4LXu DaqcSaukNgr8tbo2oHre97XbBmhd5ndP2bRDAqPA9pJ9f+Q3qJzWoGZPxQcfi1XrLw/O YOLuIvM+9eNh+dyu7YkQNCO4TQSKG7B+R0RVusEYus6pLvOPiCAA3rRqc+Rr5X5qQCSW HtUonhmbGDa2tff7E5tqRk20CGMWHxlYSo6v9xNUMbDKOCbYenZgtxxVlH8PhLwaVbGd KdOQ== X-Gm-Message-State: AOJu0Yy0J+NbqvIElNxkKE7lmydHmet54c9vBCTMI/Bo3xJXGXLx1ex/ s8Cg9clMY7JGJoI+k/tl+AEkdtF0GEKV+KmmCPIG+iiUz/fQlsYt3uYs X-Gm-Gg: AZuq6aJVWazPUM0wCHWGvR3XFqXlsuGQOInQaxfk3L/Rux/QOViUPh6c3ebS3XeVaY8 eF1NEPUCR2m9XIrDpcuIAvCCHymupFXp9zf0OzHfkCEPL+DqTrHIkZ/KViaik3Y+Rf7QkY1DPwX td2LwWbquWBrUWQDD2VKLyfxdIwWAUQHXAh0y4RndrWOEeHp0GBY1tgrOHR4tSv+iPT04ZVn8DG 2KAeB4UizMmCmWt+4TMOO5dgMRNO79R2EKKFf/G7Uygnf0IuSkfMYqiv4nKr7xueGMUfn7P8tCN Ae9JQR3/qs8XcxfhfvuZBTINGH+Tx4cIX9IPqTwb9rdIEY0g1jolGMT9CtRIH9pYMtprAGiK98T OL9sUU5NRxpuvSNGF3FvKLs7TcwM2r1NqCrVhn/j3pwMMc1dxZt2Ffuh4g+SR1ZUUslbl8+UDN+ 2iRl9sEb68LU88BU/P9FOJrDg7 X-Received: by 2002:a05:600c:1c12:b0:480:6ab1:ed0d with SMTP id 5b1f17b1804b1-48370e21259mr2877835e9.9.1770922802602; Thu, 12 Feb 2026 11:00:02 -0800 (PST) Received: from [192.168.0.50] ([89.149.93.164]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4834d5d77f9sm227899305e9.3.2026.02.12.11.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Feb 2026 11:00:01 -0800 (PST) Content-Type: multipart/mixed; boundary="------------qkZKJHNb7cv2tDSvEXdQyJeg" Message-ID: Date: Thu, 12 Feb 2026 21:00:00 +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. --------------qkZKJHNb7cv2tDSvEXdQyJeg Content-Type: multipart/alternative; boundary="------------wauAxdmhPNwswW5PTu2eyd1j" --------------wauAxdmhPNwswW5PTu2eyd1j Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Dear Kuroda-san, 09.02.2026 04:38, Hayato Kuroda (Fujitsu) wrote: > > Dear Alexander, Aleksander > > Is it enough that we can wait till all WALs are replayed before the promotion? > > Like attached. > > Thank you for paying attention to this! I tried to add $primary->wait_for_replay_catchup($standby); in my test (see attached), but that doesn't help -- it still fails as below: iteration 61 # +++ tap check in src/test/recovery +++ t/099_change_roles.pl .. 1/? make: *** [Makefile:28: check] Terminated src/test/recovery/tmp_check/log/099_change_roles_node1.log 2026-02-12 20:30:42.953 EET [2716149] LOG:  new timeline 4 forked off current database system timeline 3 before current recovery point 0/3025B48 Best regards, Alexander --------------wauAxdmhPNwswW5PTu2eyd1j Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Dear Kuroda-san,

09.02.2026 04:38, Hayato Kuroda (Fujitsu) wrote:

Dear Alexander, Aleksander

 

Is it enough that we can wait till all WALs are replayed before the promotion?

Like attached.



Thank you for paying attention to this!

I tried to add
$primary->wait_for_replay_catchup($standby);
in my test (see attached), but that doesn't help -- it still fails as below:
iteration 61
# +++ tap check in src/test/recovery +++
t/099_change_roles.pl .. 1/? make: *** [Makefile:28: check] Terminated

src/test/recovery/tmp_check/log/099_change_roles_node1.log
2026-02-12 20:30:42.953 EET [2716149] LOG:  new timeline 4 forked off current database system timeline 3 before current recovery point 0/3025B48

Best regards,
Alexander
--------------wauAxdmhPNwswW5PTu2eyd1j-- --------------qkZKJHNb7cv2tDSvEXdQyJeg Content-Type: application/x-perl; name="099_change_roles.pl" Content-Disposition: attachment; filename="099_change_roles.pl" Content-Transfer-Encoding: 7bit use strict; use warnings FATAL => 'all'; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; use IPC::Run; use threads; use threads::shared; sub bgactivity { my @args = @_; my ($n, $port, $db_name) = @args; $SIG{'KILL'} = sub { print("Thread killed.\n"); threads->exit(); }; my $try = 1; while (1) { my ($stdout, $stderr); my $cmd = [ 'psql', '-h', $ENV{'PGHOST'}, '-p', $port, '-d', $db_name, '-c', "INSERT INTO t VALUES (1000 * $n + $try, 'background activity');" ]; my $result = IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr); $try += 1; sleep(0.001); } } # Set up two replication nodes, which will switch roles. my $node1 = PostgreSQL::Test::Cluster->new("node1"); $node1->init(allows_streaming => 1); $node1->start; $node1->backup('initial_backup'); my $node2 = PostgreSQL::Test::Cluster->new('node2'); $node2->init_from_backup($node1, 'initial_backup', has_streaming => 1); $node2->start; $node1->psql('postgres', "ALTER SYSTEM SET synchronous_standby_names = 'node2'; SELECT pg_reload_conf()"); $node2->psql('postgres', "ALTER SYSTEM SET synchronous_standby_names = 'node1'; SELECT pg_reload_conf()"); $node1->psql('postgres', "CREATE TABLE t(id int, message text)"); my $numthreads = 2; my @threads; foreach my $ti (1 .. $numthreads) { push @threads, threads->create('bgactivity', $ti, $node1->port, 'postgres'); } for (my $i = 1; $i <= 20; $i++) { my ($primary, $standby) = ($node1, $node2); $primary->safe_psql('postgres', "INSERT INTO t VALUES ($i, 'inserted on node1');"); # change roles $primary->wait_for_replay_catchup($standby); $primary->teardown_node; $standby->promote; $primary->enable_streaming($standby); $primary->start; ($primary, $standby) = ($node2, $node1); $primary->safe_psql('postgres', "INSERT INTO t VALUES ($i, 'inserted on node2');"); # change roles back $primary->wait_for_replay_catchup($standby); $primary->teardown_node; $standby->promote; $primary->enable_streaming($standby); $primary->start; ok(1); } for my $thread (@threads) { $thread->kill('KILL')->detach; } done_testing(); --------------qkZKJHNb7cv2tDSvEXdQyJeg--