mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Pre-beta mechanical code beautification.
Run pgindent, pgperltidy, and reformat-dat-files. This set of diffs is a bit larger than typical. We've updated to pg_bsd_indent 2.1.2, which properly indents variable declarations that have multi-line initialization expressions (the continuation lines are now indented one tab stop). We've also updated to perltidy version 20230309 and changed some of its settings, which reduces its desire to add whitespace to lines to make assignments etc. line up. Going forward, that should make for fewer random-seeming changes to existing code. Discussion: https://postgr.es/m/20230428092545.qfb3y5wcu4cm75ur@alvherre.pgsql
This commit is contained in:
@@ -329,13 +329,13 @@ sub adjust_old_dumpfile
|
||||
# adjust some places where we don't print so many parens anymore
|
||||
|
||||
my $prefix = "CONSTRAINT (?:sequence|copy)_con CHECK [(][(]";
|
||||
my $orig = "((x > 3) AND (y <> 'check failed'::text))";
|
||||
my $repl = "(x > 3) AND (y <> 'check failed'::text)";
|
||||
my $orig = "((x > 3) AND (y <> 'check failed'::text))";
|
||||
my $repl = "(x > 3) AND (y <> 'check failed'::text)";
|
||||
$dump =~ s/($prefix)\Q$orig\E/$1$repl/mg;
|
||||
|
||||
$prefix = "CONSTRAINT insert_con CHECK [(][(]";
|
||||
$orig = "((x >= 3) AND (y <> 'check failed'::text))";
|
||||
$repl = "(x >= 3) AND (y <> 'check failed'::text)";
|
||||
$orig = "((x >= 3) AND (y <> 'check failed'::text))";
|
||||
$repl = "(x >= 3) AND (y <> 'check failed'::text)";
|
||||
$dump =~ s/($prefix)\Q$orig\E/$1$repl/mg;
|
||||
|
||||
$orig = "DEFAULT ((-1) * currval('public.insert_seq'::regclass))";
|
||||
@@ -406,78 +406,78 @@ sub adjust_old_dumpfile
|
||||
# Data for _mash_view_qualifiers
|
||||
my @_unused_view_qualifiers = (
|
||||
# Present at least since 9.2
|
||||
{ obj => 'VIEW public.trigger_test_view', qual => 'trigger_test' },
|
||||
{ obj => 'VIEW public.domview', qual => 'domtab' },
|
||||
{ obj => 'VIEW public.trigger_test_view', qual => 'trigger_test' },
|
||||
{ obj => 'VIEW public.domview', qual => 'domtab' },
|
||||
{ obj => 'VIEW public.my_property_normal', qual => 'customer' },
|
||||
{ obj => 'VIEW public.my_property_secure', qual => 'customer' },
|
||||
{ obj => 'VIEW public.pfield_v1', qual => 'pf' },
|
||||
{ obj => 'VIEW public.rtest_v1', qual => 'rtest_t1' },
|
||||
{ obj => 'VIEW public.rtest_vview1', qual => 'x' },
|
||||
{ obj => 'VIEW public.rtest_vview2', qual => 'rtest_view1' },
|
||||
{ obj => 'VIEW public.rtest_vview3', qual => 'x' },
|
||||
{ obj => 'VIEW public.rtest_vview5', qual => 'rtest_view1' },
|
||||
{ obj => 'VIEW public.shoelace_obsolete', qual => 'shoelace' },
|
||||
{ obj => 'VIEW public.pfield_v1', qual => 'pf' },
|
||||
{ obj => 'VIEW public.rtest_v1', qual => 'rtest_t1' },
|
||||
{ obj => 'VIEW public.rtest_vview1', qual => 'x' },
|
||||
{ obj => 'VIEW public.rtest_vview2', qual => 'rtest_view1' },
|
||||
{ obj => 'VIEW public.rtest_vview3', qual => 'x' },
|
||||
{ obj => 'VIEW public.rtest_vview5', qual => 'rtest_view1' },
|
||||
{ obj => 'VIEW public.shoelace_obsolete', qual => 'shoelace' },
|
||||
{ obj => 'VIEW public.shoelace_candelete', qual => 'shoelace_obsolete' },
|
||||
{ obj => 'VIEW public.toyemp', qual => 'emp' },
|
||||
{ obj => 'VIEW public.xmlview4', qual => 'emp' },
|
||||
{ obj => 'VIEW public.toyemp', qual => 'emp' },
|
||||
{ obj => 'VIEW public.xmlview4', qual => 'emp' },
|
||||
# Since 9.3 (some of these were removed in 9.6)
|
||||
{ obj => 'VIEW public.tv', qual => 't' },
|
||||
{ obj => 'VIEW public.tv', qual => 't' },
|
||||
{ obj => 'MATERIALIZED VIEW mvschema.tvm', qual => 'tv' },
|
||||
{ obj => 'VIEW public.tvv', qual => 'tv' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tvvm', qual => 'tvv' },
|
||||
{ obj => 'VIEW public.tvvmv', qual => 'tvvm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.bb', qual => 'tvvmv' },
|
||||
{ obj => 'VIEW public.nums', qual => 'nums' },
|
||||
{ obj => 'VIEW public.sums_1_100', qual => 't' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tm', qual => 't' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tmm', qual => 'tm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tvmm', qual => 'tvm' },
|
||||
{ obj => 'VIEW public.tvv', qual => 'tv' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tvvm', qual => 'tvv' },
|
||||
{ obj => 'VIEW public.tvvmv', qual => 'tvvm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.bb', qual => 'tvvmv' },
|
||||
{ obj => 'VIEW public.nums', qual => 'nums' },
|
||||
{ obj => 'VIEW public.sums_1_100', qual => 't' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tm', qual => 't' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tmm', qual => 'tm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.tvmm', qual => 'tvm' },
|
||||
# Since 9.4
|
||||
{
|
||||
obj => 'MATERIALIZED VIEW public.citext_matview',
|
||||
obj => 'MATERIALIZED VIEW public.citext_matview',
|
||||
qual => 'citext_table'
|
||||
},
|
||||
{
|
||||
obj => 'OR REPLACE VIEW public.key_dependent_view',
|
||||
obj => 'OR REPLACE VIEW public.key_dependent_view',
|
||||
qual => 'view_base_table'
|
||||
},
|
||||
{
|
||||
obj => 'OR REPLACE VIEW public.key_dependent_view_no_cols',
|
||||
obj => 'OR REPLACE VIEW public.key_dependent_view_no_cols',
|
||||
qual => 'view_base_table'
|
||||
},
|
||||
# Since 9.5
|
||||
{
|
||||
obj => 'VIEW public.dummy_seclabel_view1',
|
||||
obj => 'VIEW public.dummy_seclabel_view1',
|
||||
qual => 'dummy_seclabel_tbl2'
|
||||
},
|
||||
{ obj => 'VIEW public.vv', qual => 'test_tablesample' },
|
||||
{ obj => 'VIEW public.vv', qual => 'test_tablesample' },
|
||||
{ obj => 'VIEW public.test_tablesample_v1', qual => 'test_tablesample' },
|
||||
{ obj => 'VIEW public.test_tablesample_v2', qual => 'test_tablesample' },
|
||||
# Since 9.6
|
||||
{
|
||||
obj => 'MATERIALIZED VIEW public.test_pg_dump_mv1',
|
||||
obj => 'MATERIALIZED VIEW public.test_pg_dump_mv1',
|
||||
qual => 'test_pg_dump_t1'
|
||||
},
|
||||
{ obj => 'VIEW public.test_pg_dump_v1', qual => 'test_pg_dump_t1' },
|
||||
{ obj => 'VIEW public.mvtest_tv', qual => 'mvtest_t' },
|
||||
{ obj => 'VIEW public.mvtest_tv', qual => 'mvtest_t' },
|
||||
{
|
||||
obj => 'MATERIALIZED VIEW mvtest_mvschema.mvtest_tvm',
|
||||
obj => 'MATERIALIZED VIEW mvtest_mvschema.mvtest_tvm',
|
||||
qual => 'mvtest_tv'
|
||||
},
|
||||
{ obj => 'VIEW public.mvtest_tvv', qual => 'mvtest_tv' },
|
||||
{ obj => 'VIEW public.mvtest_tvv', qual => 'mvtest_tv' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_tvvm', qual => 'mvtest_tvv' },
|
||||
{ obj => 'VIEW public.mvtest_tvvmv', qual => 'mvtest_tvvm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_bb', qual => 'mvtest_tvvmv' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_tm', qual => 'mvtest_t' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_tmm', qual => 'mvtest_tm' },
|
||||
{ obj => 'VIEW public.mvtest_tvvmv', qual => 'mvtest_tvvm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_bb', qual => 'mvtest_tvvmv' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_tm', qual => 'mvtest_t' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_tmm', qual => 'mvtest_tm' },
|
||||
{ obj => 'MATERIALIZED VIEW public.mvtest_tvmm', qual => 'mvtest_tvm' },
|
||||
# Since 10 (some removed in 12)
|
||||
{ obj => 'VIEW public.itestv10', qual => 'itest10' },
|
||||
{ obj => 'VIEW public.itestv11', qual => 'itest11' },
|
||||
{ obj => 'VIEW public.itestv10', qual => 'itest10' },
|
||||
{ obj => 'VIEW public.itestv11', qual => 'itest11' },
|
||||
{ obj => 'VIEW public.xmltableview2', qual => '"xmltable"' },
|
||||
# Since 12
|
||||
{
|
||||
obj => 'MATERIALIZED VIEW public.tableam_tblmv_heap2',
|
||||
obj => 'MATERIALIZED VIEW public.tableam_tblmv_heap2',
|
||||
qual => 'tableam_tbl_heap2'
|
||||
},
|
||||
# Since 13
|
||||
@@ -496,7 +496,7 @@ sub _mash_view_qualifiers
|
||||
|
||||
for my $uvq (@_unused_view_qualifiers)
|
||||
{
|
||||
my $leader = "CREATE $uvq->{obj} ";
|
||||
my $leader = "CREATE $uvq->{obj} ";
|
||||
my $qualifier = $uvq->{qual};
|
||||
# Note: we loop because there are presently some cases where the same
|
||||
# view name appears in multiple databases. Fortunately, the same
|
||||
@@ -507,8 +507,8 @@ sub _mash_view_qualifiers
|
||||
foreach my $chunk (@splitchunks)
|
||||
{
|
||||
my @thischunks = split /;/, $chunk, 2;
|
||||
my $stmt = shift(@thischunks);
|
||||
my $ostmt = $stmt;
|
||||
my $stmt = shift(@thischunks);
|
||||
my $ostmt = $stmt;
|
||||
|
||||
# now $stmt is just the body of the CREATE [MATERIALIZED] VIEW
|
||||
$stmt =~ s/$qualifier\.//g;
|
||||
|
||||
@@ -82,20 +82,28 @@ sub new
|
||||
{
|
||||
my $class = shift;
|
||||
my ($interactive, $psql_params) = @_;
|
||||
my $psql = {'stdin' => '', 'stdout' => '', 'stderr' => '', 'query_timer_restart' => undef};
|
||||
my $psql = {
|
||||
'stdin' => '',
|
||||
'stdout' => '',
|
||||
'stderr' => '',
|
||||
'query_timer_restart' => undef
|
||||
};
|
||||
my $run;
|
||||
|
||||
# This constructor should only be called from PostgreSQL::Test::Cluster
|
||||
my ($package, $file, $line) = caller;
|
||||
die "Forbidden caller of constructor: package: $package, file: $file:$line"
|
||||
my ($package, $file, $line) = caller;
|
||||
die
|
||||
"Forbidden caller of constructor: package: $package, file: $file:$line"
|
||||
unless $package->isa('PostgreSQL::Test::Cluster');
|
||||
|
||||
$psql->{timeout} = IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
|
||||
$psql->{timeout} =
|
||||
IPC::Run::timeout($PostgreSQL::Test::Utils::timeout_default);
|
||||
|
||||
if ($interactive)
|
||||
{
|
||||
$run = IPC::Run::start $psql_params,
|
||||
'<pty<', \$psql->{stdin}, '>pty>', \$psql->{stdout}, '2>', \$psql->{stderr},
|
||||
'<pty<', \$psql->{stdin}, '>pty>', \$psql->{stdout}, '2>',
|
||||
\$psql->{stderr},
|
||||
$psql->{timeout};
|
||||
}
|
||||
else
|
||||
@@ -126,8 +134,9 @@ sub _wait_connect
|
||||
# errors anyway, but that might be added later.)
|
||||
my $banner = "background_psql: ready";
|
||||
$self->{stdin} .= "\\echo $banner\n";
|
||||
$self->{run}->pump() until $self->{stdout} =~ /$banner/ || $self->{timeout}->is_expired;
|
||||
$self->{stdout} = ''; # clear out banner
|
||||
$self->{run}->pump()
|
||||
until $self->{stdout} =~ /$banner/ || $self->{timeout}->is_expired;
|
||||
$self->{stdout} = ''; # clear out banner
|
||||
|
||||
die "psql startup timed out" if $self->{timeout}->is_expired;
|
||||
}
|
||||
@@ -173,10 +182,10 @@ sub reconnect_and_clear
|
||||
|
||||
# restart
|
||||
$self->{run}->run();
|
||||
$self->{stdin} = '';
|
||||
$self->{stdin} = '';
|
||||
$self->{stdout} = '';
|
||||
|
||||
$self->_wait_connect()
|
||||
$self->_wait_connect();
|
||||
}
|
||||
|
||||
=pod
|
||||
@@ -219,7 +228,7 @@ sub query
|
||||
|
||||
$ret = $self->{stderr} eq "" ? 0 : 1;
|
||||
|
||||
return wantarray ? ( $output, $ret ) : $output;
|
||||
return wantarray ? ($output, $ret) : $output;
|
||||
}
|
||||
|
||||
=pod
|
||||
|
||||
@@ -112,10 +112,10 @@ use PostgreSQL::Version;
|
||||
use PostgreSQL::Test::RecursiveCopy;
|
||||
use Socket;
|
||||
use Test::More;
|
||||
use PostgreSQL::Test::Utils ();
|
||||
use PostgreSQL::Test::Utils ();
|
||||
use PostgreSQL::Test::BackgroundPsql ();
|
||||
use Time::HiRes qw(usleep);
|
||||
use Scalar::Util qw(blessed);
|
||||
use Time::HiRes qw(usleep);
|
||||
use Scalar::Util qw(blessed);
|
||||
|
||||
our ($use_tcp, $test_localhost, $test_pghost, $last_host_assigned,
|
||||
$last_port_assigned, @all_nodes, $died, $portdir);
|
||||
@@ -132,8 +132,8 @@ INIT
|
||||
|
||||
# Set PGHOST for backward compatibility. This doesn't work for own_host
|
||||
# nodes, so prefer to not rely on this when writing new tests.
|
||||
$use_tcp = !$PostgreSQL::Test::Utils::use_unix_sockets;
|
||||
$test_localhost = "127.0.0.1";
|
||||
$use_tcp = !$PostgreSQL::Test::Utils::use_unix_sockets;
|
||||
$test_localhost = "127.0.0.1";
|
||||
$last_host_assigned = 1;
|
||||
if ($use_tcp)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ INIT
|
||||
$test_pghost = PostgreSQL::Test::Utils::tempdir_short;
|
||||
$test_pghost =~ s!\\!/!g if $PostgreSQL::Test::Utils::windows_os;
|
||||
}
|
||||
$ENV{PGHOST} = $test_pghost;
|
||||
$ENV{PGHOST} = $test_pghost;
|
||||
$ENV{PGDATABASE} = 'postgres';
|
||||
|
||||
# Tracking of last port value assigned to accelerate free port lookup.
|
||||
@@ -160,9 +160,10 @@ INIT
|
||||
$portdir = $ENV{PG_TEST_PORT_DIR};
|
||||
# Otherwise, try to use a directory at the top of the build tree
|
||||
# or as a last resort use the tmp_check directory
|
||||
my $build_dir = $ENV{MESON_BUILD_ROOT}
|
||||
my $build_dir =
|
||||
$ENV{MESON_BUILD_ROOT}
|
||||
|| $ENV{top_builddir}
|
||||
|| $PostgreSQL::Test::Utils::tmp_check ;
|
||||
|| $PostgreSQL::Test::Utils::tmp_check;
|
||||
$portdir ||= "$build_dir/portlock";
|
||||
$portdir =~ s!\\!/!g;
|
||||
# Make sure the directory exists
|
||||
@@ -408,7 +409,7 @@ sub config_data
|
||||
my @map;
|
||||
foreach my $line (@lines)
|
||||
{
|
||||
my ($k,$v) = split (/ = /,$line,2);
|
||||
my ($k, $v) = split(/ = /, $line, 2);
|
||||
push(@map, $k, $v);
|
||||
}
|
||||
return @map;
|
||||
@@ -509,14 +510,14 @@ disabled.
|
||||
sub init
|
||||
{
|
||||
my ($self, %params) = @_;
|
||||
my $port = $self->port;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $host = $self->host;
|
||||
my $host = $self->host;
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
|
||||
$params{allows_streaming} = 0 unless defined $params{allows_streaming};
|
||||
$params{has_archiving} = 0 unless defined $params{has_archiving};
|
||||
$params{has_archiving} = 0 unless defined $params{has_archiving};
|
||||
|
||||
mkdir $self->backup_dir;
|
||||
mkdir $self->archive_dir;
|
||||
@@ -585,7 +586,7 @@ sub init
|
||||
or die("unable to set permissions for $pgdata/postgresql.conf");
|
||||
|
||||
$self->set_replication_conf if $params{allows_streaming};
|
||||
$self->enable_archiving if $params{has_archiving};
|
||||
$self->enable_archiving if $params{has_archiving};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -680,17 +681,17 @@ sub backup
|
||||
{
|
||||
my ($self, $backup_name, %params) = @_;
|
||||
my $backup_path = $self->backup_dir . '/' . $backup_name;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
|
||||
print "# Taking pg_basebackup $backup_name from node \"$name\"\n";
|
||||
PostgreSQL::Test::Utils::system_or_bail(
|
||||
'pg_basebackup', '-D',
|
||||
$backup_path, '-h',
|
||||
$self->host, '-p',
|
||||
$self->port, '--checkpoint',
|
||||
'fast', '--no-sync',
|
||||
$backup_path, '-h',
|
||||
$self->host, '-p',
|
||||
$self->port, '--checkpoint',
|
||||
'fast', '--no-sync',
|
||||
@{ $params{backup_options} });
|
||||
print "# Backup finished\n";
|
||||
return;
|
||||
@@ -755,14 +756,14 @@ sub init_from_backup
|
||||
{
|
||||
my ($self, $root_node, $backup_name, %params) = @_;
|
||||
my $backup_path = $root_node->backup_dir . '/' . $backup_name;
|
||||
my $host = $self->host;
|
||||
my $port = $self->port;
|
||||
my $node_name = $self->name;
|
||||
my $root_name = $root_node->name;
|
||||
my $host = $self->host;
|
||||
my $port = $self->port;
|
||||
my $node_name = $self->name;
|
||||
my $root_name = $root_node->name;
|
||||
|
||||
$params{has_streaming} = 0 unless defined $params{has_streaming};
|
||||
$params{has_restoring} = 0 unless defined $params{has_restoring};
|
||||
$params{standby} = 1 unless defined $params{standby};
|
||||
$params{standby} = 1 unless defined $params{standby};
|
||||
|
||||
print
|
||||
"# Initializing node \"$node_name\" from backup \"$backup_name\" of node \"$root_name\"\n";
|
||||
@@ -780,7 +781,7 @@ sub init_from_backup
|
||||
$backup_path . '/base.tar',
|
||||
'-C', $data_path);
|
||||
PostgreSQL::Test::Utils::system_or_bail(
|
||||
$params{tar_program}, 'xf',
|
||||
$params{tar_program}, 'xf',
|
||||
$backup_path . '/pg_wal.tar', '-C',
|
||||
$data_path . '/pg_wal');
|
||||
}
|
||||
@@ -853,9 +854,9 @@ instead return a true or false value to indicate success or failure.
|
||||
sub start
|
||||
{
|
||||
my ($self, %params) = @_;
|
||||
my $port = $self->port;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
my $ret;
|
||||
|
||||
BAIL_OUT("node \"$name\" is already running") if defined $self->{_pid};
|
||||
@@ -872,8 +873,8 @@ sub start
|
||||
# -w is now the default but having it here does no harm and helps
|
||||
# compatibility with older versions.
|
||||
$ret = PostgreSQL::Test::Utils::system_log(
|
||||
'pg_ctl', '-w', '-D', $self->data_dir,
|
||||
'-l', $self->logfile, '-o', "--cluster-name=$name",
|
||||
'pg_ctl', '-w', '-D', $self->data_dir,
|
||||
'-l', $self->logfile, '-o', "--cluster-name=$name",
|
||||
'start');
|
||||
|
||||
if ($ret != 0)
|
||||
@@ -938,7 +939,7 @@ sub stop
|
||||
{
|
||||
my ($self, $mode, %params) = @_;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
my $ret;
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
@@ -976,9 +977,9 @@ Reload configuration parameters on the node.
|
||||
sub reload
|
||||
{
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
|
||||
@@ -998,11 +999,11 @@ Wrapper for pg_ctl restart
|
||||
|
||||
sub restart
|
||||
{
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $logfile = $self->logfile;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
|
||||
local %ENV = $self->_get_env(PGAPPNAME => undef);
|
||||
|
||||
@@ -1027,11 +1028,11 @@ Wrapper for pg_ctl promote
|
||||
|
||||
sub promote
|
||||
{
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $logfile = $self->logfile;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
|
||||
@@ -1051,11 +1052,11 @@ Wrapper for pg_ctl logrotate
|
||||
|
||||
sub logrotate
|
||||
{
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my ($self) = @_;
|
||||
my $port = $self->port;
|
||||
my $pgdata = $self->data_dir;
|
||||
my $logfile = $self->logfile;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
|
||||
@@ -1070,7 +1071,7 @@ sub enable_streaming
|
||||
{
|
||||
my ($self, $root_node) = @_;
|
||||
my $root_connstr = $root_node->connstr;
|
||||
my $name = $self->name;
|
||||
my $name = $self->name;
|
||||
|
||||
print "### Enabling streaming replication for node \"$name\"\n";
|
||||
$self->append_conf(
|
||||
@@ -1155,8 +1156,8 @@ sub set_standby_mode
|
||||
sub enable_archiving
|
||||
{
|
||||
my ($self) = @_;
|
||||
my $path = $self->archive_dir;
|
||||
my $name = $self->name;
|
||||
my $path = $self->archive_dir;
|
||||
my $name = $self->name;
|
||||
|
||||
print "### Enabling WAL archiving for node \"$name\"\n";
|
||||
|
||||
@@ -1301,7 +1302,7 @@ sub new
|
||||
_host => $host,
|
||||
_basedir =>
|
||||
"$PostgreSQL::Test::Utils::tmp_check/t_${testname}_${name}_data",
|
||||
_name => $name,
|
||||
_name => $name,
|
||||
_logfile_generation => 0,
|
||||
_logfile_base =>
|
||||
"$PostgreSQL::Test::Utils::log_path/${testname}_${name}",
|
||||
@@ -1354,8 +1355,8 @@ sub new
|
||||
#
|
||||
sub _set_pg_version
|
||||
{
|
||||
my ($self) = @_;
|
||||
my $inst = $self->{_install_path};
|
||||
my ($self) = @_;
|
||||
my $inst = $self->{_install_path};
|
||||
my $pg_config = "pg_config";
|
||||
|
||||
if (defined $inst)
|
||||
@@ -1509,7 +1510,7 @@ called from outside the module as C<PostgreSQL::Test::Cluster::get_free_port()>.
|
||||
sub get_free_port
|
||||
{
|
||||
my $found = 0;
|
||||
my $port = $last_port_assigned;
|
||||
my $port = $last_port_assigned;
|
||||
|
||||
while ($found == 0)
|
||||
{
|
||||
@@ -1589,14 +1590,14 @@ sub _reserve_port
|
||||
my $port = shift;
|
||||
# open in rw mode so we don't have to reopen it and lose the lock
|
||||
my $filename = "$portdir/$port.rsv";
|
||||
sysopen(my $portfile, $filename, O_RDWR|O_CREAT)
|
||||
sysopen(my $portfile, $filename, O_RDWR | O_CREAT)
|
||||
|| die "opening port file $filename: $!";
|
||||
# take an exclusive lock to avoid concurrent access
|
||||
flock($portfile, LOCK_EX) || die "locking port file $filename: $!";
|
||||
# see if someone else has or had a reservation of this port
|
||||
my $pid = <$portfile> || "0";
|
||||
chomp $pid;
|
||||
if ($pid +0 > 0)
|
||||
if ($pid + 0 > 0)
|
||||
{
|
||||
if (kill 0, $pid)
|
||||
{
|
||||
@@ -1609,7 +1610,7 @@ sub _reserve_port
|
||||
# All good, go ahead and reserve the port
|
||||
seek($portfile, 0, SEEK_SET);
|
||||
# print the pid with a fixed width so we don't leave any trailing junk
|
||||
print $portfile sprintf("%10d\n",$$);
|
||||
print $portfile sprintf("%10d\n", $$);
|
||||
flock($portfile, LOCK_UN);
|
||||
close($portfile);
|
||||
push(@port_reservation_files, $filename);
|
||||
@@ -1705,9 +1706,9 @@ sub safe_psql
|
||||
my $ret = $self->psql(
|
||||
$dbname, $sql,
|
||||
%params,
|
||||
stdout => \$stdout,
|
||||
stderr => \$stderr,
|
||||
on_error_die => 1,
|
||||
stdout => \$stdout,
|
||||
stderr => \$stderr,
|
||||
on_error_die => 1,
|
||||
on_error_stop => 1);
|
||||
|
||||
# psql can emit stderr from NOTICEs etc
|
||||
@@ -1819,10 +1820,10 @@ sub psql
|
||||
|
||||
local %ENV = $self->_get_env();
|
||||
|
||||
my $stdout = $params{stdout};
|
||||
my $stderr = $params{stderr};
|
||||
my $replication = $params{replication};
|
||||
my $timeout = undef;
|
||||
my $stdout = $params{stdout};
|
||||
my $stderr = $params{stderr};
|
||||
my $replication = $params{replication};
|
||||
my $timeout = undef;
|
||||
my $timeout_exception = 'psql timed out';
|
||||
|
||||
# Build the connection string.
|
||||
@@ -1859,7 +1860,7 @@ sub psql
|
||||
}
|
||||
|
||||
$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, @{ $params{extra_params} }
|
||||
@@ -1888,7 +1889,7 @@ sub psql
|
||||
local $@;
|
||||
eval {
|
||||
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, $timeout if defined $timeout;
|
||||
|
||||
@@ -2231,8 +2232,8 @@ sub connect_ok
|
||||
my ($ret, $stdout, $stderr) = $self->psql(
|
||||
'postgres',
|
||||
$sql,
|
||||
extra_params => ['-w'],
|
||||
connstr => "$connstr",
|
||||
extra_params => ['-w'],
|
||||
connstr => "$connstr",
|
||||
on_error_stop => 0);
|
||||
|
||||
is($ret, 0, $test_name);
|
||||
@@ -2306,7 +2307,7 @@ sub connect_fails
|
||||
'postgres',
|
||||
undef,
|
||||
extra_params => ['-w'],
|
||||
connstr => "$connstr");
|
||||
connstr => "$connstr");
|
||||
|
||||
isnt($ret, 0, $test_name);
|
||||
|
||||
@@ -2353,11 +2354,11 @@ sub poll_query_until
|
||||
|
||||
my $cmd = [
|
||||
$self->installed_command('psql'), '-XAt',
|
||||
'-d', $self->connstr($dbname)
|
||||
'-d', $self->connstr($dbname)
|
||||
];
|
||||
my ($stdout, $stderr);
|
||||
my $max_attempts = 10 * $PostgreSQL::Test::Utils::timeout_default;
|
||||
my $attempts = 0;
|
||||
my $attempts = 0;
|
||||
|
||||
while ($attempts < $max_attempts)
|
||||
{
|
||||
@@ -2531,8 +2532,7 @@ Returns the contents of log of the node
|
||||
sub log_content
|
||||
{
|
||||
my ($self) = @_;
|
||||
return
|
||||
PostgreSQL::Test::Utils::slurp_file($self->logfile);
|
||||
return PostgreSQL::Test::Utils::slurp_file($self->logfile);
|
||||
}
|
||||
|
||||
|
||||
@@ -2574,11 +2574,11 @@ sub lsn
|
||||
{
|
||||
my ($self, $mode) = @_;
|
||||
my %modes = (
|
||||
'insert' => 'pg_current_wal_insert_lsn()',
|
||||
'flush' => 'pg_current_wal_flush_lsn()',
|
||||
'write' => 'pg_current_wal_lsn()',
|
||||
'insert' => 'pg_current_wal_insert_lsn()',
|
||||
'flush' => 'pg_current_wal_flush_lsn()',
|
||||
'write' => 'pg_current_wal_lsn()',
|
||||
'receive' => 'pg_last_wal_receive_lsn()',
|
||||
'replay' => 'pg_last_wal_replay_lsn()');
|
||||
'replay' => 'pg_last_wal_replay_lsn()');
|
||||
|
||||
$mode = '<undef>' if !defined($mode);
|
||||
croak "unknown mode for 'lsn': '$mode', valid modes are "
|
||||
@@ -2650,7 +2650,8 @@ sub wait_for_catchup
|
||||
}
|
||||
if (!defined($target_lsn))
|
||||
{
|
||||
my $isrecovery = $self->safe_psql('postgres', "SELECT pg_is_in_recovery()");
|
||||
my $isrecovery =
|
||||
$self->safe_psql('postgres', "SELECT pg_is_in_recovery()");
|
||||
chomp($isrecovery);
|
||||
if ($isrecovery eq 't')
|
||||
{
|
||||
@@ -2788,7 +2789,7 @@ sub wait_for_subscription_sync
|
||||
# Wait for all tables to finish initial sync.
|
||||
print "Waiting for all subscriptions in \"$name\" to synchronize data\n";
|
||||
my $query =
|
||||
qq[SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');];
|
||||
qq[SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('r', 's');];
|
||||
$self->poll_query_until($dbname, $query)
|
||||
or croak "timed out waiting for subscriber to synchronize data";
|
||||
|
||||
@@ -2821,7 +2822,7 @@ sub wait_for_log
|
||||
$offset = 0 unless defined $offset;
|
||||
|
||||
my $max_attempts = 10 * $PostgreSQL::Test::Utils::timeout_default;
|
||||
my $attempts = 0;
|
||||
my $attempts = 0;
|
||||
|
||||
while ($attempts < $max_attempts)
|
||||
{
|
||||
@@ -2903,8 +2904,8 @@ sub slot
|
||||
{
|
||||
my ($self, $slot_name) = @_;
|
||||
my @columns = (
|
||||
'plugin', 'slot_type', 'datoid', 'database',
|
||||
'active', 'active_pid', 'xmin', 'catalog_xmin',
|
||||
'plugin', 'slot_type', 'datoid', 'database',
|
||||
'active', 'active_pid', 'xmin', 'catalog_xmin',
|
||||
'restart_lsn');
|
||||
return $self->query_hash(
|
||||
'postgres',
|
||||
@@ -2943,7 +2944,7 @@ sub pg_recvlogical_upto
|
||||
my $timeout_exception = 'pg_recvlogical timed out';
|
||||
|
||||
croak 'slot name must be specified' unless defined($slot_name);
|
||||
croak 'endpos must be specified' unless defined($endpos);
|
||||
croak 'endpos must be specified' unless defined($endpos);
|
||||
|
||||
my @cmd = (
|
||||
$self->installed_command('pg_recvlogical'),
|
||||
@@ -3057,7 +3058,17 @@ sub create_logical_slot_on_standby
|
||||
|
||||
my $handle;
|
||||
|
||||
$handle = IPC::Run::start(['pg_recvlogical', '-d', $self->connstr($dbname), '-P', 'test_decoding', '-S', $slot_name, '--create-slot'], '>', \$stdout, '2>', \$stderr);
|
||||
$handle = IPC::Run::start(
|
||||
[
|
||||
'pg_recvlogical', '-d',
|
||||
$self->connstr($dbname), '-P',
|
||||
'test_decoding', '-S',
|
||||
$slot_name, '--create-slot'
|
||||
],
|
||||
'>',
|
||||
\$stdout,
|
||||
'2>',
|
||||
\$stderr);
|
||||
|
||||
# Once the slot's restart_lsn is determined, the standby looks for
|
||||
# xl_running_xacts WAL record from the restart_lsn onwards. First wait
|
||||
@@ -3067,7 +3078,9 @@ sub create_logical_slot_on_standby
|
||||
'postgres', qq[
|
||||
SELECT restart_lsn IS NOT NULL
|
||||
FROM pg_catalog.pg_replication_slots WHERE slot_name = '$slot_name'
|
||||
]) or die "timed out waiting for logical slot to calculate its restart_lsn";
|
||||
])
|
||||
or die
|
||||
"timed out waiting for logical slot to calculate its restart_lsn";
|
||||
|
||||
# Then arrange for the xl_running_xacts record for which pg_recvlogical is
|
||||
# waiting.
|
||||
@@ -3075,8 +3088,9 @@ sub create_logical_slot_on_standby
|
||||
|
||||
$handle->finish();
|
||||
|
||||
is($self->slot($slot_name)->{'slot_type'}, 'logical', $slot_name . ' on standby created')
|
||||
or die "could not create slot" . $slot_name;
|
||||
is($self->slot($slot_name)->{'slot_type'},
|
||||
'logical', $slot_name . ' on standby created')
|
||||
or die "could not create slot" . $slot_name;
|
||||
}
|
||||
|
||||
=pod
|
||||
|
||||
@@ -93,7 +93,7 @@ sub copypath
|
||||
sub _copypath_recurse
|
||||
{
|
||||
my ($base_src_dir, $base_dest_dir, $curr_path, $filterfn) = @_;
|
||||
my $srcpath = "$base_src_dir/$curr_path";
|
||||
my $srcpath = "$base_src_dir/$curr_path";
|
||||
my $destpath = "$base_dest_dir/$curr_path";
|
||||
|
||||
# invoke the filter and skip all further operation if it returns false
|
||||
|
||||
@@ -27,7 +27,7 @@ BEGIN { $last_time = time; }
|
||||
|
||||
sub _time_str
|
||||
{
|
||||
my $tm = time;
|
||||
my $tm = time;
|
||||
my $diff = $tm - $last_time;
|
||||
$last_time = $tm;
|
||||
my ($sec, $min, $hour) = localtime($tm);
|
||||
@@ -45,12 +45,12 @@ sub TIEHANDLE
|
||||
sub PRINT
|
||||
{
|
||||
my $self = shift;
|
||||
my $ok = 1;
|
||||
my $ok = 1;
|
||||
# The first file argument passed to tiehandle in PostgreSQL::Test::Utils is
|
||||
# the original stdout, which is what PROVE sees. Additional decorations
|
||||
# confuse it, so only put out the time string on files after the first.
|
||||
my $skip = 1;
|
||||
my $ts = _time_str;
|
||||
my $ts = _time_str;
|
||||
for my $fh (@$self)
|
||||
{
|
||||
print $fh ($skip ? "" : $ts), @_ or $ok = 0;
|
||||
|
||||
@@ -146,7 +146,7 @@ BEGIN
|
||||
$windows_os = $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys';
|
||||
# Check if this environment is MSYS2.
|
||||
$is_msys2 =
|
||||
$windows_os
|
||||
$windows_os
|
||||
&& -x '/usr/bin/uname'
|
||||
&& `uname -or` =~ /^[2-9].*Msys/;
|
||||
|
||||
@@ -211,15 +211,15 @@ INIT
|
||||
# Hijack STDOUT and STDERR to the log file
|
||||
open(my $orig_stdout, '>&', \*STDOUT);
|
||||
open(my $orig_stderr, '>&', \*STDERR);
|
||||
open(STDOUT, '>&', $testlog);
|
||||
open(STDERR, '>&', $testlog);
|
||||
open(STDOUT, '>&', $testlog);
|
||||
open(STDERR, '>&', $testlog);
|
||||
|
||||
# The test output (ok ...) needs to be printed to the original STDOUT so
|
||||
# that the 'prove' program can parse it, and display it to the user in
|
||||
# real time. But also copy it to the log file, to provide more context
|
||||
# in the log.
|
||||
my $builder = Test::More->builder;
|
||||
my $fh = $builder->output;
|
||||
my $fh = $builder->output;
|
||||
tie *$fh, "PostgreSQL::Test::SimpleTee", $orig_stdout, $testlog;
|
||||
$fh = $builder->failure_output;
|
||||
tie *$fh, "PostgreSQL::Test::SimpleTee", $orig_stderr, $testlog;
|
||||
@@ -284,7 +284,7 @@ sub tempdir
|
||||
$prefix = "tmp_test" unless defined $prefix;
|
||||
return File::Temp::tempdir(
|
||||
$prefix . '_XXXX',
|
||||
DIR => $tmp_check,
|
||||
DIR => $tmp_check,
|
||||
CLEANUP => 1);
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ https://postgr.es/m/20220116210241.GC756210@rfd.leadboat.com for details.
|
||||
sub has_wal_read_bug
|
||||
{
|
||||
return
|
||||
$Config{osname} eq 'linux'
|
||||
$Config{osname} eq 'linux'
|
||||
&& $Config{archname} =~ /^sparc/
|
||||
&& !run_log([ qw(df -x ext4), $tmp_check ], '>', '/dev/null', '2>&1');
|
||||
}
|
||||
@@ -563,10 +563,10 @@ sub string_replace_file
|
||||
my ($filename, $find, $replace) = @_;
|
||||
open(my $in, '<', $filename);
|
||||
my $content;
|
||||
while(<$in>)
|
||||
while (<$in>)
|
||||
{
|
||||
$_ =~ s/$find/$replace/;
|
||||
$content = $content.$_;
|
||||
$content = $content . $_;
|
||||
}
|
||||
close $in;
|
||||
open(my $out, '>', $filename);
|
||||
@@ -595,7 +595,7 @@ sub check_mode_recursive
|
||||
find(
|
||||
{
|
||||
follow_fast => 1,
|
||||
wanted => sub {
|
||||
wanted => sub {
|
||||
# Is file in the ignore list?
|
||||
foreach my $ignore ($ignore_list ? @{$ignore_list} : [])
|
||||
{
|
||||
@@ -611,7 +611,7 @@ sub check_mode_recursive
|
||||
unless (defined($file_stat))
|
||||
{
|
||||
my $is_ENOENT = $!{ENOENT};
|
||||
my $msg = "unable to stat $File::Find::name: $!";
|
||||
my $msg = "unable to stat $File::Find::name: $!";
|
||||
if ($is_ENOENT)
|
||||
{
|
||||
warn $msg;
|
||||
@@ -682,7 +682,7 @@ sub chmod_recursive
|
||||
find(
|
||||
{
|
||||
follow_fast => 1,
|
||||
wanted => sub {
|
||||
wanted => sub {
|
||||
my $file_stat = stat($File::Find::name);
|
||||
|
||||
if (defined($file_stat))
|
||||
|
||||
@@ -52,7 +52,7 @@ use Scalar::Util qw(blessed);
|
||||
use overload
|
||||
'<=>' => \&_version_cmp,
|
||||
'cmp' => \&_version_cmp,
|
||||
'""' => \&_stringify;
|
||||
'""' => \&_stringify;
|
||||
|
||||
=pod
|
||||
|
||||
@@ -74,7 +74,7 @@ of a Postgres command like `psql --version` or `pg_config --version`;
|
||||
sub new
|
||||
{
|
||||
my $class = shift;
|
||||
my $arg = shift;
|
||||
my $arg = shift;
|
||||
|
||||
chomp $arg;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user