Apply more consistent style for command options in TAP tests

This commit reshapes the grammar of some commands to apply a more
consistent style across the board, following rules similar to
ce1b0f9da03e:
- Elimination of some pointless used-once variables.
- Use of long options, to self-document better the options used.
- Use of fat commas to link option names and their assigned values,
including redirections, so as perltidy can be tricked to put them
together.

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://postgr.es/m/87jz8rzf3h.fsf@wibble.ilmari.org
This commit is contained in:
Michael Paquier 2025-03-17 12:42:23 +09:00
parent 5721e5453e
commit 19c6e92b13
43 changed files with 522 additions and 399 deletions

View File

@ -28,7 +28,7 @@ sub query_log
} }
my $node = PostgreSQL::Test::Cluster->new('main'); my $node = PostgreSQL::Test::Cluster->new('main');
$node->init('auth_extra' => [ '--create-role', 'regress_user1' ]); $node->init('auth_extra' => [ '--create-role' => 'regress_user1' ]);
$node->append_conf('postgresql.conf', $node->append_conf('postgresql.conf',
"session_preload_libraries = 'auto_explain'"); "session_preload_libraries = 'auto_explain'");
$node->append_conf('postgresql.conf', "auto_explain.log_min_duration = 0"); $node->append_conf('postgresql.conf', "auto_explain.log_min_duration = 0");

View File

@ -131,8 +131,10 @@ sub verify_backup
# Untar. # Untar.
my $extract_path = PostgreSQL::Test::Utils::tempdir; my $extract_path = PostgreSQL::Test::Utils::tempdir;
system_or_bail($tar, 'xf', $backup_dir . '/' . $prefix . 'base.tar', system_or_bail(
'-C', $extract_path); $tar,
'xf' => $backup_dir . '/' . $prefix . 'base.tar',
'-C' => $extract_path);
# Verify. # Verify.
$node->command_ok( $node->command_ok(

View File

@ -216,8 +216,7 @@ $node->append_conf('postgresql.conf', 'log_statement=none');
'-D' => $node->data_dir, '-D' => $node->data_dir,
'template0' 'template0'
], ],
'<', '<' => $ENV{share_contrib_dir} . '/sepgsql.sql');
$ENV{share_contrib_dir} . '/sepgsql.sql');
ok($result, 'sepgsql installation script'); ok($result, 'sepgsql installation script');
} }

View File

@ -85,10 +85,11 @@ command_fails_like(
my $stderr; my $stderr;
my $oldestkeptwalfile = '00000001000000370000000E'; my $oldestkeptwalfile = '00000001000000370000000E';
my $result = my $result = IPC::Run::run [
IPC::Run::run [ 'pg_archivecleanup', '-d', '-n', $tempdir, 'pg_archivecleanup', '--debug', '--dry-run', $tempdir,
$oldestkeptwalfile ], $oldestkeptwalfile
'2>', \$stderr; ],
'2>' => \$stderr;
ok($result, "pg_archivecleanup dry run: exit code 0"); ok($result, "pg_archivecleanup dry run: exit code 0");
for my $walpair (@walfiles_verbose) for my $walpair (@walfiles_verbose)

View File

@ -60,7 +60,8 @@ command_fails_like(
[ 'pg_resetwal', $node->data_dir ], [ 'pg_resetwal', $node->data_dir ],
qr/not proceeding because control file values were guessed/, qr/not proceeding because control file values were guessed/,
'does not run when control file values were guessed'); 'does not run when control file values were guessed');
command_ok([ 'pg_resetwal', '-f', $node->data_dir ], command_ok(
[ 'pg_resetwal', '--force', $node->data_dir ],
'runs with force when control file values were guessed'); 'runs with force when control file values were guessed');
done_testing(); done_testing();

View File

@ -56,8 +56,7 @@ my $ret = run_log(
'--target-pgdata' => $primary_pgdata, '--target-pgdata' => $primary_pgdata,
'--no-sync', '--no-sync',
], ],
'2>>', '2>>' => "$standby_pgdata/tst_both_dir/file1");
"$standby_pgdata/tst_both_dir/file1");
ok(!$ret, 'Error out on copying growing file'); ok(!$ret, 'Error out on copying growing file');
# Ensure that the files are of different size, the final error message should # Ensure that the files are of different size, the final error message should

View File

@ -69,8 +69,9 @@ sub primary_psql
my $cmd = shift; my $cmd = shift;
my $dbname = shift || 'postgres'; my $dbname = shift || 'postgres';
system_or_bail 'psql', '-q', '--no-psqlrc', '-d', system_or_bail 'psql', '--quiet', '--no-psqlrc',
$node_primary->connstr($dbname), '-c', "$cmd"; '--dbname' => $node_primary->connstr($dbname),
'--command' => $cmd;
return; return;
} }
@ -79,8 +80,9 @@ sub standby_psql
my $cmd = shift; my $cmd = shift;
my $dbname = shift || 'postgres'; my $dbname = shift || 'postgres';
system_or_bail 'psql', '-q', '--no-psqlrc', '-d', system_or_bail 'psql', '--quiet', '--no-psqlrc',
$node_standby->connstr($dbname), '-c', "$cmd"; '--dbname' => $node_standby->connstr($dbname),
'--command' => $cmd;
return; return;
} }
@ -95,11 +97,12 @@ sub check_query
# we want just the output, no formatting # we want just the output, no formatting
my $result = run [ my $result = run [
'psql', '-q', '-A', '-t', '--no-psqlrc', '-d', 'psql', '--quiet', '--no-align', '--tuples-only', '--no-psqlrc',
$node_primary->connstr('postgres'), '--dbname' => $node_primary->connstr('postgres'),
'-c', $query '--command' => $query
], ],
'>', \$stdout, '2>', \$stderr; '>' => \$stdout,
'2>' => \$stderr;
is($result, 1, "$test_name: psql exit code"); is($result, 1, "$test_name: psql exit code");
is($stderr, '', "$test_name: psql no stderr"); is($stderr, '', "$test_name: psql no stderr");
@ -124,7 +127,7 @@ sub setup_cluster
$node_primary->init( $node_primary->init(
allows_streaming => 1, allows_streaming => 1,
extra => $extra, extra => $extra,
auth_extra => [ '--create-role', 'rewind_user' ]); auth_extra => [ '--create-role' => 'rewind_user' ]);
# Set wal_keep_size to prevent WAL segment recycling after enforced # Set wal_keep_size to prevent WAL segment recycling after enforced
# checkpoints in the tests. # checkpoints in the tests.

View File

