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 1tv0xl-00FdJq-2E for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Mar 2025 21:28:33 +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 1tv0xj-00C5UP-QM for pgsql-hackers@arkaria.postgresql.org; Wed, 19 Mar 2025 21:28:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tv0xj-00C5UH-EV for pgsql-hackers@lists.postgresql.org; Wed, 19 Mar 2025 21:28:31 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tv0xg-0000Ot-2z for pgsql-hackers@postgresql.org; Wed, 19 Mar 2025 21:28:31 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-6f754678c29so1474807b3.0 for ; Wed, 19 Mar 2025 14:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742419707; x=1743024507; 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=AOPF0hgBlEPpO/iq58+DbFh+Xm8iRe+xh052ymBuPwA=; b=RfA5eAQkou1lD+/cy4rowmTpx9WyF3o7N7Xz6kqG7xZrLSz4XFuXPriUGcwbnOTIXR XA2l4UEbC+cskMUJmGBfpOErBlkY+GDewTPAuieKveZc7pvM3I9DUynqSIabCJ7TLFON MXQcsBoieA5i5KaAgmWsQy5Vfr9DYqSEmsPxwJ3PfFSlsF4EdJWjUUv2670HibDTw8Vn p0dSwYTXpJOuDR6rML1Ng9Evi2BG3vD/F5X7lvOYriiTT3932i3iWiuILCSyuPwmHZWX 9Cite4N5L4SfMFCHLNZ15P7Bn8ZOgFjhFlTjBJXHU8jhJGn0HerB1Y7UTF6PrrDM7NQu A3Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742419707; x=1743024507; 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=AOPF0hgBlEPpO/iq58+DbFh+Xm8iRe+xh052ymBuPwA=; b=v0khE03ZJVMw9Pdwd6PoAk0/9ZmeFEx/c2iGBGSz0dg06x3ZeieSxdp9O+Iij09akw 3bQahjFhX+GoD74Me6/dT4wj0VgEluBU1YYwq0sMz7fuN12c/4vkLKI4v3iRrlnMaSoq cXjn86e65Xeid6rIyvyC7s4OhhRp4zmWMfKjIckwlZQAyaLTlcgI7IMrs5czqlqYeg4t yxKbB+AS0w+OWcsbqxr0CFm5z3t/PInCsEplXMT+GmXFCrQjp4u3qnMr7rM/ZbTMBhR8 m7Hzq4lZOpM4wtlv9qXT2bDpBexi8OMi/oNXegsZcPdlDe59sj8CuN/WuFJfTtP2ceHV TTdA== X-Forwarded-Encrypted: i=1; AJvYcCXiGmmnMwMam8s6qs9HA0F7pBcAfx76jNZBD6a1Kjm/EcDP13miHQ1uEQSIhZVitCkfKuoqS1j6BNWZoVI1@postgresql.org X-Gm-Message-State: AOJu0YzzJgGB/xOBnYebzO+kBW4ZUSHJMHM1jtQCEbD2lsV+PQgbVQF+ gH31Y8/APrG6zmdWUP63FJu75jB7Sw/Nm9llbgb25OCtqO1bOrl2 X-Gm-Gg: ASbGncus7O3c5XWxVfSnjZ0ZPHD16hFzCuBJLKzFnekW1Nwxfs0KGszBmmjHUgC7uVK 5NDdw59Dfp5x0WTcIuSdUfqaG1Mmev5kNXTD/eKAnR8NjrBbpV3xcA0prJZgSP10KsNZeoBlW40 o8daWrgMJ0rmx/V3dMc2jXDhbinrGcXx+xr3/QqqShjslXTSagLc2qP1PLsy57NFMaYDyoTr1pC tjSuNDIKY4nMXbSu9Wz3rW/DN+jlBIGfq/5W9XTN/y7PfM85rOQKi+APTgCK+R5QjqSYSU6PYGX LM2EqxrDCNA+FUxdmrW7TqkVJo7sTVHDqVCL78WDmggM574UoveKc2uYW5fQsRkjvHMgncDrVOJ +QMCtQAtewY/tO8fm+7o78M/i7crg7fFK7DE= X-Google-Smtp-Source: AGHT+IHtac+szwIOzX0LCHpckr54vpCzr1hIB++9cYZ5S4gL9VIRjMmBoMzL7uGp3xwH7bCtlrQwfg== X-Received: by 2002:a05:690c:6ac8:b0:6f9:88ba:aa5d with SMTP id 00721157ae682-7009bf86272mr58848537b3.9.1742419706660; Wed, 19 Mar 2025 14:28:26 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ff32a82b3csm32223377b3.64.2025.03.19.14.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Mar 2025 14:28:26 -0700 (PDT) Date: Wed, 19 Mar 2025 16:28:23 -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: <7rhxl5nl5cuenm4kzprjhaojo74m2teuwzjffcrdi6bxx6b2wn@orb5h3mteh2y> <712605.1742401713@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="C5ohSC+cpjxht8ja" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --C5ohSC+cpjxht8ja Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Mar 19, 2025 at 02:32:01PM -0500, Nathan Bossart wrote: > In addition to testing with in-place tablespaces, we might also want to > teach the transfer modes test to do cross-version testing when possible. > In that case, we can test normal (non-in-place) tablespaces. However, that > would be limited to the buildfarm. Actually, this one was pretty easy to do. -- nathan --C5ohSC+cpjxht8ja Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Add-test-for-pg_upgrade-file-transfer-modes.patch" From cc9bcd456f0d7d6ab19a89813755a3e76993cfb9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 18 Mar 2025 20:58:07 -0500 Subject: [PATCH 1/1] Add test for pg_upgrade file transfer modes. This new test checks all of pg_upgrade's file transfer modes. For each mode, we verify that pg_upgrade either succeeds (and some test objects successfully reach the new version) or fails with an error that indicates the mode is not supported on the current platform. Suggested-by: Robert Haas Reviewed-by: Andres Freund Discussion: https://postgr.es/m/Zyvop-LxLXBLrZil%40nathan --- src/bin/pg_upgrade/meson.build | 1 + src/bin/pg_upgrade/t/006_modes.pl | 89 ++++++++++++++++++++++++ src/test/perl/PostgreSQL/Test/Cluster.pm | 19 +++++ src/test/perl/PostgreSQL/Test/Utils.pm | 25 +++++++ 4 files changed, 134 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..85098e86245 --- /dev/null +++ b/src/bin/pg_upgrade/t/006_modes.pl @@ -0,0 +1,89 @@ +# 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', install_path => $ENV{oldinstall}); + my $new = PostgreSQL::Test::Cluster->new('new'); + + if (defined($ENV{oldinstall})) + { + $old->init(force_initdb => 1, extra => ['-k']); + } + else + { + $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 testdb1"); + $old->safe_psql('testdb1', "CREATE TABLE test2 AS SELECT generate_series(200, 300)"); + $old->safe_psql('testdb1', "VACUUM FULL test2"); + $old->safe_psql('testdb1', "CREATE SEQUENCE testseq START 5432"); + if (defined($ENV{oldinstall})) + { + my $tblspc = PostgreSQL::Test::Utils::tempdir_short(); + $old->safe_psql('postgres', "CREATE TABLESPACE test_tblspc LOCATION '$tblspc'"); + $old->safe_psql('postgres', "CREATE DATABASE testdb2 TABLESPACE test_tblspc"); + $old->safe_psql('postgres', "CREATE TABLE test3 TABLESPACE test_tblspc AS SELECT generate_series(300, 401)"); + $old->safe_psql('testdb2', "CREATE TABLE test4 AS SELECT generate_series(400, 502)"); + } + $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('testdb1', "SELECT COUNT(*) FROM test2"); + is($result, '101', "test2 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb1', "SELECT nextval('testseq')"); + is($result, '5432', "sequence data after pg_upgrade $mode"); + if (defined($ENV{oldinstall})) + { + $result = $new->safe_psql('postgres', "SELECT COUNT(*) FROM test3"); + is($result, '102', "test3 data after pg_upgrade $mode"); + $result = $new->safe_psql('testdb2', "SELECT COUNT(*) FROM test4"); + is($result, '103', "test4 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 05bd94609d4..8759ed2cbba 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) --C5ohSC+cpjxht8ja--