From 52108f9ea9a3ce394dc0486ba63b4dfbf8566764 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 30 Oct 2026 15:05:58 -0400
Subject: [PATCH v1] tests: Don't use the initdb template for older
 installations

Previously the initdb template was used even when creating a Cluster.pm
instance for an old install. Obviously the current template is not right for
that case.  The only reason we didn't notice before is because the existing
cross-version tests, e.g. 002_pg_upgrade.pl, always pass initdb options for
the old node.

Oversight in 252dcb32397.

Backpatch-through: 17
---
 src/test/perl/PostgreSQL/Test/Cluster.pm | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm
index 920d831be9e..0875c5a6e53 100644
--- a/src/test/perl/PostgreSQL/Test/Cluster.pm
+++ b/src/test/perl/PostgreSQL/Test/Cluster.pm
@@ -657,12 +657,15 @@ sub init
 	# disabled, use a previously initdb'd cluster as a template by copying it.
 	# For a lot of tests, that's substantially cheaper. It does not seem
 	# worth figuring out whether extra parameters affect compatibility, so
-	# initdb is forced if any are defined.
+	# initdb is forced if any are defined.  The template was created by the
+	# installation under test, so it can't be used for a node using a
+	# different installation.
 	#
 	# There's very similar code in pg_regress.c, but we can't easily
 	# deduplicate it until we require perl at build time.
 	if (   $params{force_initdb}
 		or defined $params{extra}
+		or defined $self->{_install_path}
 		or !defined $ENV{INITDB_TEMPLATE})
 	{
 		note("initializing database system by running initdb");

base-commit: cb3a90c8211241aaeb88de799f6bd96a776f6675
-- 
2.54.0.450.g9ac3f193c0

