From e141bbe2598117aabd76730cca109bd3470b5018 Mon Sep 17 00:00:00 2001
From: Hou Zhijie <houzj.fnst@cn.fujitsu.com>
Date: Thu, 11 Jul 2024 18:59:13 +0800
Subject: [PATCH] fix unstable test in 040_pg_createsubscriber

In this test, the INSERT before slot synchronization results in the
generation of a new xid. The new xid could be replicated to the standby
before the xmin of physical slot on the primary catches up, as the xmin is
updated independently through hot standby feedback. To address this issue
and ensure slot synchronization reliability, the INSERT operation has been
moved to occur after the logical slot has been successfully synchronized.

---
 src/bin/pg_basebackup/t/040_pg_createsubscriber.pl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
index 74b90d9a91..cdac75768b 100644
--- a/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
+++ b/src/bin/pg_basebackup/t/040_pg_createsubscriber.pl
@@ -227,10 +227,6 @@ command_fails(
 	],
 	'primary server is in recovery');
 
-# Insert another row on node P and wait node S to catch up
-$node_p->safe_psql($db1, "INSERT INTO tbl1 VALUES('second row')");
-$node_p->wait_for_replay_catchup($node_s);
-
 # Check some unmet conditions on node P
 $node_p->append_conf(
 	'postgresql.conf', q{
@@ -306,6 +302,10 @@ my $result = $node_s->safe_psql('postgres',
 );
 is($result, 'failover_slot', 'failover slot is synced');
 
+# Insert another row on node P and wait node S to catch up
+$node_p->safe_psql($db1, "INSERT INTO tbl1 VALUES('second row')");
+$node_p->wait_for_replay_catchup($node_s);
+
 # Create subscription to test its removal
 my $dummy_sub = 'regress_sub_dummy';
 $node_p->safe_psql($db1,
-- 
2.30.0.windows.2