@ -208,7 +208,8 @@ if (defined($ENV{olddump}))
# Load the dump using the "postgres" database as "regression" does # Load the dump using the "postgres" database as "regression" does
# not exist yet, and we are done here. # not exist yet, and we are done here.
$oldnode->command_ok([ 'psql', '-X', '-f', $olddumpfile, 'postgres' ], $oldnode->command_ok(
[ 'psql', '--no-psqlrc', '--file' => $olddumpfile, 'postgres' ],
'loaded old dump file'); 'loaded old dump file');
} }
else else
@ -303,14 +304,15 @@ if (defined($ENV{oldinstall}))
my @command_args = (); my @command_args = ();
for my $upcmd (@{ $adjust_cmds->{$updb} }) for my $upcmd (@{ $adjust_cmds->{$updb} })
{ {
push @command_args, '-c', $upcmd; push @command_args, '--command' => $upcmd;
} }
# For simplicity, use the newer version's psql to issue the commands. # For simplicity, use the newer version's psql to issue the commands.
$newnode->command_ok( $newnode->command_ok(
[ [
'psql', '-X', '-v', 'ON_ERROR_STOP=1', 'psql', '--no-psqlrc',
'-d', $oldnode->connstr($updb), '--set' => 'ON_ERROR_STOP=1',
'--dbname' => $oldnode->connstr($updb),
@command_args, @command_args,
], ],
"ran version adaptation commands for database $updb"); "ran version adaptation commands for database $updb");
@ -324,8 +326,9 @@ $oldnode->restart;
# Take a dump before performing the upgrade as a base comparison. Note # Take a dump before performing the upgrade as a base comparison. Note
# that we need to use pg_dumpall from the new node here. # that we need to use pg_dumpall from the new node here.
my @dump_command = ( my @dump_command = (
'pg_dumpall', '--no-sync', '-d', $oldnode->connstr('postgres'), 'pg_dumpall', '--no-sync',
'-f', $dump1_file); '--dbname' => $oldnode->connstr('postgres'),
'--file' => $dump1_file);
# --extra-float-digits is needed when upgrading from a version older than 11. # --extra-float-digits is needed when upgrading from a version older than 11.
push(@dump_command, '--extra-float-digits', '0') push(@dump_command, '--extra-float-digits', '0')
if ($oldnode->pg_version < 12); if ($oldnode->pg_version < 12);
@ -399,13 +402,13 @@ $oldnode->stop;
command_checks_all( command_checks_all(
[ [
'pg_upgrade', '--no-sync', 'pg_upgrade', '--no-sync',
'-d', $oldnode->data_dir, '--old-datadir' => $oldnode->data_dir,
'-D', $newnode->data_dir, '--new-datadir' => $newnode->data_dir,
'-b', $oldbindir . '/does/not/exist/', '--old-bindir' => $oldbindir . '/does/not/exist/',
'-B', $newbindir, '--new-bindir' => $newbindir,
'-s', $newnode->host, '--socketdir' => $newnode->host,
'-p', $oldnode->port, '--old-port' => $oldnode->port,
'-P', $newnode->port, '--new-port' => $newnode->port,
$mode, '--check', $mode, '--check',
], ],
1, 1,
@ -427,13 +430,13 @@ SKIP:
command_checks_all( command_checks_all(
[ [
'pg_upgrade', '--no-sync', 'pg_upgrade', '--no-sync',
'-d', $oldnode->data_dir, '--old-datadir' => $oldnode->data_dir,
'-D', $newnode->data_dir, '--new-datadir' => $newnode->data_dir,
'-b', $oldbindir, '--old-bindir' => $oldbindir,
'-B', $newbindir, '--new-bindir' => $newbindir,
'-s', $newnode->host, '--socketdir' => $newnode->host,
'-p', $oldnode->port, '--old-port' => $oldnode->port,
'-P', $newnode->port, '--new-port' => $newnode->port,
$mode, '--check', $mode, '--check',
], ],
1, 1,
@ -451,10 +454,14 @@ $oldnode->stop;
# --check command works here, cleans up pg_upgrade_output.d. # --check command works here, cleans up pg_upgrade_output.d.
command_ok( command_ok(
[ [
'pg_upgrade', '--no-sync', '-d', $oldnode->data_dir, 'pg_upgrade', '--no-sync',
'-D', $newnode->data_dir, '-b', $oldbindir, '--old-datadir' => $oldnode->data_dir,
'-B', $newbindir, '-s', $newnode->host, '--new-datadir' => $newnode->data_dir,
'-p', $oldnode->port, '-P', $newnode->port, '--old-bindir' => $oldbindir,
'--new-bindir' => $newbindir,
'--socketdir' => $newnode->host,
'--old-port' => $oldnode->port,
'--new-port' => $newnode->port,
$mode, '--check', $mode, '--check',
], ],
'run of pg_upgrade --check for new instance'); 'run of pg_upgrade --check for new instance');
@ -464,10 +471,14 @@ ok(!-d $newnode->data_dir . "/pg_upgrade_output.d",
# Actual run, pg_upgrade_output.d is removed at the end. # Actual run, pg_upgrade_output.d is removed at the end.
command_ok( command_ok(
[ [
'pg_upgrade', '--no-sync', '-d', $oldnode->data_dir, 'pg_upgrade', '--no-sync',
'-D', $newnode->data_dir, '-b', $oldbindir, '--old-datadir' => $oldnode->data_dir,
'-B', $newbindir, '-s', $newnode->host, '--new-datadir' => $newnode->data_dir,
'-p', $oldnode->port, '-P', $newnode->port, '--old-bindir' => $oldbindir,
'--new-bindir' => $newbindir,
'--socketdir' => $newnode->host,
'--old-port' => $oldnode->port,
'--new-port' => $newnode->port,
$mode, $mode,
], ],
'run of pg_upgrade for new instance'); 'run of pg_upgrade for new instance');
@ -512,10 +523,11 @@ is( $result,
# Second dump from the upgraded instance. # Second dump from the upgraded instance.
@dump_command = ( @dump_command = (
'pg_dumpall', '--no-sync', '-d', $newnode->connstr('postgres'), 'pg_dumpall', '--no-sync',
'-f', $dump2_file); '--dbname' => $newnode->connstr('postgres'),
'--file' => $dump2_file);
# --extra-float-digits is needed when upgrading from a version older than 11. # --extra-float-digits is needed when upgrading from a version older than 11.
push(@dump_command, '--extra-float-digits', '0') push(@dump_command, '--extra-float-digits' => '0')
if ($oldnode->pg_version < 12); if ($oldnode->pg_version < 12);
$newnode->command_ok(\@dump_command, 'dump after running pg_upgrade'); $newnode->command_ok(\@dump_command, 'dump after running pg_upgrade');

View File

@ -40,13 +40,13 @@ checkpoint_timeout = 1h
# Setup a common pg_upgrade command to be used by all the test cases # Setup a common pg_upgrade command to be used by all the test cases
my @pg_upgrade_cmd = ( my @pg_upgrade_cmd = (
'pg_upgrade', '--no-sync', 'pg_upgrade', '--no-sync',
'-d', $oldpub->data_dir, '--old-datadir' => $oldpub->data_dir,
'-D', $newpub->data_dir, '--new-datadir' => $newpub->data_dir,
'-b', $oldpub->config_data('--bindir'), '--old-bindir' => $oldpub->config_data('--bindir'),
'-B', $newpub->config_data('--bindir'), '--new-bindir' => $newpub->config_data('--bindir'),
'-s', $newpub->host, '--socketdir' => $newpub->host,
'-p', $oldpub->port, '--old-port' => $oldpub->port,
'-P', $newpub->port, '--new-port' => $newpub->port,
$mode); $mode);
# In a VPATH build, we'll be started in the source directory, but we want # In a VPATH build, we'll be started in the source directory, but we want

View File

@ -31,7 +31,12 @@ command_like(
# Set the old cluster's default char signedness to unsigned for test. # Set the old cluster's default char signedness to unsigned for test.
command_ok( command_ok(
[ 'pg_resetwal', '--char-signedness', 'unsigned', '-f', $old->data_dir ], [
'pg_resetwal',
'--char-signedness' => 'unsigned',
'--force',
$old->data_dir
],
"set old cluster's default char signedness to unsigned"); "set old cluster's default char signedness to unsigned");
# Check if the value is successfully updated. # Check if the value is successfully updated.
@ -44,14 +49,14 @@ command_like(
command_checks_all( command_checks_all(
[ [
'pg_upgrade', '--no-sync', 'pg_upgrade', '--no-sync',
'-d', $old->data_dir, '--old-datadir' => $old->data_dir,
'-D', $new->data_dir, '--new-datadir' => $new->data_dir,
'-b', $old->config_data('--bindir'), '--old-bindir' => $old->config_data('--bindir'),
'-B', $new->config_data('--bindir'), '--new-bindir' => $new->config_data('--bindir'),
'-s', $new->host, '--socketdir' => $new->host,
'-p', $old->port, '--old-port' => $old->port,
'-P', $new->port, '--new-port' => $new->port,
'--set-char-signedness', 'signed', '--set-char-signedness' => 'signed',
$mode $mode
], ],
1, 1,
@ -64,13 +69,13 @@ command_checks_all(
command_ok( command_ok(
[ [
'pg_upgrade', '--no-sync', 'pg_upgrade', '--no-sync',
'-d', $old->data_dir, '--old-datadir' => $old->data_dir,
'-D', $new->data_dir, '--new-datadir' => $new->data_dir,
'-b', $old->config_data('--bindir'), '--old-bindir' => $old->config_data('--bindir'),
'-B', $new->config_data('--bindir'), '--new-bindir' => $new->config_data('--bindir'),
'-s', $new->host, '--socketdir' => $new->host,
'-p', $old->port, '--old-port' => $old->port,
'-P', $new->port, '--new-port' => $new->port,
$mode $mode
], ],
'run of pg_upgrade'); 'run of pg_upgrade');

View File

@ -19,18 +19,21 @@ sub test_checksums
my ($format, $algorithm) = @_; my ($format, $algorithm) = @_;
my $backup_path = $primary->backup_dir . '/' . $format . '/' . $algorithm; my $backup_path = $primary->backup_dir . '/' . $format . '/' . $algorithm;
my @backup = ( my @backup = (
'pg_basebackup', '-D', $backup_path, 'pg_basebackup',
'--manifest-checksums', $algorithm, '--no-sync', '-cfast'); '--pgdata' => $backup_path,
my @verify = ('pg_verifybackup', '-e', $backup_path); '--manifest-checksums' => $algorithm,
'--no-sync',
'--checkpoint' => 'fast');
my @verify = ('pg_verifybackup', '--exit-on-error', $backup_path);
if ($format eq 'tar') if ($format eq 'tar')
{ {
# Add switch to get a tar-format backup # Add switch to get a tar-format backup
push @backup, ('-F', 't'); push @backup, ('--format' => 'tar');
# Add switch to skip WAL verification, which is not yet supported for # Add switch to skip WAL verification, which is not yet supported for
# tar-format backups # tar-format backups
push @verify, ('-n'); push @verify, ('--no-parse-wal');
} }
# A backup with a bogus algorithm should fail. # A backup with a bogus algorithm should fail.

View File

@ -190,13 +190,13 @@ for my $scenario (@scenario)
# Construct base.tar with what's left. # Construct base.tar with what's left.
chdir($backup_path) || die "chdir: $!"; chdir($backup_path) || die "chdir: $!";
command_ok([ $tar, '-cf', "$tar_backup_path/base.tar", '.' ]); command_ok([ $tar, '-cf' => "$tar_backup_path/base.tar", '.' ]);
chdir($cwd) || die "chdir: $!"; chdir($cwd) || die "chdir: $!";
# Now check that the backup no longer verifies. We must use -n # Now check that the backup no longer verifies. We must use -n
# here, because pg_waldump can't yet read WAL from a tarfile. # here, because pg_waldump can't yet read WAL from a tarfile.
command_fails_like( command_fails_like(
[ 'pg_verifybackup', '-n', $tar_backup_path ], [ 'pg_verifybackup', '--no-parse-wal', $tar_backup_path ],
$scenario->{'fails_like'}, $scenario->{'fails_like'},
"corrupt backup fails verification: $name"); "corrupt backup fails verification: $name");

View File

@ -119,7 +119,8 @@ command_like(
# Verify that when --ignore is not used, both problems are reported. # Verify that when --ignore is not used, both problems are reported.
$result = IPC::Run::run [ 'pg_verifybackup', $backup_path ], $result = IPC::Run::run [ 'pg_verifybackup', $backup_path ],
'>', \$stdout, '2>', \$stderr; '>' => \$stdout,
'2>' => \$stderr;
ok(!$result, "multiple problems: fails"); ok(!$result, "multiple problems: fails");
like( like(
$stderr, $stderr,

View File

@ -79,12 +79,14 @@ for my $tc (@test_configuration)
|| $tc->{'decompress_program'} eq ''); || $tc->{'decompress_program'} eq '');
# Take a server-side backup. # Take a server-side backup.
my @backup = ( $primary->command_ok(
'pg_basebackup', '--no-sync', [
'-cfast', '--target', 'pg_basebackup', '--no-sync',
"server:$backup_path", '-Xfetch'); '--checkpoint' => 'fast',
push @backup, @{ $tc->{'backup_flags'} }; '--target' => "server:$backup_path",
$primary->command_ok(\@backup, '--wal-method' => 'fetch',
@{ $tc->{'backup_flags'} },
],
"server side backup, compression $method"); "server side backup, compression $method");
@ -97,7 +99,11 @@ for my $tc (@test_configuration)
"found expected backup files, compression $method"); "found expected backup files, compression $method");
# Verify tar backup. # Verify tar backup.
$primary->command_ok([ 'pg_verifybackup', '-n', '-e', $backup_path ], $primary->command_ok(
[
'pg_verifybackup', '--no-parse-wal',
'--exit-on-error', $backup_path,
],
"verify backup, compression $method"); "verify backup, compression $method");
# Cleanup. # Cleanup.

View File

@ -53,19 +53,21 @@ for my $tc (@test_configuration)
skip "$method compression not supported by this build", 2 skip "$method compression not supported by this build", 2
if !$tc->{'enabled'}; if !$tc->{'enabled'};
# Take backup with server compression enabled.
my @backup = (
'pg_basebackup', '-D', $backup_path,
'-Xfetch', '--no-sync', '-cfast', '-Fp');
push @backup, @{ $tc->{'backup_flags'} };
my @verify = ('pg_verifybackup', '-e', $backup_path);
# A backup with a valid compression method should work. # A backup with a valid compression method should work.
my $backup_stdout = ''; my $backup_stdout = '';
my $backup_stderr = ''; my $backup_stderr = '';
my $backup_result = $primary->run_log(\@backup, '>', \$backup_stdout, my $backup_result = $primary->run_log(
'2>', \$backup_stderr); [
'pg_basebackup',
'--pgdata' => $backup_path,
'--wal-method' => 'fetch',
'--no-sync',
'--checkpoint' => 'fast',
'--format' => 'plain',
@{ $tc->{'backup_flags'} },
],
'>' => \$backup_stdout,
'2>' => \$backup_stderr);
if ($backup_stdout ne '') if ($backup_stdout ne '')
{ {
print "# standard output was:\n$backup_stdout"; print "# standard output was:\n$backup_stdout";
@ -86,7 +88,8 @@ for my $tc (@test_configuration)
} }
# Make sure that it verifies OK. # Make sure that it verifies OK.
$primary->command_ok(\@verify, $primary->command_ok(
[ 'pg_verifybackup', '--exit-on-error', $backup_path ],
"backup verified, compression method \"$method\""); "backup verified, compression method \"$method\"");
} }

View File

@ -72,14 +72,19 @@ for my $tc (@test_configuration)
|| $tc->{'decompress_program'} eq ''); || $tc->{'decompress_program'} eq '');
# Take a client-side backup. # Take a client-side backup.
my @backup = (
'pg_basebackup', '-D', $backup_path,
'-Xfetch', '--no-sync', '-cfast', '-Ft');
push @backup, @{ $tc->{'backup_flags'} };
my $backup_stdout = ''; my $backup_stdout = '';
my $backup_stderr = ''; my $backup_stderr = '';
my $backup_result = $primary->run_log(\@backup, '>', \$backup_stdout, my $backup_result = $primary->run_log(
'2>', \$backup_stderr); [
'pg_basebackup', '--no-sync',
'--pgdata' => $backup_path,
'--wal-method' => 'fetch',
'--checkpoint' => 'fast',
'--format' => 'tar',
@{ $tc->{'backup_flags'} }
],
'>' => \$backup_stdout,
'2>' => \$backup_stderr);
if ($backup_stdout ne '') if ($backup_stdout ne '')
{ {
print "# standard output was:\n$backup_stdout"; print "# standard output was:\n$backup_stdout";

View File

@ -247,13 +247,15 @@ command_fails_like(
$lsn2++; $lsn2++;
my $new_start = sprintf("%s/%X", $part1, $lsn2); my $new_start = sprintf("%s/%X", $part1, $lsn2);
my (@cmd, $stdout, $stderr, $result); my ($stdout, $stderr);
@cmd = ( my $result = IPC::Run::run [
'pg_waldump', 'pg_waldump',
'--start' => $new_start, '--start' => $new_start,
$node->data_dir . '/pg_wal/' . $start_walfile); $node->data_dir . '/pg_wal/' . $start_walfile
$result = IPC::Run::run \@cmd, '>', \$stdout, '2>', \$stderr; ],
'>' => \$stdout,
'2>' => \$stderr;
ok($result, "runs with start segment and start LSN specified"); ok($result, "runs with start segment and start LSN specified");
like($stderr, qr/first record is after/, 'info message printed'); like($stderr, qr/first record is after/, 'info message printed');
} }
@ -266,18 +268,20 @@ sub test_pg_waldump
local $Test::Builder::Level = $Test::Builder::Level + 1; local $Test::Builder::Level = $Test::Builder::Level + 1;
my @opts = @_; my @opts = @_;
my (@cmd, $stdout, $stderr, $result, @lines); my ($stdout, $stderr);
@cmd = ( my $result = IPC::Run::run [
'pg_waldump', 'pg_waldump',
'--path' => $node->data_dir, '--path' => $node->data_dir,
'--start' => $start_lsn, '--start' => $start_lsn,
'--end' => $end_lsn); '--end' => $end_lsn,
push @cmd, @opts; @opts
$result = IPC::Run::run \@cmd, '>', \$stdout, '2>', \$stderr; ],
'>' => \$stdout,
'2>' => \$stderr;
ok($result, "pg_waldump @opts: runs ok"); ok($result, "pg_waldump @opts: runs ok");
is($stderr, '', "pg_waldump @opts: no stderr"); is($stderr, '', "pg_waldump @opts: no stderr");
@lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
ok(@lines > 0, "pg_waldump @opts: some lines are output"); ok(@lines > 0, "pg_waldump @opts: some lines are output");
return @lines; return @lines;
} }

View File

@ -213,7 +213,7 @@ my $nthreads = 2;
{ {
my ($stderr); my ($stderr);
run_log([ 'pgbench', '--jobs' => '2', '--bad-option' ], '2>', \$stderr); run_log([ 'pgbench', '--jobs' => '2', '--bad-option' ], '2>' => \$stderr);
$nthreads = 1 if $stderr =~ m/threads are not supported on this platform/; $nthreads = 1 if $stderr =~ m/threads are not supported on this platform/;
} }

View File

@ -50,7 +50,7 @@ sub pgbench_scripts
# cleanup from prior runs # cleanup from prior runs
unlink $filename; unlink $filename;
append_to_file($filename, $$files{$fn}); append_to_file($filename, $$files{$fn});
push @cmd, '-f', $filename; push @cmd, '--file' => $filename;
} }
} }
command_checks_all(\@cmd, $stat, $out, $err, $name); command_checks_all(\@cmd, $stat, $out, $err, $name);

View File

@ -52,8 +52,9 @@ foreach my $arg (qw(commands variables))
my ($stdout, $stderr); my ($stdout, $stderr);
my $result; my $result;
$result = IPC::Run::run [ 'psql', "--help=$arg" ], '>', \$stdout, '2>', $result = IPC::Run::run [ 'psql', "--help=$arg" ],
\$stderr; '>' => \$stdout,
'2>' => \$stderr;
ok($result, "psql --help=$arg exit code 0"); ok($result, "psql --help=$arg exit code 0");
isnt($stdout, '', "psql --help=$arg goes to stdout"); isnt($stdout, '', "psql --help=$arg goes to stdout");
is($stderr, '', "psql --help=$arg nothing to stderr"); is($stderr, '', "psql --help=$arg nothing to stderr");

View File

@ -22,8 +22,13 @@ $node->start;
local %ENV = $node->_get_env(); local %ENV = $node->_get_env();
my ($stdin, $stdout, $stderr); my ($stdin, $stdout, $stderr);
my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ], my $h = IPC::Run::start(
\$stdin, \$stdout, \$stderr); [
'psql', '--no-psqlrc', '--set' => 'ON_ERROR_STOP=1',
],
'<' => \$stdin,
'>' => \$stdout,
'2>' => \$stderr);
# Send sleep command and wait until the server has registered it # Send sleep command and wait until the server has registered it
$stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n"; $stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n";

