Hello!

Found out that test for pg_upgrade (test.sh for 11-14 and 002_pg_upgrade.pl for 15+) doesn't work from 10th versions to higher ones due to incompatible options for initdb and default PGDATA permissions.

Here are the patches that may solve this problem.

Would be glad to your comments and concerns.


With best regards,
--
Anton A. Melnikov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
commit aa96ef028482fc026850363c776145687cc60fc4
Author: Anton A. Melnikov <a.melni...@postgrespro.ru>
Date:   Thu Jun 2 03:35:26 2022 +0300

    Fix test for pg_upgrade from 10x versions.

diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index 75ac768a96..e9b4977fee 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -1,5 +1,6 @@
 # Set of tests for pg_upgrade, including cross-version checks.
 use strict;
+use version;
 use warnings;
 
 use Cwd qw(abs_path getcwd);
@@ -56,7 +57,13 @@ my $oldnode =
 # To increase coverage of non-standard segment size and group access without
 # increasing test runtime, run these tests with a custom setting.
 # --allow-group-access and --wal-segsize have been added in v11.
-$oldnode->init(extra => [ '--wal-segsize', '1', '--allow-group-access' ]);
+my ($oldverstr) = `$ENV{oldinstall}/bin/pg_ctl --version` =~ /(\d+\.\d+)/;
+my ($oldver) =  (version->parse(${oldverstr}));
+$oldnode->init(extra => [ '--wal-segsize', '1', '--allow-group-access' ])
+		if $oldver >= version->parse('11.0');
+$oldnode->init()
+		if $oldver < version->parse('11.0');
+
 $oldnode->start;
 
 # The default location of the source code is the root of this directory.
commit c62e484e73e0071bc00dffe3b2333fd702108ec6
Author: Anton A. Melnikov <a.melni...@postgrespro.ru>
Date:   Thu Jun 2 03:40:09 2022 +0300

    Fix test for pg_upgrade from 10x versions.

diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh
index f353e565b5..2f5ef1bb9f 100644
--- a/src/bin/pg_upgrade/test.sh
+++ b/src/bin/pg_upgrade/test.sh
@@ -24,7 +24,13 @@ standard_initdb() {
 	# without increasing test runtime, run these tests with a custom setting.
 	# Also, specify "-A trust" explicitly to suppress initdb's warning.
 	# --allow-group-access and --wal-segsize have been added in v11.
-	"$1" -N --wal-segsize 1 --allow-group-access -A trust
+	initdbopt="-N -A trust"
+	if [ $OLD_PG_VERSION_NUM -ge 110000 ]; then
+		initdbopt="$initdbopt --wal-segsize 1 --allow-group-access"
+	fi
+
+	"$1" $initdbopt
+
 	if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ]
 	then
 		cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf"
@@ -136,6 +142,7 @@ PGHOSTADDR="";        unset PGHOSTADDR
 
 # Select a non-conflicting port number, similarly to pg_regress.c
 PG_VERSION_NUM=`grep '#define PG_VERSION_NUM' "$newsrc"/src/include/pg_config.h | awk '{print $3}'`
+OLD_PG_VERSION_NUM=`grep '#define PG_VERSION_NUM' "$oldsrc"/src/include/pg_config.h | awk '{print $3}'`
 PGPORT=`expr $PG_VERSION_NUM % 16384 + 49152`
 export PGPORT
 
@@ -240,18 +247,26 @@ pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "$PGDATA" -b "$oldbindir" -p "
 
 # make sure all directories and files have group permissions, on Unix hosts
 # Windows hosts don't support Unix-y permissions.
+if [ $OLD_PG_VERSION_NUM -lt 110000 ]; then
+	NEW_DIR_PERM=700
+	NEW_FILE_PERM=600
+else
+	NEW_DIR_PERM=750
+	NEW_FILE_PERM=640
+fi
+
 case $testhost in
-	MINGW*|CYGWIN*) ;;
-	*)	if [ `find "$PGDATA" -type f ! -perm 640 | wc -l` -ne 0 ]; then
-			echo "files in PGDATA with permission != 640";
+	MINGW*) ;;
+	*)	if [ `find "$PGDATA" -type f ! -perm $NEW_FILE_PERM | wc -l` -ne 0 ]; then
+			echo "files in PGDATA with permission != $NEW_FILE_PERM";
 			exit 1;
 		fi ;;
 esac
 
 case $testhost in
-	MINGW*|CYGWIN*) ;;
-	*)	if [ `find "$PGDATA" -type d ! -perm 750 | wc -l` -ne 0 ]; then
-			echo "directories in PGDATA with permission != 750";
+	MINGW*) ;;
+	*)	if [ `find "$PGDATA" -type d ! -perm $NEW_DIR_PERM | wc -l` -ne 0 ]; then
+			echo "directories in PGDATA with permission != $NEW_DIR_PERM";
 			exit 1;
 		fi ;;
 esac

Reply via email to