On 07.12.22 17:33, Peter Eisentraut wrote:
I think if we want to make this configurable on the fly, and environment variable would be much easier, like

     my $mode = $ENV{PG_TEST_PG_UPGRADE_MODE} || '--copy';

Here is an updated patch set that incorporates this idea.
From c0f72bb9f50a36bc158943f3a51fbbc749d7f93c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 14 Dec 2022 07:52:58 +0100
Subject: [PATCH v2 1/2] pg_upgrade: Add --copy option

This option selects the default transfer mode.  Having an explicit
option is handy to make scripts and tests more explicit.  It also
makes it easier to talk about a "copy" mode rather than "the default
mode" or something like that, since until now the default mode didn't
have an externally visible name.

Discussion: 
https://www.postgresql.org/message-id/flat/50a97009-8ff9-ca4d-a0f6-6086a6775a5b%40enterprisedb.com
---
 doc/src/sgml/ref/pgupgrade.sgml | 10 ++++++++++
 src/bin/pg_upgrade/option.c     |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml
index 8f7a3025c3..7816b4c685 100644
--- a/doc/src/sgml/ref/pgupgrade.sgml
+++ b/doc/src/sgml/ref/pgupgrade.sgml
@@ -230,6 +230,16 @@ <title>Options</title>
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>--copy</option></term>
+      <listitem>
+       <para>
+        Copy files to the new cluster.  This is the default.  (See also
+        <option>--link</option> and <option>--clone</option>.)
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-?</option></term>
       <term><option>--help</option></term>
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index 2939f584b4..51fc7aede0 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -56,6 +56,7 @@ parseCommandLine(int argc, char *argv[])
                {"socketdir", required_argument, NULL, 's'},
                {"verbose", no_argument, NULL, 'v'},
                {"clone", no_argument, NULL, 1},
+               {"copy", no_argument, NULL, 2},
 
                {NULL, 0, NULL, 0}
        };
@@ -194,6 +195,10 @@ parseCommandLine(int argc, char *argv[])
                                user_opts.transfer_mode = TRANSFER_MODE_CLONE;
                                break;
 
+                       case 2:
+                               user_opts.transfer_mode = TRANSFER_MODE_COPY;
+                               break;
+
                        default:
                                fprintf(stderr, _("Try \"%s --help\" for more 
information.\n"),
                                                os_info.progname);
@@ -283,6 +288,7 @@ usage(void)
        printf(_("  -v, --verbose                 enable verbose internal 
logging\n"));
        printf(_("  -V, --version                 display version information, 
then exit\n"));
        printf(_("  --clone                       clone instead of copying 
files to new cluster\n"));
+       printf(_("  --copy                        copy files to new cluster 
(default)\n"));
        printf(_("  -?, --help                    show this help, then 
exit\n"));
        printf(_("\n"
                         "Before running pg_upgrade you must:\n"

base-commit: 60684dd834a222fefedd49b19d1f0a6189c1632e
-- 
2.38.1

From 49861815c1cf76658a77cf8ade59c4bb61c4064b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 14 Dec 2022 08:02:57 +0100
Subject: [PATCH v2 2/2] pg_upgrade: Make testing different transfer modes
 easier

The environment variable PG_TEST_PG_UPGRADE_MODE can be set to
override the default transfer mode for the pg_upgrade tests.
(Automatically running the pg_upgrade tests for all supported modes
would be too slow.)

Discussion: 
https://www.postgresql.org/message-id/flat/50a97009-8ff9-ca4d-a0f6-6086a6775a5b%40enterprisedb.com
---
 src/bin/pg_upgrade/t/002_pg_upgrade.pl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_upgrade/t/002_pg_upgrade.pl 
b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
index add6ea9c34..1d5c80907c 100644
--- a/src/bin/pg_upgrade/t/002_pg_upgrade.pl
+++ b/src/bin/pg_upgrade/t/002_pg_upgrade.pl
@@ -12,6 +12,9 @@
 use PostgreSQL::Test::Utils;
 use Test::More;
 
+# Can be changed to test the other modes.
+my $mode = $ENV{PG_TEST_PG_UPGRADE_MODE} || '--copy';
+
 # Generate a database with a name made of a range of ASCII characters.
 sub generate_db
 {
@@ -75,6 +78,8 @@ sub filter_dump
 my $dump1_file = "$tempdir/dump1.sql";
 my $dump2_file = "$tempdir/dump2.sql";
 
+note "testing using transfer mode $mode";
+
 # Initialize node to upgrade
 my $oldnode =
   PostgreSQL::Test::Cluster->new('old_node',
@@ -128,6 +133,7 @@ sub filter_dump
        # --inputdir points to the path of the input files.
        my $inputdir = "$srcdir/src/test/regress";
 
+       note 'running regression tests in old instance';
        my $rc =
          system($ENV{PG_REGRESS}
                  . " $extra_opts "
@@ -256,6 +262,7 @@ sub filter_dump
                '-s',         $newnode->host,
                '-p',         $oldnode->port,
                '-P',         $newnode->port,
+               $mode,
                '--check'
        ],
        'run of pg_upgrade --check for new instance with incorrect binary 
path');
@@ -270,6 +277,7 @@ sub filter_dump
                '-D',         $newnode->data_dir, '-b', $oldbindir,
                '-B',         $newbindir,         '-s', $newnode->host,
                '-p',         $oldnode->port,     '-P', $newnode->port,
+               $mode,
                '--check'
        ],
        'run of pg_upgrade --check for new instance');
@@ -282,7 +290,8 @@ sub filter_dump
                'pg_upgrade', '--no-sync',        '-d', $oldnode->data_dir,
                '-D',         $newnode->data_dir, '-b', $oldbindir,
                '-B',         $newbindir,         '-s', $newnode->host,
-               '-p',         $oldnode->port,     '-P', $newnode->port
+               '-p',         $oldnode->port,     '-P', $newnode->port,
+               $mode,
        ],
        'run of pg_upgrade for new instance');
 ok( !-d $newnode->data_dir . "/pg_upgrade_output.d",
-- 
2.38.1

Reply via email to