Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tucJ0-00AD2z-Cv for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Mar 2025 19:08:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tucIy-003LVY-LG for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Mar 2025 19:08:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tucIy-003LRW-6t for pgsql-hackers@lists.postgresql.org; Tue, 18 Mar 2025 19:08:48 +0000 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tucIw-003Ypo-0e for pgsql-hackers@postgresql.org; Tue, 18 Mar 2025 19:08:47 +0000 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-6fecfae554bso54287707b3.0 for ; Tue, 18 Mar 2025 12:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742324926; x=1742929726; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=mxfkA6HJMzp5UqZjoLIwxwafPQvRIvoAfJmP5R0AxsY=; b=njfrEr4+xKSRpSkzEICEMMBcNPqZuEbFqmYOaghd5ExL7IbDeHnxYWB3whuS+DD3Ga a6Aiuc0ekQc73k44G5WLG2mXzTu6DdX4unyhLZkwPNc8lQDHzkL1pAmLh9yPAvQaoFXb H0rnszSrqN6+FmFy+2wIIuDBeNUX84EtU1lH226qNoNoYDKyF98RiBERSipq0Gcwi0qK PHqqXYCYH2yN/w7lC/srXn+5WDp9LpD0N3jaJAiF1/D3FK1MouaawrCAFwUVvglYF9iP oGL6Ynfseuq64lqdyIKyST75B/jGMBEBBrLNHOAI+Y3mrUvNtBhte3fGTZAsStxrnUCf Bk0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742324926; x=1742929726; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mxfkA6HJMzp5UqZjoLIwxwafPQvRIvoAfJmP5R0AxsY=; b=cVVV3zlyz0jGERIHbDwOf92T4JCcuZxTFL4HKUTPa0EExG7BF68wwVI39K17jmgxR1 H498sl54loLvPblU9PjjdZNSuXazIf4WPe0DQitwqVQLPSPaFRhJQGuAFekf42D9LaNS Y573gljXJ8lJMIayODgreMK5VakvKAReXEpwcFL9UZ9HiXXcIFkO2kaGLDRxiN4lxQv3 bEunxv24u+6Ns1YEfxq7x63RBJFi5iFTuWBg2G0M7It7y/LqnBLSKl/kdt0VT1lZ0zcj /Xt629I6a4TP/vxw6Ky1MDntaEWy0D8oO5gBnQy5QUMTgH2HhEs/PuqxTQOH/2Sr9Ng6 6++g== X-Forwarded-Encrypted: i=1; AJvYcCXSBV0x0Q/SqBV4Lrp5ch1e7u2WpY3JCJs7V21XJ/yoZlQvweOt+d3vESL+4PQzGL2w+MZIwjIw9OnxRCFK@postgresql.org X-Gm-Message-State: AOJu0YwpjBfHfR457/QWWmcK8zBYA9/XxayS3WrL5Wnr6u1VIiXfI4Wl V8Vodc0d9ebDqOuFEpBhbVCRXt+Q/oOiSA7vX43ngVe/Ffso0AbL X-Gm-Gg: ASbGnctuyEaWq9Q/dvHhbKbicAGKdyc1xommIyNRPS5kZt1yEA+sq/v74YvsC2rRkpI Huyz9LZJ31qPondR3SB3aIN10Epg40o/BYpzSoARwgpe3B2PSFOWZKoluuCRSdmvJaWEEpM024M 1c9Pysnf5ec1wJAdTUlUzW64GoxUAXBjfgEWy7ECz0j8rS2fxmuPOOWndYFR6DBRd/xWn4YyuOY nU6u66BCDfVN2zBucWcnCumpW8cGAmww4z7zMA0P2k9ZMt2ubfjnNDvLNJwq07Y2fkhqBytIzps NlhBHuoJTkgMNf46+OgS/hkHxkK3zTVagqz8XpxyFUPNIlCREgJer/bOYGN9WNH/R49Fm1CAQ09 YIQ8ulSHgpfyqP0rpi9e4KsJaKtHFV82TMAFLXaJmpCH44g== X-Google-Smtp-Source: AGHT+IFPwFR6J3QgE/j4CVdC2y7Nvuw8ur9HVjIwmyTlUABIN8R0pyPT90VEpt5hP0OjI7mZZNqKXQ== X-Received: by 2002:a05:6902:1105:b0:e48:7efe:57b0 with SMTP id 3f1490d57ef6-e63f65c53b7mr22508914276.47.1742324925595; Tue, 18 Mar 2025 12:08:45 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e64f4bac1e9sm530582276.12.2025.03.18.12.08.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Mar 2025 12:08:44 -0700 (PDT) Date: Tue, 18 Mar 2025 14:08:42 -0500 From: Nathan Bossart To: Andres Freund Cc: Tom Lane , Robert Haas , Greg Sabino Mullane , pgsql-hackers@postgresql.org, bruce@momjian.us Subject: Re: optimize file transfer in pg_upgrade Message-ID: References: <17820.1742306681@sss.pgh.pa.us> <7rhxl5nl5cuenm4kzprjhaojo74m2teuwzjffcrdi6bxx6b2wn@orb5h3mteh2y> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="RVUTIYpSRw61lFha" Content-Disposition: inline In-Reply-To: <7rhxl5nl5cuenm4kzprjhaojo74m2teuwzjffcrdi6bxx6b2wn@orb5h3mteh2y> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --RVUTIYpSRw61lFha Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Mar 18, 2025 at 01:50:10PM -0400, Andres Freund wrote: > On 2025-03-18 12:47:01 -0500, Nathan Bossart wrote: >> On Tue, Mar 18, 2025 at 01:37:02PM -0400, Andres Freund wrote: >> > - Do we need a new old cluster for each of the modes? That seems like wasted >> > time? I guess it's required for --link... >> >> It'll also be needed for --swap. We could optionally save the old cluster >> for a couple of modes if we really wanted to. *shrug* > > Don't worry about it, I think the template initdb stuff should make it cheap enough... Cool. I realize now why there's poor coverage for pg_upgrade with tablespaces: you can't upgrade between the same version with tablespaces (presumably due to the version-specific subdirectory conflict). I don't know if the regression tests leave around any tablespaces for the cross-version pg_upgrade tests, but that's probably the best we can do at the moment. For now, here's a new version of the test with a rewritten table. I also tried to fix the expected error regex to handle some of the other error messages for unsupported modes (as revealed by cfbot). -- nathan --RVUTIYpSRw61lFha Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Add-test-for-pg_upgrade-file-transfer-modes.patch" From c4b7816955cfb5d331851e14f9a93cbb182f4d1e Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 18 Mar 2025 12:21:03 -0500 Subject: [PATCH v2 1/1] Add test for pg_upgrade file transfer modes. --- src/bin/pg_upgrade/meson.build | 1 + src/bin/pg_upgrade/t/006_modes.pl | 67 ++++++++++++++++++++++++ src/test/perl/PostgreSQL/Test/Cluster.pm | 19 +++++++ src/test/perl/PostgreSQL/Test/Utils.pm | 25 +++++++++ 4 files changed, 112 insertions(+) create mode 100644 src/bin/pg_upgrade/t/006_modes.pl diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index da84344966a..16cd9247e76 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -46,6 +46,7 @@ tests += { 't/003_logical_slots.pl', 't/004_subscription.pl', 't/005_char_signedness.pl', + 't/006_modes.pl', ], 'test_kwargs': {'priority': 40}, # pg_upgrade tests are slow }, diff --git a/src/bin/pg_upgrade/t/006_modes.pl b/src/bin/pg_upgrade/t/006_modes.pl new file mode 100644 index 00000000000..468591fc486 --- /dev/null +++ b/src/bin/pg_upgrade/t/006_modes.pl @@ -0,0 +1,67 @@ +# Copyright (c) 2025, PostgreSQL Global Development Group + +# Tests for file transfer modes + +use strict; +use warnings FATAL => 'all'; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +sub test_mode +{ + my ($mode) = @_; + + my $old = PostgreSQL::Test::Cluster->new('old'); + my $new = PostgreSQL::Test::Cluster->new('new'); + + $old->init(); + $new->init(); + + $old->start; + $old->safe_psql('postgres', "CREATE TABLE test1 AS SELECT generate_series(1, 100)"); + $old->safe_psql('postgres', "CREATE DATABASE testdb"); + $old->safe_psql('testdb', "CREATE TABLE test2 AS SELECT generate_series(200, 300)"); + $old->safe_psql('testdb', "VACUUM FULL test2"); + $old->safe_psql('testdb', "CREATE SEQUENCE testseq START 5432"); + $old->stop; + + my $result = command_ok_or_fails_like( + [ + 'pg_upgrade', '--no-sync', + '--old-datadir' => $old->data_dir, + '--new-datadir' => $new->data_dir, + '--old-bindir' => $old->config_data('--bindir'), + '--new-bindir' => $new->config_data('--bindir'), + '--socketdir' => $new->host, + '--old-port' => $old->port, + '--new-port' => $new->port, + $mode + ], + qr/.* not supported on this platform|could not .* between old and new data directories: .*/, + qr/^$/, + "pg_upgrade with transfer mode $mode"); + + if ($result) + { + $new->start; + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test1"); + is($result, '100', "test1 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb', "SELECT COUNT(*) FROM test2"); + is($result, '101', "test2 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb', "SELECT nextval('testseq')"); + is($result, '5432', "sequence data after pg_upgrade $mode"); + $new->stop; + } + + $old->clean_node(); + $new->clean_node(); +} + +test_mode('--clone'); +test_mode('--copy'); +test_mode('--copy-file-range'); +test_mode('--link'); + +done_testing(); diff --git a/src/test/perl/PostgreSQL/Test/Cluster.pm b/src/test/perl/PostgreSQL/Test/Cluster.pm index bab3f3d2dbe..bda19bbcee2 100644 --- a/src/test/perl/PostgreSQL/Test/Cluster.pm +++ b/src/test/perl/PostgreSQL/Test/Cluster.pm @@ -2801,6 +2801,25 @@ sub command_fails_like =pod +=item $node->command_ok_or_fails_like(...) + +PostgreSQL::Test::Utils::command_ok_or_fails_like with our connection parameters. See command_ok(...) + +=cut + +sub command_ok_or_fails_like +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + + my $self = shift; + + local %ENV = $self->_get_env(); + + return PostgreSQL::Test::Utils::command_ok_or_fails_like(@_); +} + +=pod + =item $node->command_checks_all(...) PostgreSQL::Test::Utils::command_checks_all with our connection parameters. See diff --git a/src/test/perl/PostgreSQL/Test/Utils.pm b/src/test/perl/PostgreSQL/Test/Utils.pm index d1ad131eadf..7d7ca83495f 100644 --- a/src/test/perl/PostgreSQL/Test/Utils.pm +++ b/src/test/perl/PostgreSQL/Test/Utils.pm @@ -89,6 +89,7 @@ our @EXPORT = qw( command_like command_like_safe command_fails_like + command_ok_or_fails_like command_checks_all $windows_os @@ -1067,6 +1068,30 @@ sub command_fails_like =pod +=item command_ok_or_fails_like(cmd, expected_stdout, expected_stderr, test_name) + +Check that the command either succeeds or fails with an error that matches the +given regular expressions. + +=cut + +sub command_ok_or_fails_like +{ + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($cmd, $expected_stdout, $expected_stderr, $test_name) = @_; + my ($stdout, $stderr); + print("# Running: " . join(" ", @{$cmd}) . "\n"); + my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr; + if (!$result) + { + like($stdout, $expected_stdout, "$test_name: stdout matches"); + like($stderr, $expected_stderr, "$test_name: stderr matches"); + } + return $result; +} + +=pod + =item command_checks_all(cmd, ret, out, err, test_name) Run a command and check its status and outputs. -- 2.39.5 (Apple Git-154) --RVUTIYpSRw61lFha--