From fc083fa6320605c54ae0d7b11ce5102c13977491 Mon Sep 17 00:00:00 2001
From: Shi Yu <shiy.fnst@fujitsu.com>
Date: Mon, 24 Apr 2023 17:25:56 +0800
Subject: [PATCH v2 1/2] dump rel state in wait_for_subscription_sync

---
 src/test/perl/PostgreSQL/Test/Cluster.pm | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 6f7f4e5de4..89cfc0f8a0 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -2774,8 +2774,25 @@ sub wait_for_subscription_sync
 	print "Waiting for all subscriptions in \"$name\" to synchronize data\n";
 	my $query =
 	    qq[SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');];
-	$self->poll_query_until($dbname, $query)
-	  or croak "timed out waiting for subscriber to synchronize data";
+	if (!$self->poll_query_until($dbname, $query))
+	{
+		my $result = $self->safe_psql(
+			$dbname, qq(
+			SELECT
+				PS.subname,
+				N.nspname,
+				C.relname,
+				PSR.srrelid,
+				PSR.srsubstate
+			FROM pg_subscription_rel AS PSR
+				JOIN pg_subscription PS ON (PS.oid = PSR.srsubid)
+				JOIN pg_class C ON (C.oid = PSR.srrelid)
+				JOIN pg_namespace N ON (N.oid = C.relnamespace);
+		));
+		print "### Subscription rel state\n";
+		print "$result\n";
+		croak "timed out waiting for subscriber to synchronize data";
+	}
 
 	# Then, wait for the replication to catchup if required.
 	if (defined($publisher))
-- 
2.30.0.windows.2