View File

@ -268,8 +268,9 @@ sub test_uri
%ENV = (%ENV, %envvars); %ENV = (%ENV, %envvars);
my $cmd = [ 'libpq_uri_regress', $uri ]; my $cmd = [ 'libpq_uri_regress', $uri ];
$result{exit} = IPC::Run::run $cmd, '>', \$result{stdout}, '2>', $result{exit} = IPC::Run::run $cmd,
\$result{stderr}; '>' => \$result{stdout},
'2>' => \$result{stderr};
chomp($result{stdout}); chomp($result{stdout});
chomp($result{stderr}); chomp($result{stderr});

View File

@ -673,7 +673,9 @@ sub connect_test
my ($ret, $stdout, $stderr) = $node->psql( my ($ret, $stdout, $stderr) = $node->psql(
'postgres', 'postgres',
'', '',
extra_params => [ '-w', '-c', 'SELECT current_enc()' ], extra_params => [
'--no-password', '--command' => 'SELECT current_enc()',
],
connstr => "$connstr_full", connstr => "$connstr_full",
on_error_stop => 0); on_error_stop => 0);

View File

@ -57,7 +57,7 @@ $primary->restart;
$primary->append_conf('postgresql.conf', 'track_commit_timestamp = off'); $primary->append_conf('postgresql.conf', 'track_commit_timestamp = off');
$primary->restart; $primary->restart;
system_or_bail('pg_ctl', '-D', $standby->data_dir, 'promote'); system_or_bail('pg_ctl', '--pgdata' => $standby->data_dir, 'promote');
$standby->safe_psql('postgres', "create table t11()"); $standby->safe_psql('postgres', "create table t11()");
my $standby_ts = $standby->safe_psql('postgres', my $standby_ts = $standby->safe_psql('postgres',

View File

@ -35,7 +35,7 @@ mkdir "$PostgreSQL::Test::Utils::tmp_check/traces";
for my $testname (@tests) for my $testname (@tests)
{ {
my @extraargs = ('-r', $numrows); my @extraargs = ('-r' => $numrows);
my $cmptrace = grep(/^$testname$/, my $cmptrace = grep(/^$testname$/,
qw(simple_pipeline nosync multi_pipelines prepared singlerow qw(simple_pipeline nosync multi_pipelines prepared singlerow
pipeline_abort pipeline_idle transaction pipeline_abort pipeline_idle transaction
@ -46,7 +46,7 @@ for my $testname (@tests)
"$PostgreSQL::Test::Utils::tmp_check/traces/$testname.trace"; "$PostgreSQL::Test::Utils::tmp_check/traces/$testname.trace";
if ($cmptrace) if ($cmptrace)
{ {
push @extraargs, "-t", $traceout; push @extraargs, "-t" => $traceout;
} }
# Execute the test # Execute the test

View File

@ -62,9 +62,11 @@ like(
$node->append_conf('postgresql.conf', "ssl_passphrase.passphrase = 'blurfl'"); $node->append_conf('postgresql.conf', "ssl_passphrase.passphrase = 'blurfl'");
# try to start the server again # try to start the server again
my $ret = my $ret = PostgreSQL::Test::Utils::system_log(
PostgreSQL::Test::Utils::system_log('pg_ctl', '-D', $node->data_dir, '-l', 'pg_ctl',
$node->logfile, 'start'); '--pgdata' => $node->data_dir,
'--log' => $node->logfile,
'start');
# with a bad passphrase the server should not start # with a bad passphrase the server should not start

View File

@ -47,131 +47,149 @@ my %pgdump_runs = (
binary_upgrade => { binary_upgrade => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/binary_upgrade.sql", '--schema-only', '--file' => "$tempdir/binary_upgrade.sql",
'--binary-upgrade', '--dbname=postgres', '--schema-only', '--binary-upgrade',
'--dbname' => 'postgres',
], ],
}, },
clean => { clean => {
dump_cmd => [ dump_cmd => [
'pg_dump', "--file=$tempdir/clean.sql", 'pg_dump', '--no-sync',
'-c', '--no-sync', '--file' => "$tempdir/clean.sql",
'--dbname=postgres', '--clean',
'--dbname' => 'postgres',
], ],
}, },
clean_if_exists => { clean_if_exists => {
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump', '--no-sync',
'--no-sync', '--file' => "$tempdir/clean_if_exists.sql",
"--file=$tempdir/clean_if_exists.sql", '--clean',
'-c',
'--if-exists', '--if-exists',
'--encoding=UTF8', # no-op, just tests that option is accepted '--encoding' => 'UTF8', # no-op, just tests that it is accepted
'postgres', 'postgres',
], ],
}, },
createdb => { createdb => {
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump', '--no-sync',
'--no-sync', '--file' => "$tempdir/createdb.sql",
"--file=$tempdir/createdb.sql", '--create',
'-C', '--no-reconnect', # no-op, just for testing
'-R', # no-op, just for testing
'postgres', 'postgres',
], ],
}, },
data_only => { data_only => {
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump', '--no-sync',
'--no-sync', '--file' => "$tempdir/data_only.sql",
"--file=$tempdir/data_only.sql", '--data-only',
'-a', '--verbose', # no-op, just make sure it works
'-v', # no-op, just make sure it works
'postgres', 'postgres',
], ],
}, },
defaults => { defaults => {
dump_cmd => [ 'pg_dump', '-f', "$tempdir/defaults.sql", 'postgres', ], dump_cmd => [
'pg_dump',
'--file' => "$tempdir/defaults.sql",
'postgres',
],
}, },
defaults_custom_format => { defaults_custom_format => {
test_key => 'defaults', test_key => 'defaults',
compile_option => 'gzip', compile_option => 'gzip',
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', '-Fc', '-Z6', 'pg_dump', '--no-sync',
"--file=$tempdir/defaults_custom_format.dump", 'postgres', '--format' => 'custom',
'--compress' => 6,
'--file' => "$tempdir/defaults_custom_format.dump",
'postgres',
], ],
restore_cmd => [ restore_cmd => [
'pg_restore', 'pg_restore',
"--file=$tempdir/defaults_custom_format.sql", '--file' => "$tempdir/defaults_custom_format.sql",
"$tempdir/defaults_custom_format.dump", "$tempdir/defaults_custom_format.dump",
], ],
}, },
defaults_dir_format => { defaults_dir_format => {
test_key => 'defaults', test_key => 'defaults',
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', '-Fd', 'pg_dump', '--no-sync',
"--file=$tempdir/defaults_dir_format", 'postgres', '--format' => 'directory',
'--file' => "$tempdir/defaults_dir_format",
'postgres',
], ],
restore_cmd => [ restore_cmd => [
'pg_restore', 'pg_restore',
"--file=$tempdir/defaults_dir_format.sql", '--file' => "$tempdir/defaults_dir_format.sql",
"$tempdir/defaults_dir_format", "$tempdir/defaults_dir_format",
], ],
}, },
defaults_parallel => { defaults_parallel => {
test_key => 'defaults', test_key => 'defaults',
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', '-Fd', '-j2', 'pg_dump', '--no-sync',
"--file=$tempdir/defaults_parallel", 'postgres', '--format' => 'directory',
'--jobs' => 2,
'--file' => "$tempdir/defaults_parallel",
'postgres',
], ],
restore_cmd => [ restore_cmd => [
'pg_restore', 'pg_restore',
"--file=$tempdir/defaults_parallel.sql", '--file' => "$tempdir/defaults_parallel.sql",
"$tempdir/defaults_parallel", "$tempdir/defaults_parallel",
], ],
}, },
defaults_tar_format => { defaults_tar_format => {
test_key => 'defaults', test_key => 'defaults',
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', '-Ft', 'pg_dump', '--no-sync',
"--file=$tempdir/defaults_tar_format.tar", 'postgres', '--format' => 'tar',
'--file' => "$tempdir/defaults_tar_format.tar",
'postgres',
], ],
restore_cmd => [ restore_cmd => [
'pg_restore', 'pg_restore',
"--file=$tempdir/defaults_tar_format.sql", '--file' => "$tempdir/defaults_tar_format.sql",
"$tempdir/defaults_tar_format.tar", "$tempdir/defaults_tar_format.tar",
], ],
}, },
exclude_table => { exclude_table => {
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump',
'--exclude-table=regress_table_dumpable', '--exclude-table' => 'regress_table_dumpable',
"--file=$tempdir/exclude_table.sql", '--file' => "$tempdir/exclude_table.sql",
'postgres', 'postgres',
], ],
}, },
extension_schema => { extension_schema => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--schema=public', 'pg_dump',
"--file=$tempdir/extension_schema.sql", 'postgres', '--schema' => 'public',
'--file' => "$tempdir/extension_schema.sql",
'postgres',
], ],
}, },
pg_dumpall_globals => { pg_dumpall_globals => {
dump_cmd => [ dump_cmd => [
'pg_dumpall', '--no-sync', 'pg_dumpall', '--no-sync',
"--file=$tempdir/pg_dumpall_globals.sql", '-g', '--file' => "$tempdir/pg_dumpall_globals.sql",
'--globals-only',
], ],
}, },
no_privs => { no_privs => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/no_privs.sql", '-x', '--file' => "$tempdir/no_privs.sql",
'--no-privileges',
'postgres', 'postgres',
], ],
}, },
no_owner => { no_owner => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/no_owner.sql", '-O', '--file' => "$tempdir/no_owner.sql",
'--no-owner',
'postgres', 'postgres',
], ],
}, },
@ -181,59 +199,68 @@ my %pgdump_runs = (
privileged_internals => { privileged_internals => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/privileged_internals.sql", '--file' => "$tempdir/privileged_internals.sql",
# these two tables are irrelevant to the test case # these two tables are irrelevant to the test case
'--exclude-table=regress_pg_dump_schema.external_tab', '--exclude-table' => 'regress_pg_dump_schema.external_tab',
'--exclude-table=regress_pg_dump_schema.extdependtab', '--exclude-table' => 'regress_pg_dump_schema.extdependtab',
'--username=regress_dump_login_role', 'postgres', '--username' => 'regress_dump_login_role',
'postgres',
], ],
}, },
schema_only => { schema_only => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', "--file=$tempdir/schema_only.sql", 'pg_dump', '--no-sync',
'-s', 'postgres', '--file' => "$tempdir/schema_only.sql",
'--schema-only', 'postgres',
], ],
}, },
section_pre_data => { section_pre_data => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/section_pre_data.sql", '--section=pre-data', '--file' => "$tempdir/section_pre_data.sql",
'--section' => 'pre-data',
'postgres', 'postgres',
], ],
}, },
section_data => { section_data => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/section_data.sql", '--section=data', '--file' => "$tempdir/section_data.sql",
'--section' => 'data',
'postgres', 'postgres',
], ],
}, },
section_post_data => { section_post_data => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', "--file=$tempdir/section_post_data.sql", 'pg_dump', '--no-sync',
'--section=post-data', 'postgres', '--file' => "$tempdir/section_post_data.sql",
'--section' => 'post-data',
'postgres',
], ],
}, },
with_extension => { with_extension => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', "--file=$tempdir/with_extension.sql", 'pg_dump', '--no-sync',
'--extension=test_pg_dump', 'postgres', '--file' => "$tempdir/with_extension.sql",
'--extension' => 'test_pg_dump',
'postgres',
], ],
}, },
exclude_extension => { exclude_extension => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', 'pg_dump', '--no-sync',
"--file=$tempdir/exclude_extension.sql", '--file' => "$tempdir/exclude_extension.sql",
'--exclude-extension=test_pg_dump', 'postgres', '--exclude-extension' => 'test_pg_dump',
'postgres',
], ],
}, },
exclude_extension_filter => { exclude_extension_filter => {
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump',
'--no-sync', '--no-sync',
"--file=$tempdir/exclude_extension_filter.sql", '--file' => "$tempdir/exclude_extension_filter.sql",
"--filter=$tempdir/exclude_extension_filter.txt", '--filter' => "$tempdir/exclude_extension_filter.txt",
'postgres', 'postgres',
], ],
}, },
@ -241,8 +268,10 @@ my %pgdump_runs = (
# plpgsql in the list blocks the dump of extension test_pg_dump # plpgsql in the list blocks the dump of extension test_pg_dump
without_extension => { without_extension => {
dump_cmd => [ dump_cmd => [
'pg_dump', '--no-sync', "--file=$tempdir/without_extension.sql", 'pg_dump', '--no-sync',
'--extension=plpgsql', 'postgres', '--file' => "$tempdir/without_extension.sql",
'--extension' => 'plpgsql',
'postgres',
], ],
}, },
@ -253,9 +282,9 @@ my %pgdump_runs = (
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump',
'--no-sync', '--no-sync',
"--file=$tempdir/without_extension_explicit_schema.sql", '--file' => "$tempdir/without_extension_explicit_schema.sql",
'--extension=plpgsql', '--extension' => 'plpgsql',
'--schema=public', '--schema' => 'public',
'postgres', 'postgres',
], ],
}, },
@ -267,9 +296,9 @@ my %pgdump_runs = (
dump_cmd => [ dump_cmd => [
'pg_dump', 'pg_dump',
'--no-sync', '--no-sync',
"--file=$tempdir/without_extension_internal_schema.sql", '--file' => "$tempdir/without_extension_internal_schema.sql",
'--extension=plpgsql', '--extension' => 'plpgsql',
'--schema=regress_pg_dump_schema', '--schema' => 'regress_pg_dump_schema',
'postgres', 'postgres',
], ],
},); },);
@ -840,7 +869,7 @@ my %tests = (
# Create a PG instance to test actually dumping from # Create a PG instance to test actually dumping from
my $node = PostgreSQL::Test::Cluster->new('main'); my $node = PostgreSQL::Test::Cluster->new('main');
$node->init('auth_extra' => [ '--create-role', 'regress_dump_login_role' ]); $node->init('auth_extra' => [ '--create-role' => 'regress_dump_login_role' ]);
$node->start; $node->start;
my $port = $node->port; my $port = $node->port;

View File

@ -108,14 +108,17 @@ sub new
if ($interactive) if ($interactive)
{ {
$run = IPC::Run::start $psql_params, $run = IPC::Run::start $psql_params,
'<pty<', \$psql->{stdin}, '>pty>', \$psql->{stdout}, '2>', '<pty<' => \$psql->{stdin},
\$psql->{stderr}, '>pty>' => \$psql->{stdout},
'2>' => \$psql->{stderr},
$psql->{timeout}; $psql->{timeout};
} }
else else
{ {
$run = IPC::Run::start $psql_params, $run = IPC::Run::start $psql_params,
'<', \$psql->{stdin}, '>', \$psql->{stdout}, '2>', \$psql->{stderr}, '<' => \$psql->{stdin},
'>' => \$psql->{stdout},
'2>' => \$psql->{stderr},
$psql->{timeout}; $psql->{timeout};
} }

View File

@ -640,8 +640,11 @@ sub init
or !defined $ENV{INITDB_TEMPLATE}) or !defined $ENV{INITDB_TEMPLATE})
{ {
note("initializing database system by running initdb"); note("initializing database system by running initdb");
PostgreSQL::Test::Utils::system_or_bail('initdb', '-D', $pgdata, '-A', PostgreSQL::Test::Utils::system_or_bail(
'trust', '-N', @{ $params{extra} }); 'initdb', '--no-sync',
'--pgdata' => $pgdata,
'--auth' => 'trust',
@{ $params{extra} });
} }
else else
{ {
@ -838,11 +841,11 @@ sub backup
print "# Taking pg_basebackup $backup_name from node \"$name\"\n"; print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
PostgreSQL::Test::Utils::system_or_bail( PostgreSQL::Test::Utils::system_or_bail(
'pg_basebackup', '-D', 'pg_basebackup', '--no-sync',
$backup_path, '-h', '--pgdata' => $backup_path,
$self->host, '-p', '--host' => $self->host,
$self->port, '--checkpoint', '--port' => $self->port,
'fast', '--no-sync', '--checkpoint' => 'fast',
@{ $params{backup_options} }); @{ $params{backup_options} });
print "# Backup finished\n"; print "# Backup finished\n";
return; return;
@ -946,7 +949,7 @@ sub init_from_backup
} }
local %ENV = $self->_get_env(); local %ENV = $self->_get_env();
my @combineargs = ('pg_combinebackup', '-d'); my @combineargs = ('pg_combinebackup', '--debug');
if (exists $params{tablespace_map}) if (exists $params{tablespace_map})
{ {
while (my ($olddir, $newdir) = each %{ $params{tablespace_map} }) while (my ($olddir, $newdir) = each %{ $params{tablespace_map} })
@ -959,19 +962,21 @@ sub init_from_backup
{ {
push @combineargs, $params{combine_mode}; push @combineargs, $params{combine_mode};
} }
push @combineargs, @prior_backup_path, $backup_path, '-o', $data_path; push @combineargs, @prior_backup_path, $backup_path,
'--output' => $data_path;
PostgreSQL::Test::Utils::system_or_bail(@combineargs); PostgreSQL::Test::Utils::system_or_bail(@combineargs);
} }
elsif (defined $params{tar_program}) elsif (defined $params{tar_program})
{ {
mkdir($data_path) || die "mkdir $data_path: $!"; mkdir($data_path) || die "mkdir $data_path: $!";
PostgreSQL::Test::Utils::system_or_bail($params{tar_program}, 'xf',
$backup_path . '/base.tar',
'-C', $data_path);
PostgreSQL::Test::Utils::system_or_bail( PostgreSQL::Test::Utils::system_or_bail(
$params{tar_program}, 'xf', $params{tar_program},
$backup_path . '/pg_wal.tar', '-C', 'xf' => $backup_path . '/base.tar',
$data_path . '/pg_wal'); '-C' => $data_path);
PostgreSQL::Test::Utils::system_or_bail(
$params{tar_program},
'xf' => $backup_path . '/pg_wal.tar',
'-C' => $data_path . '/pg_wal');
# We need to generate a tablespace_map file. # We need to generate a tablespace_map file.
open(my $tsmap, ">", "$data_path/tablespace_map") open(my $tsmap, ">", "$data_path/tablespace_map")
@ -991,9 +996,10 @@ sub init_from_backup
my $newdir = $params{tablespace_map}{$tsoid}; my $newdir = $params{tablespace_map}{$tsoid};
mkdir($newdir) || die "mkdir $newdir: $!"; mkdir($newdir) || die "mkdir $newdir: $!";
PostgreSQL::Test::Utils::system_or_bail($params{tar_program}, PostgreSQL::Test::Utils::system_or_bail(
'xf', $backup_path . '/' . $tstar, $params{tar_program},
'-C', $newdir); 'xf' => $backup_path . '/' . $tstar,
'-C' => $newdir);
my $escaped_newdir = $newdir; my $escaped_newdir = $newdir;
$escaped_newdir =~ s/\\/\\\\/g; $escaped_newdir =~ s/\\/\\\\/g;
@ -1133,8 +1139,10 @@ sub start
# -w is now the default but having it here does no harm and helps # -w is now the default but having it here does no harm and helps
# compatibility with older versions. # compatibility with older versions.
$ret = PostgreSQL::Test::Utils::system_log( $ret = PostgreSQL::Test::Utils::system_log(
'pg_ctl', '-w', '-D', $self->data_dir, 'pg_ctl', '--wait',
'-l', $self->logfile, '-o', "--cluster-name=$name", '--pgdata' => $self->data_dir,
'--log' => $self->logfile,
'--options' => "--cluster-name=$name",
'start'); 'start');
if ($ret != 0) if ($ret != 0)
@ -1211,10 +1219,10 @@ sub stop
return 1 unless defined $self->{_pid}; return 1 unless defined $self->{_pid};
print "### Stopping node \"$name\" using mode $mode\n"; print "### Stopping node \"$name\" using mode $mode\n";
my @cmd = ('pg_ctl', '-D', $pgdata, '-m', $mode, 'stop'); my @cmd = ('pg_ctl', '--pgdata' => $pgdata, '--mode' => $mode, 'stop');
if ($params{timeout}) if ($params{timeout})
{ {
push(@cmd, ('--timeout', $params{timeout})); push(@cmd, ('--timeout' => $params{timeout}));
} }
$ret = PostgreSQL::Test::Utils::system_log(@cmd); $ret = PostgreSQL::Test::Utils::system_log(@cmd);
@ -1251,7 +1259,9 @@ sub reload
local %ENV = $self->_get_env(); local %ENV = $self->_get_env();
print "### Reloading node \"$name\"\n"; print "### Reloading node \"$name\"\n";
PostgreSQL::Test::Utils::system_or_bail('pg_ctl', '-D', $pgdata, PostgreSQL::Test::Utils::system_or_bail(
'pg_ctl',
'--pgdata' => $pgdata,
'reload'); 'reload');
return; return;
} }
@ -1279,8 +1289,11 @@ sub restart
# -w is now the default but having it here does no harm and helps # -w is now the default but having it here does no harm and helps
# compatibility with older versions. # compatibility with older versions.
$ret = PostgreSQL::Test::Utils::system_log('pg_ctl', '-w', '-D', $ret = PostgreSQL::Test::Utils::system_log(
$self->data_dir, '-l', $self->logfile, 'restart'); 'pg_ctl', '--wait',
'--pgdata' => $self->data_dir,
'--log' => $self->logfile,
'restart');
if ($ret != 0) if ($ret != 0)
{ {
@ -1318,8 +1331,11 @@ sub promote
local %ENV = $self->_get_env(); local %ENV = $self->_get_env();
print "### Promoting node \"$name\"\n"; print "### Promoting node \"$name\"\n";
PostgreSQL::Test::Utils::system_or_bail('pg_ctl', '-D', $pgdata, '-l', PostgreSQL::Test::Utils::system_or_bail(
$logfile, 'promote'); 'pg_ctl',
'--pgdata' => $pgdata,
'--log' => $logfile,
'promote');
return; return;
} }
@ -1342,8 +1358,11 @@ sub logrotate
local %ENV = $self->_get_env(); local %ENV = $self->_get_env();
print "### Rotating log in node \"$name\"\n"; print "### Rotating log in node \"$name\"\n";
PostgreSQL::Test::Utils::system_or_bail('pg_ctl', '-D', $pgdata, '-l', PostgreSQL::Test::Utils::system_or_bail(
$logfile, 'logrotate'); 'pg_ctl',
'--pgdata' => $pgdata,
'--log' => $logfile,
'logrotate');
return; return;
} }
@ -2120,7 +2139,9 @@ sub psql
my @psql_params = ( my @psql_params = (
$self->installed_command('psql'), $self->installed_command('psql'),
'-XAtq', '-d', $psql_connstr, '-f', '-'); '--no-psqlrc', '--no-align', '--tuples-only', '--quiet',
'--dbname' => $psql_connstr,
'--file' => '-');
# If the caller wants an array and hasn't passed stdout/stderr # If the caller wants an array and hasn't passed stdout/stderr
# references, allocate temporary ones to capture them so we # references, allocate temporary ones to capture them so we
@ -2142,7 +2163,8 @@ sub psql
$params{on_error_stop} = 1 unless defined $params{on_error_stop}; $params{on_error_stop} = 1 unless defined $params{on_error_stop};
$params{on_error_die} = 0 unless defined $params{on_error_die}; $params{on_error_die} = 0 unless defined $params{on_error_die};
push @psql_params, '-v', 'ON_ERROR_STOP=1' if $params{on_error_stop}; push @psql_params, '--variable' => 'ON_ERROR_STOP=1'
if $params{on_error_stop};
push @psql_params, @{ $params{extra_params} } push @psql_params, @{ $params{extra_params} }
if defined $params{extra_params}; if defined $params{extra_params};
@ -2168,9 +2190,9 @@ sub psql
{ {
local $@; local $@;
eval { eval {
my @ipcrun_opts = (\@psql_params, '<', \$sql); my @ipcrun_opts = (\@psql_params, '<' => \$sql);
push @ipcrun_opts, '>', $stdout if defined $stdout; push @ipcrun_opts, '>' => $stdout if defined $stdout;
push @ipcrun_opts, '2>', $stderr if defined $stderr; push @ipcrun_opts, '2>' => $stderr if defined $stderr;
push @ipcrun_opts, $timeout if defined $timeout; push @ipcrun_opts, $timeout if defined $timeout;
IPC::Run::run @ipcrun_opts; IPC::Run::run @ipcrun_opts;
@ -2325,13 +2347,16 @@ sub background_psql
my @psql_params = ( my @psql_params = (
$self->installed_command('psql'), $self->installed_command('psql'),
'-XAtq', '-d', $psql_connstr, '-f', '-'); '--no-psqlrc', '--no-align',
'--tuples-only', '--quiet',
'--dbname' => $psql_connstr,
'--file' => '-');
$params{on_error_stop} = 1 unless defined $params{on_error_stop}; $params{on_error_stop} = 1 unless defined $params{on_error_stop};
$params{wait} = 1 unless defined $params{wait}; $params{wait} = 1 unless defined $params{wait};
$timeout = $params{timeout} if defined $params{timeout}; $timeout = $params{timeout} if defined $params{timeout};
push @psql_params, '-v', 'ON_ERROR_STOP=1' if $params{on_error_stop}; push @psql_params, '--set' => 'ON_ERROR_STOP=1' if $params{on_error_stop};
push @psql_params, @{ $params{extra_params} } push @psql_params, @{ $params{extra_params} }
if defined $params{extra_params}; if defined $params{extra_params};
@ -2402,7 +2427,8 @@ sub interactive_psql
my @psql_params = ( my @psql_params = (
$self->installed_command('psql'), $self->installed_command('psql'),
'-XAt', '-d', $self->connstr($dbname)); '--no-psqlrc', '--no-align', '--tuples-only',
'--dbname' => $self->connstr($dbname));
push @psql_params, @{ $params{extra_params} } push @psql_params, @{ $params{extra_params} }
if defined $params{extra_params}; if defined $params{extra_params};
@ -2424,7 +2450,7 @@ sub _pgbench_make_files
for my $fn (sort keys %$files) for my $fn (sort keys %$files)
{ {
my $filename = $self->basedir . '/' . $fn; my $filename = $self->basedir . '/' . $fn;
push @file_opts, '-f', $filename; push @file_opts, '--file' => $filename;
# cleanup file weight # cleanup file weight
$filename =~ s/\@\d+$//; $filename =~ s/\@\d+$//;
@ -2650,8 +2676,9 @@ sub poll_query_until
$expected = 't' unless defined($expected); # default value $expected = 't' unless defined($expected); # default value
my $cmd = [ my $cmd = [
$self->installed_command('psql'), '-XAt', $self->installed_command('psql'), '--no-psqlrc',
'-d', $self->connstr($dbname) '--no-align', '--tuples-only',
'--dbname' => $self->connstr($dbname)
]; ];
my ($stdout, $stderr); my ($stdout, $stderr);
my $max_attempts = 10 * $PostgreSQL::Test::Utils::timeout_default; my $max_attempts = 10 * $PostgreSQL::Test::Utils::timeout_default;
@ -2659,8 +2686,10 @@ sub poll_query_until
while ($attempts < $max_attempts) while ($attempts < $max_attempts)
{ {
my $result = IPC::Run::run $cmd, '<', \$query, my $result = IPC::Run::run $cmd,
'>', \$stdout, '2>', \$stderr; '<' => \$query,
'>' => \$stdout,
'2>' => \$stderr;
chomp($stdout); chomp($stdout);
chomp($stderr); chomp($stderr);
@ -3534,15 +3563,17 @@ sub pg_recvlogical_upto
my @cmd = ( my @cmd = (
$self->installed_command('pg_recvlogical'), $self->installed_command('pg_recvlogical'),
'-S', $slot_name, '--dbname', $self->connstr($dbname)); '--slot' => $slot_name,
push @cmd, '--endpos', $endpos; '--dbname' => $self->connstr($dbname),
push @cmd, '-f', '-', '--no-loop', '--start'; '--endpos' => $endpos,
'--file' => '-',
'--no-loop', '--start');
while (my ($k, $v) = each %plugin_options) while (my ($k, $v) = each %plugin_options)
{ {
croak "= is not permitted to appear in replication option name" croak "= is not permitted to appear in replication option name"
if ($k =~ qr/=/); if ($k =~ qr/=/);
push @cmd, "-o", "$k=$v"; push @cmd, "--option" => "$k=$v";
} }
my $timeout; my $timeout;
@ -3555,7 +3586,7 @@ sub pg_recvlogical_upto
{ {
local $@; local $@;
eval { eval {
IPC::Run::run(\@cmd, ">", \$stdout, "2>", \$stderr, $timeout); IPC::Run::run(\@cmd, '>' => \$stdout, '2>' => \$stderr, $timeout);
$ret = $?; $ret = $?;
}; };
my $exc_save = $@; my $exc_save = $@;
@ -3669,15 +3700,14 @@ sub create_logical_slot_on_standby
$handle = IPC::Run::start( $handle = IPC::Run::start(
[ [
'pg_recvlogical', '-d', 'pg_recvlogical',
$self->connstr($dbname), '-P', '--dbname' => $self->connstr($dbname),
'test_decoding', '-S', '--plugin' => 'test_decoding',
$slot_name, '--create-slot' '--slot' => $slot_name,
'--create-slot'
], ],
'>', '>' => \$stdout,
\$stdout, '2>' => \$stderr);
'2>',
\$stderr);
# Arrange for the xl_running_xacts record for which pg_recvlogical is # Arrange for the xl_running_xacts record for which pg_recvlogical is
# waiting. # waiting.

View File

@ -104,7 +104,7 @@ sub new
my ($host, $hostaddr, $realm) = @_; my ($host, $hostaddr, $realm) = @_;
my ($stdout, $krb5_version); my ($stdout, $krb5_version);
run_log [ $krb5_config, '--version' ], '>', \$stdout run_log [ $krb5_config, '--version' ], '>' => \$stdout
or BAIL_OUT("could not execute krb5-config"); or BAIL_OUT("could not execute krb5-config");
BAIL_OUT("Heimdal is not supported") if $stdout =~ m/heimdal/; BAIL_OUT("Heimdal is not supported") if $stdout =~ m/heimdal/;
$stdout =~ m/Kerberos 5 release ([0-9]+\.[0-9]+)/ $stdout =~ m/Kerberos 5 release ([0-9]+\.[0-9]+)/

View File

@ -20,7 +20,7 @@ PostgreSQL::Test::Utils - helper module for writing PostgreSQL's C<prove> tests.
command_fails(['initdb', '--invalid-option'], command_fails(['initdb', '--invalid-option'],
'command fails with invalid option'); 'command fails with invalid option');
my $tempdir = PostgreSQL::Test::Utils::tempdir; my $tempdir = PostgreSQL::Test::Utils::tempdir;
command_ok('initdb', '-D', $tempdir); command_ok('initdb', '--pgdata' => $tempdir);
# Miscellanea # Miscellanea
print "on Windows" if $PostgreSQL::Test::Utils::windows_os; print "on Windows" if $PostgreSQL::Test::Utils::windows_os;
@ -333,7 +333,7 @@ sub has_wal_read_bug
return return
$Config{osname} eq 'linux' $Config{osname} eq 'linux'
&& $Config{archname} =~ /^sparc/ && $Config{archname} =~ /^sparc/
&& !run_log([ qw(df -x ext4), $tmp_check ], '>', '/dev/null', '2>&1'); && !run_log([ qw(df -x ext4), $tmp_check ], '&>' => '/dev/null');
} }
=pod =pod
@ -419,7 +419,7 @@ sub run_command
{ {
my ($cmd) = @_; my ($cmd) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr; my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr;
chomp($stdout); chomp($stdout);
chomp($stderr); chomp($stderr);
return ($stdout, $stderr); return ($stdout, $stderr);
@ -723,8 +723,9 @@ sub scan_server_header
my ($header_path, $regexp) = @_; my ($header_path, $regexp) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
my $result = IPC::Run::run [ 'pg_config', '--includedir-server' ], '>', my $result = IPC::Run::run [ 'pg_config', '--includedir-server' ],
\$stdout, '2>', \$stderr '>' => \$stdout,
'2>' => \$stderr
or die "could not execute pg_config"; or die "could not execute pg_config";
chomp($stdout); chomp($stdout);
$stdout =~ s/\r$//; $stdout =~ s/\r$//;
@ -761,8 +762,9 @@ sub check_pg_config
{ {
my ($regexp) = @_; my ($regexp) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
my $result = IPC::Run::run [ 'pg_config', '--includedir' ], '>', my $result = IPC::Run::run [ 'pg_config', '--includedir' ],
\$stdout, '2>', \$stderr '>' => \$stdout,
'2>' => \$stderr
or die "could not execute pg_config"; or die "could not execute pg_config";
chomp($stdout); chomp($stdout);
$stdout =~ s/\r$//; $stdout =~ s/\r$//;
@ -925,8 +927,9 @@ sub program_help_ok
my ($cmd) = @_; my ($cmd) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
print("# Running: $cmd --help\n"); print("# Running: $cmd --help\n");
my $result = IPC::Run::run [ $cmd, '--help' ], '>', \$stdout, '2>', my $result = IPC::Run::run [ $cmd, '--help' ],
\$stderr; '>' => \$stdout,
'2>' => \$stderr;
ok($result, "$cmd --help exit code 0"); ok($result, "$cmd --help exit code 0");
isnt($stdout, '', "$cmd --help goes to stdout"); isnt($stdout, '', "$cmd --help goes to stdout");
is($stderr, '', "$cmd --help nothing to stderr"); is($stderr, '', "$cmd --help nothing to stderr");
@ -956,8 +959,9 @@ sub program_version_ok
my ($cmd) = @_; my ($cmd) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
print("# Running: $cmd --version\n"); print("# Running: $cmd --version\n");
my $result = IPC::Run::run [ $cmd, '--version' ], '>', \$stdout, '2>', my $result = IPC::Run::run [ $cmd, '--version' ],
\$stderr; '>' => \$stdout,
'2>' => \$stderr;
ok($result, "$cmd --version exit code 0"); ok($result, "$cmd --version exit code 0");
isnt($stdout, '', "$cmd --version goes to stdout"); isnt($stdout, '', "$cmd --version goes to stdout");
is($stderr, '', "$cmd --version nothing to stderr"); is($stderr, '', "$cmd --version nothing to stderr");
@ -979,9 +983,9 @@ sub program_options_handling_ok
my ($cmd) = @_; my ($cmd) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
print("# Running: $cmd --not-a-valid-option\n"); print("# Running: $cmd --not-a-valid-option\n");
my $result = IPC::Run::run [ $cmd, '--not-a-valid-option' ], '>', my $result = IPC::Run::run [ $cmd, '--not-a-valid-option' ],
\$stdout, '>' => \$stdout,
'2>', \$stderr; '2>' => \$stderr;
ok(!$result, "$cmd with invalid option nonzero exit code"); ok(!$result, "$cmd with invalid option nonzero exit code");
isnt($stderr, '', "$cmd with invalid option prints error message"); isnt($stderr, '', "$cmd with invalid option prints error message");
return; return;
@ -1002,7 +1006,7 @@ sub command_like
my ($cmd, $expected_stdout, $test_name) = @_; my ($cmd, $expected_stdout, $test_name) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
print("# Running: " . join(" ", @{$cmd}) . "\n"); print("# Running: " . join(" ", @{$cmd}) . "\n");
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr; my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr;
ok($result, "$test_name: exit code 0"); ok($result, "$test_name: exit code 0");
is($stderr, '', "$test_name: no stderr"); is($stderr, '', "$test_name: no stderr");
like($stdout, $expected_stdout, "$test_name: matches"); like($stdout, $expected_stdout, "$test_name: matches");
@ -1031,7 +1035,7 @@ sub command_like_safe
my $stdoutfile = File::Temp->new(); my $stdoutfile = File::Temp->new();
my $stderrfile = File::Temp->new(); my $stderrfile = File::Temp->new();
print("# Running: " . join(" ", @{$cmd}) . "\n"); print("# Running: " . join(" ", @{$cmd}) . "\n");
my $result = IPC::Run::run $cmd, '>', $stdoutfile, '2>', $stderrfile; my $result = IPC::Run::run $cmd, '>' => $stdoutfile, '2>' => $stderrfile;
$stdout = slurp_file($stdoutfile); $stdout = slurp_file($stdoutfile);
$stderr = slurp_file($stderrfile); $stderr = slurp_file($stderrfile);
ok($result, "$test_name: exit code 0"); ok($result, "$test_name: exit code 0");
@ -1055,7 +1059,7 @@ sub command_fails_like
my ($cmd, $expected_stderr, $test_name) = @_; my ($cmd, $expected_stderr, $test_name) = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
print("# Running: " . join(" ", @{$cmd}) . "\n"); print("# Running: " . join(" ", @{$cmd}) . "\n");
my $result = IPC::Run::run $cmd, '>', \$stdout, '2>', \$stderr; my $result = IPC::Run::run $cmd, '>' => \$stdout, '2>' => \$stderr;
ok(!$result, "$test_name: exit code not 0"); ok(!$result, "$test_name: exit code not 0");
like($stderr, $expected_stderr, "$test_name: matches"); like($stderr, $expected_stderr, "$test_name: matches");
return; return;
@ -1093,7 +1097,7 @@ sub command_checks_all
# run command # run command
my ($stdout, $stderr); my ($stdout, $stderr);
print("# Running: " . join(" ", @{$cmd}) . "\n"); print("# Running: " . join(" ", @{$cmd}) . "\n");
IPC::Run::run($cmd, '>', \$stdout, '2>', \$stderr); IPC::Run::run($cmd, '>' => \$stdout, '2>' => \$stderr);
# See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR # See http://perldoc.perl.org/perlvar.html#%24CHILD_ERROR
my $ret = $?; my $ret = $?;

View File

@ -14,7 +14,8 @@ use Test::More;
my $node = PostgreSQL::Test::Cluster->new('primary'); my $node = PostgreSQL::Test::Cluster->new('primary');
$node->init( $node->init(
'auth_extra' => [ 'auth_extra' => [
'--create-role', 'regress_regular,regress_reserved,regress_superuser' '--create-role' =>
'regress_regular,regress_reserved,regress_superuser',
]); ]);
$node->append_conf('postgresql.conf', "max_connections = 6"); $node->append_conf('postgresql.conf', "max_connections = 6");
$node->append_conf('postgresql.conf', "reserved_connections = 2"); $node->append_conf('postgresql.conf', "reserved_connections = 2");
@ -43,7 +44,7 @@ sub background_psql_as_user
return $node->background_psql( return $node->background_psql(
'postgres', 'postgres',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-U', $user ]); extra_params => [ '--username' => $user ]);
} }
# Like connect_fails(), except that we also wait for the failed backend to # Like connect_fails(), except that we also wait for the failed backend to

View File

@ -14,7 +14,7 @@ my $node_primary = PostgreSQL::Test::Cluster->new('primary');
# and it needs proper authentication configuration. # and it needs proper authentication configuration.
$node_primary->init( $node_primary->init(
allows_streaming => 1, allows_streaming => 1,
auth_extra => [ '--create-role', 'repl_role' ]); auth_extra => [ '--create-role' => 'repl_role' ]);
$node_primary->start; $node_primary->start;
my $backup_name = 'my_backup'; my $backup_name = 'my_backup';
@ -146,9 +146,13 @@ sub test_target_session_attrs
# we connected to. Note we must pass the SQL command via the command # we connected to. Note we must pass the SQL command via the command
# line not stdin, else Perl may spit up trying to write to stdin of # line not stdin, else Perl may spit up trying to write to stdin of
# an already-failed psql process. # an already-failed psql process.
my ($ret, $stdout, $stderr) = my ($ret, $stdout, $stderr) = $node1->psql(
$node1->psql('postgres', undef, 'postgres',
extra_params => [ '-d', $connstr, '-c', 'SHOW port;' ]); undef,
extra_params => [
'--dbname' => $connstr,
'--command' => 'SHOW port;',
]);
if ($status == 0) if ($status == 0)
{ {
is( $status == $ret && $stdout eq $target_port, is( $status == $ret && $stdout eq $target_port,
@ -257,26 +261,26 @@ my $connstr_db = "$connstr_common replication=database dbname=postgres";
my ($ret, $stdout, $stderr) = $node_primary->psql( my ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'SHOW ALL;', 'postgres', 'SHOW ALL;',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
ok($ret == 0, "SHOW ALL with replication role and physical replication"); ok($ret == 0, "SHOW ALL with replication role and physical replication");
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'SHOW ALL;', 'postgres', 'SHOW ALL;',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-d', $connstr_db ]); extra_params => [ '--dbname' => $connstr_db ]);
ok($ret == 0, "SHOW ALL with replication role and logical replication"); ok($ret == 0, "SHOW ALL with replication role and logical replication");
# Test SHOW with a user-settable parameter # Test SHOW with a user-settable parameter
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'SHOW work_mem;', 'postgres', 'SHOW work_mem;',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
ok( $ret == 0, ok( $ret == 0,
"SHOW with user-settable parameter, replication role and physical replication" "SHOW with user-settable parameter, replication role and physical replication"
); );
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'SHOW work_mem;', 'postgres', 'SHOW work_mem;',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-d', $connstr_db ]); extra_params => [ '--dbname' => $connstr_db ]);
ok( $ret == 0, ok( $ret == 0,
"SHOW with user-settable parameter, replication role and logical replication" "SHOW with user-settable parameter, replication role and logical replication"
); );
@ -285,14 +289,14 @@ ok( $ret == 0,
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'SHOW primary_conninfo;', 'postgres', 'SHOW primary_conninfo;',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
ok( $ret == 0, ok( $ret == 0,
"SHOW with superuser-settable parameter, replication role and physical replication" "SHOW with superuser-settable parameter, replication role and physical replication"
); );
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'SHOW primary_conninfo;', 'postgres', 'SHOW primary_conninfo;',
on_error_die => 1, on_error_die => 1,
extra_params => [ '-d', $connstr_db ]); extra_params => [ '--dbname' => $connstr_db ]);
ok( $ret == 0, ok( $ret == 0,
"SHOW with superuser-settable parameter, replication role and logical replication" "SHOW with superuser-settable parameter, replication role and logical replication"
); );
@ -304,7 +308,7 @@ my $slotname = 'test_read_replication_slot_physical';
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'postgres',
'READ_REPLICATION_SLOT non_existent_slot;', 'READ_REPLICATION_SLOT non_existent_slot;',
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
ok($ret == 0, "READ_REPLICATION_SLOT exit code 0 on success"); ok($ret == 0, "READ_REPLICATION_SLOT exit code 0 on success");
like($stdout, qr/^\|\|$/, like($stdout, qr/^\|\|$/,
"READ_REPLICATION_SLOT returns NULL values if slot does not exist"); "READ_REPLICATION_SLOT returns NULL values if slot does not exist");
@ -312,12 +316,12 @@ like($stdout, qr/^\|\|$/,
$node_primary->psql( $node_primary->psql(
'postgres', 'postgres',
"CREATE_REPLICATION_SLOT $slotname PHYSICAL RESERVE_WAL;", "CREATE_REPLICATION_SLOT $slotname PHYSICAL RESERVE_WAL;",
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
($ret, $stdout, $stderr) = $node_primary->psql( ($ret, $stdout, $stderr) = $node_primary->psql(
'postgres', 'postgres',
"READ_REPLICATION_SLOT $slotname;", "READ_REPLICATION_SLOT $slotname;",
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
ok($ret == 0, "READ_REPLICATION_SLOT success with existing slot"); ok($ret == 0, "READ_REPLICATION_SLOT success with existing slot");
like($stdout, qr/^physical\|[^|]*\|1$/, like($stdout, qr/^physical\|[^|]*\|1$/,
"READ_REPLICATION_SLOT returns tuple with slot information"); "READ_REPLICATION_SLOT returns tuple with slot information");
@ -325,7 +329,7 @@ like($stdout, qr/^physical\|[^|]*\|1$/,
$node_primary->psql( $node_primary->psql(
'postgres', 'postgres',
"DROP_REPLICATION_SLOT $slotname;", "DROP_REPLICATION_SLOT $slotname;",
extra_params => [ '-d', $connstr_rep ]); extra_params => [ '--dbname' => $connstr_rep ]);
note "switching to physical replication slot"; note "switching to physical replication slot";
@ -594,16 +598,14 @@ my $sigchld_bb_timeout =
my ($sigchld_bb_stdin, $sigchld_bb_stdout, $sigchld_bb_stderr) = ('', '', ''); my ($sigchld_bb_stdin, $sigchld_bb_stdout, $sigchld_bb_stderr) = ('', '', '');
my $sigchld_bb = IPC::Run::start( my $sigchld_bb = IPC::Run::start(
[ [
'psql', '-X', '-c', "BASE_BACKUP (CHECKPOINT 'fast', MAX_RATE 32);", 'psql', '--no-psqlrc',
'-c', 'SELECT pg_backup_stop()', '--command' => "BASE_BACKUP (CHECKPOINT 'fast', MAX_RATE 32);",
'-d', $connstr '--command' => 'SELECT pg_backup_stop()',
'--dbname' => $connstr
], ],
'<', '<' => \$sigchld_bb_stdin,
\$sigchld_bb_stdin, '>' => \$sigchld_bb_stdout,
'>', '2>' => \$sigchld_bb_stderr,
\$sigchld_bb_stdout,
'2>',
\$sigchld_bb_stderr,
$sigchld_bb_timeout); $sigchld_bb_timeout);
# The cancellation is issued once the database files are streamed and # The cancellation is issued once the database files are streamed and

View File

@ -149,8 +149,11 @@ SKIP:
my $pg_recvlogical = IPC::Run::start( my $pg_recvlogical = IPC::Run::start(
[ [
'pg_recvlogical', '-d', $node_primary->connstr('otherdb'), 'pg_recvlogical',
'-S', 'otherdb_slot', '-f', '-', '--start' '--dbname' => $node_primary->connstr('otherdb'),
'--slot' => 'otherdb_slot',
'--file' => '-',
'--start'
]); ]);
$node_primary->poll_query_until('otherdb', $node_primary->poll_query_until('otherdb',
"SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NOT NULL)" "SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NOT NULL)"

View File

@ -34,30 +34,27 @@ $node->safe_psql(
my ($killme_stdin, $killme_stdout, $killme_stderr) = ('', '', ''); my ($killme_stdin, $killme_stdout, $killme_stderr) = ('', '', '');
my $killme = IPC::Run::start( my $killme = IPC::Run::start(
[ [
'psql', '-X', '-qAt', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', 'psql', '--no-psqlrc', '--quiet', '--no-align', '--tuples-only',
$node->connstr('postgres') '--set' => 'ON_ERROR_STOP=1',
'--file' => '-',
'--dbname' => $node->connstr('postgres')
], ],
'<', '<' => \$killme_stdin,
\$killme_stdin, '>' => \$killme_stdout,
'>', '2>' => \$killme_stderr,
\$killme_stdout,
'2>',
\$killme_stderr,
$psql_timeout); $psql_timeout);
# Need a second psql to check if crash-restart happened. # Need a second psql to check if crash-restart happened.
my ($monitor_stdin, $monitor_stdout, $monitor_stderr) = ('', '', ''); my ($monitor_stdin, $monitor_stdout, $monitor_stderr) = ('', '', '');
my $monitor = IPC::Run::start( my $monitor = IPC::Run::start(
[ [
'psql', '-X', '-qAt', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', 'psql', '--no-psqlrc', '--quiet', '--no-align', '--tuples-only',
$node->connstr('postgres') '--set' => 'ON_ERROR_STOP=1',
'--file', '-', '--dbname' => $node->connstr('postgres')
], ],
'<', '<' => \$monitor_stdin,
\$monitor_stdin, '>' => \$monitor_stdout,
'>', '2>' => \$monitor_stderr,
\$monitor_stdout,
'2>',
\$monitor_stderr,
$psql_timeout); $psql_timeout);
#create table, insert row that should survive #create table, insert row that should survive

View File

@ -29,11 +29,11 @@ my $tempdir = PostgreSQL::Test::Utils::tempdir;
# Log "ipcs" diffs on a best-effort basis, swallowing any error. # Log "ipcs" diffs on a best-effort basis, swallowing any error.
my $ipcs_before = "$tempdir/ipcs_before"; my $ipcs_before = "$tempdir/ipcs_before";
eval { run_log [ 'ipcs', '-am' ], '>', $ipcs_before; }; eval { run_log [ 'ipcs', '-am' ], '>' => $ipcs_before; };
sub log_ipcs sub log_ipcs
{ {
eval { run_log [ 'ipcs', '-am' ], '|', [ 'diff', $ipcs_before, '-' ] }; eval { run_log [ 'ipcs', '-am' ], '|' => [ 'diff', $ipcs_before, '-' ] };
return; return;
} }
@ -122,15 +122,13 @@ my $slow_query = 'SELECT wait_pid(pg_backend_pid())';
my ($stdout, $stderr); my ($stdout, $stderr);
my $slow_client = IPC::Run::start( my $slow_client = IPC::Run::start(
[ [
'psql', '-X', '-qAt', '-d', $gnat->connstr('postgres'), 'psql', '--no-psqlrc', '--quiet', '--no-align', '--tuples-only',
'-c', $slow_query '--dbname' => $gnat->connstr('postgres'),
'--command' => $slow_query
], ],
'<', '<' => \undef,
\undef, '>' => \$stdout,
'>', '2>' => \$stderr,
\$stdout,
'2>',
\$stderr,
IPC::Run::timeout(5 * $PostgreSQL::Test::Utils::timeout_default)); IPC::Run::timeout(5 * $PostgreSQL::Test::Utils::timeout_default));
ok( $gnat->poll_query_until( ok( $gnat->poll_query_until(
'postgres', 'postgres',

View File

@ -38,24 +38,26 @@ my $psql_timeout =
# to check uncommitted changes being replicated and such. # to check uncommitted changes being replicated and such.
my %psql_primary = (stdin => '', stdout => '', stderr => ''); my %psql_primary = (stdin => '', stdout => '', stderr => '');
$psql_primary{run} = IPC::Run::start( $psql_primary{run} = IPC::Run::start(
[ 'psql', '-XA', '-f', '-', '-d', $node_primary->connstr('postgres') ], [
'<', 'psql', '--no-psqlrc', '--no-align',
\$psql_primary{stdin}, '--file' => '-',
'>', '--dbname' => $node_primary->connstr('postgres'),
\$psql_primary{stdout}, ],
'2>', '<' => \$psql_primary{stdin},
\$psql_primary{stderr}, '>' => \$psql_primary{stdout},
'2>' => \$psql_primary{stderr},
$psql_timeout); $psql_timeout);
my %psql_standby = ('stdin' => '', 'stdout' => '', 'stderr' => ''); my %psql_standby = ('stdin' => '', 'stdout' => '', 'stderr' => '');
$psql_standby{run} = IPC::Run::start( $psql_standby{run} = IPC::Run::start(
[ 'psql', '-XA', '-f', '-', '-d', $node_standby->connstr('postgres') ], [
'<', 'psql', '--no-psqlrc', '--no-align',
\$psql_standby{stdin}, '--file' => '-',
'>', '--dbname' => $node_standby->connstr('postgres'),
\$psql_standby{stdout}, ],
'2>', '<' => \$psql_standby{stdin},
\$psql_standby{stderr}, '>' => \$psql_standby{stdout},
'2>' => \$psql_standby{stderr},
$psql_timeout); $psql_timeout);
# #

View File

@ -38,15 +38,14 @@ $node->safe_psql('postgres', q[CREATE TABLE tab_crash (a integer UNIQUE);]);
my ($killme_stdin, $killme_stdout, $killme_stderr) = ('', '', ''); my ($killme_stdin, $killme_stdout, $killme_stderr) = ('', '', '');
my $killme = IPC::Run::start( my $killme = IPC::Run::start(
[ [
'psql', '-X', '-qAt', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', 'psql', '--no-psqlrc', '--quiet', '--no-align', '--tuples-only',
$node->connstr('postgres') '--set' => 'ON_ERROR_STOP=1',
'--file' => '-',
'--dbname' => $node->connstr('postgres')
], ],
'<', '<' => \$killme_stdin,
\$killme_stdin, '>' => \$killme_stdout,
'>', '2>' => \$killme_stderr,
\$killme_stdout,
'2>',
\$killme_stderr,
$psql_timeout); $psql_timeout);
# Get backend pid # Get backend pid
@ -66,15 +65,14 @@ $killme_stderr = '';
my ($killme_stdin2, $killme_stdout2, $killme_stderr2) = ('', '', ''); my ($killme_stdin2, $killme_stdout2, $killme_stderr2) = ('', '', '');
my $killme2 = IPC::Run::start( my $killme2 = IPC::Run::start(
[ [
'psql', '-X', '-qAt', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', 'psql', '--no-psqlrc', '--quiet', '--no-align', '--tuples-only',
$node->connstr('postgres') '--set' => 'ON_ERROR_STOP=1',
'--file' => '-',
'--dbname' => $node->connstr('postgres')
], ],
'<', '<' => \$killme_stdin2,
\$killme_stdin2, '>' => \$killme_stdout2,
'>', '2>' => \$killme_stderr2,
\$killme_stdout2,
'2>',
\$killme_stderr2,
$psql_timeout); $psql_timeout);
# Insert one tuple and leave the transaction open # Insert one tuple and leave the transaction open

View File

@ -36,24 +36,26 @@ my $psql_timeout = IPC::Run::timer($PostgreSQL::Test::Utils::timeout_default);
my %psql_primary = (stdin => '', stdout => '', stderr => ''); my %psql_primary = (stdin => '', stdout => '', stderr => '');
$psql_primary{run} = IPC::Run::start( $psql_primary{run} = IPC::Run::start(
[ 'psql', '-XA', '-f', '-', '-d', $node_primary->connstr('postgres') ], [
'<', 'psql', '--no-psqlrc', '--no-align',
\$psql_primary{stdin}, '--file' => '-',
'>', '--dbname' => $node_primary->connstr('postgres')
\$psql_primary{stdout}, ],
'2>', '<' => \$psql_primary{stdin},
\$psql_primary{stderr}, '>' => \$psql_primary{stdout},
'2>' => \$psql_primary{stderr},
$psql_timeout); $psql_timeout);
my %psql_standby = ('stdin' => '', 'stdout' => '', 'stderr' => ''); my %psql_standby = ('stdin' => '', 'stdout' => '', 'stderr' => '');
$psql_standby{run} = IPC::Run::start( $psql_standby{run} = IPC::Run::start(
[ 'psql', '-XA', '-f', '-', '-d', $node_standby->connstr('postgres') ], [
'<', 'psql', '--no-psqlrc', '--no-align',
\$psql_standby{stdin}, '--file' => '-',
'>', '--dbname' => $node_standby->connstr('postgres')
\$psql_standby{stdout}, ],
'2>', '<' => \$psql_standby{stdin},
\$psql_standby{stderr}, '>' => \$psql_standby{stdout},
'2>' => \$psql_standby{stderr},
$psql_timeout); $psql_timeout);

View File

@ -75,18 +75,17 @@ sub make_slot_active
my $active_slot = $slot_prefix . 'activeslot'; my $active_slot = $slot_prefix . 'activeslot';
$slot_user_handle = IPC::Run::start( $slot_user_handle = IPC::Run::start(
[ [
'pg_recvlogical', '-d', 'pg_recvlogical',
$node->connstr('testdb'), '-S', '--dbname' => $node->connstr('testdb'),
qq($active_slot), '-o', '--slot' => $active_slot,
'include-xids=0', '-o', '--option' => 'include-xids=0',
'skip-empty-xacts=1', '--no-loop', '--option' => 'skip-empty-xacts=1',
'--start', '-f', '--file' => '-',
'-' '--no-loop',
'--start',
], ],
'>', '>' => $to_stdout,
$to_stdout, '2>' => $to_stderr,
'2>',
$to_stderr,
IPC::Run::timeout($default_timeout)); IPC::Run::timeout($default_timeout));
if ($wait) if ($wait)
@ -333,13 +332,14 @@ my %psql_subscriber = (
'subscriber_stdout' => '', 'subscriber_stdout' => '',
'subscriber_stderr' => ''); 'subscriber_stderr' => '');
$psql_subscriber{run} = IPC::Run::start( $psql_subscriber{run} = IPC::Run::start(
[ 'psql', '-XA', '-f', '-', '-d', $node_subscriber->connstr('postgres') ], [
'<', 'psql', '--no-psqlrc', '--no-align',
\$psql_subscriber{subscriber_stdin}, '--file' => '-',
'>', '--dbname' => $node_subscriber->connstr('postgres')
\$psql_subscriber{subscriber_stdout}, ],
'2>', '<' => \$psql_subscriber{subscriber_stdin},
\$psql_subscriber{subscriber_stderr}, '>' => \$psql_subscriber{subscriber_stdout},
'2>' => \$psql_subscriber{subscriber_stderr},
IPC::Run::timeout($default_timeout)); IPC::Run::timeout($default_timeout));
################################################## ##################################################

View File

@ -18,7 +18,7 @@ my $publisher = PostgreSQL::Test::Cluster->new('publisher');
# This is only needed on Windows machines that don't use UNIX sockets. # This is only needed on Windows machines that don't use UNIX sockets.
$publisher->init( $publisher->init(
allows_streaming => 'logical', allows_streaming => 'logical',
auth_extra => [ '--create-role', 'repl_role' ]); auth_extra => [ '--create-role' => 'repl_role' ]);
# Disable autovacuum to avoid generating xid during stats update as otherwise # Disable autovacuum to avoid generating xid during stats update as otherwise
# the new XID could then be replicated to standby at some random point making # the new XID could then be replicated to standby at some random point making
# slots at primary lag behind standby during slot sync. # slots at primary lag behind standby during slot sync.

View File

@ -124,15 +124,14 @@ my $psql_timeout = IPC::Run::timer(3600);
my ($killme_stdin, $killme_stdout, $killme_stderr) = ('', '', ''); my ($killme_stdin, $killme_stdout, $killme_stderr) = ('', '', '');
my $killme = IPC::Run::start( my $killme = IPC::Run::start(
[ [
'psql', '-XAtq', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', 'psql', '--no-psqlrc', '--no-align', '--tuples-only', '--quiet',
$node_standby->connstr('postgres') '--set' => 'ON_ERROR_STOP=1',
'--file' => '-',
'--dbname' => $node_standby->connstr('postgres')
], ],
'<', '<' => \$killme_stdin,
\$killme_stdin, '>' => \$killme_stdout,
'>', '2>' => \$killme_stderr,
\$killme_stdout,
'2>',
\$killme_stderr,
$psql_timeout); $psql_timeout);
$killme_stdin .= q[ $killme_stdin .= q[
SELECT pg_backend_pid(); SELECT pg_backend_pid();

View File

@ -51,7 +51,7 @@ while (my $test_src = glob("$src_dir/tests/*.0"))
# check result matches, adding any diff to $diffs_file # check result matches, adding any diff to $diffs_file
my $result = my $result =
run_log([ 'diff', @diffopts, "$test_src.stdout", "$test.out" ], run_log([ 'diff', @diffopts, "$test_src.stdout", "$test.out" ],
'>>', $diffs_file); '>>' => $diffs_file);
ok($result, "pg_bsd_indent output matches for $test"); ok($result, "pg_bsd_indent output matches for $test");
} }