I wanted to test the different pg_upgrade transfer modes (--link, --clone), but that was not that easy, because there is more than one place in the test script you have to find and manually change. So I wrote a little patch to make that easier. It's still manual, but it's a start. (In principle, we could automatically run the tests with each supported mode in a loop, but that would be very slow.)

While doing that, I also found it strange that the default transfer mode (referred to as "copy" internally) did not have any external representation, so it is awkward to refer to it in text, and obscure to see where it is used for example in those test scripts. So I added an option --copy, which effectively does nothing, but it's not uncommon to have options that select default behaviors explicitly. (I also thought about something like a "mode" option with an argument, but given that we already have --link and --clone, this seemed the most sensible.)

Thoughts?
From e01feabdfc0e2ea01242afd93261885c035e7942 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 1 Dec 2022 15:34:00 +0100
Subject: [PATCH 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.
---
 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 8f7a3025c368..7816b4c6859b 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 f441668c612a..f986129c2fb9 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: ec386948948c1708c0c28c48ef08b9c4dd9d47cc
-- 
2.38.1

From b87a6bbb293deb94693774fa7b5c1e4918704f57 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Thu, 1 Dec 2022 15:36:12 +0100
Subject: [PATCH 2/2] pg_upgrade: Make testing different transfer modes easier

It still requires a manual change in the test script, but now there is
only one well-marked place to change.  (Automatically running the
pg_upgrade tests for all supported modes would be too slow.)
---
 src/bin/pg_upgrade/t/002_pg_upgrade.pl | 8 +++++++-
 1 file changed, 7 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 add6ea9c3437..365d81a8a380 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 (manually) to test the other modes.
+my $mode = '--copy';
+
 # Generate a database with a name made of a range of ASCII characters.
 sub generate_db
 {
@@ -256,6 +259,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 +274,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 +287,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