Commit f04d4ac9 authored by Tom Lane's avatar Tom Lane

Reindent Perl files with perltidy version 20170521.

Discussion: https://postgr.es/m/CABUevEzK3cNiHZQ18f5tK0guoT+cN_jWeVzhYYxY=r+1Q3SmoA@mail.gmail.com
parent 46cda5bf
...@@ -38,8 +38,8 @@ while (<$feat>) ...@@ -38,8 +38,8 @@ while (<$feat>)
$is_supported eq $yesno || next; $is_supported eq $yesno || next;
$feature_name =~ s/</&lt;/g; $feature_name =~ s/</&lt;/g;
$feature_name =~ s/>/&gt;/g; $feature_name =~ s/>/&gt;/g;
$subfeature_name =~ s/</&lt;/g; $subfeature_name =~ s/</&lt;/g;
$subfeature_name =~ s/>/&gt;/g; $subfeature_name =~ s/>/&gt;/g;
......
...@@ -33,185 +33,186 @@ sub ParseHeader ...@@ -33,185 +33,186 @@ sub ParseHeader
'TransactionId' => 'xid', 'TransactionId' => 'xid',
'XLogRecPtr' => 'pg_lsn'); 'XLogRecPtr' => 'pg_lsn');
my %catalog; my %catalog;
my $declaring_attributes = 0; my $declaring_attributes = 0;
my $is_varlen = 0; my $is_varlen = 0;
my $is_client_code = 0; my $is_client_code = 0;
$catalog{columns} = []; $catalog{columns} = [];
$catalog{toasting} = []; $catalog{toasting} = [];
$catalog{indexing} = []; $catalog{indexing} = [];
$catalog{client_code} = []; $catalog{client_code} = [];
open(my $ifh, '<', $input_file) || die "$input_file: $!"; open(my $ifh, '<', $input_file) || die "$input_file: $!";
# Scan the input file. # Scan the input file.
while (<$ifh>) while (<$ifh>)
{ {
# Set appropriate flag when we're in certain code sections. # Set appropriate flag when we're in certain code sections.
if (/^#/) if (/^#/)
{
$is_varlen = 1 if /^#ifdef\s+CATALOG_VARLEN/;
if (/^#ifdef\s+EXPOSE_TO_CLIENT_CODE/)
{ {
$is_varlen = 1 if /^#ifdef\s+CATALOG_VARLEN/; $is_client_code = 1;
if (/^#ifdef\s+EXPOSE_TO_CLIENT_CODE/) next;
{
$is_client_code = 1;
next;
}
next if !$is_client_code;
} }
next if !$is_client_code;
}
if (!$is_client_code) if (!$is_client_code)
{
# Strip C-style comments.
s;/\*(.|\n)*\*/;;g;
if (m;/\*;)
{ {
# Strip C-style comments.
s;/\*(.|\n)*\*/;;g;
if (m;/\*;)
{
# handle multi-line comments properly.
my $next_line = <$ifh>;
die "$input_file: ends within C-style comment\n"
if !defined $next_line;
$_ .= $next_line;
redo;
}
# Strip useless whitespace and trailing semicolons. # handle multi-line comments properly.
chomp; my $next_line = <$ifh>;
s/^\s+//; die "$input_file: ends within C-style comment\n"
s/;\s*$//; if !defined $next_line;
s/\s+/ /g; $_ .= $next_line;
redo;
} }
# Push the data into the appropriate data structure. # Strip useless whitespace and trailing semicolons.
if (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/) chomp;
s/^\s+//;
s/;\s*$//;
s/\s+/ /g;
}
# Push the data into the appropriate data structure.
if (/^DECLARE_TOAST\(\s*(\w+),\s*(\d+),\s*(\d+)\)/)
{
my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3);
push @{ $catalog{toasting} },
"declare toast $toast_oid $index_oid on $toast_name\n";
}
elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/)
{
my ($is_unique, $index_name, $index_oid, $using) =
($1, $2, $3, $4);
push @{ $catalog{indexing} },
sprintf(
"declare %sindex %s %s %s\n",
$is_unique ? 'unique ' : '',
$index_name, $index_oid, $using);
}
elsif (/^BUILD_INDICES/)
{
push @{ $catalog{indexing} }, "build indices\n";
}
elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/)
{
$catalog{catname} = $1;
$catalog{relation_oid} = $2;
$catalog{relation_oid_macro} = $3;
$catalog{bootstrap} = /BKI_BOOTSTRAP/ ? ' bootstrap' : '';
$catalog{shared_relation} =
/BKI_SHARED_RELATION/ ? ' shared_relation' : '';
$catalog{without_oids} =
/BKI_WITHOUT_OIDS/ ? ' without_oids' : '';
if (/BKI_ROWTYPE_OID\((\d+),(\w+)\)/)
{ {
my ($toast_name, $toast_oid, $index_oid) = ($1, $2, $3); $catalog{rowtype_oid} = $1;
push @{ $catalog{toasting} }, $catalog{rowtype_oid_clause} = " rowtype_oid $1";
"declare toast $toast_oid $index_oid on $toast_name\n"; $catalog{rowtype_oid_macro} = $2;
} }
elsif (/^DECLARE_(UNIQUE_)?INDEX\(\s*(\w+),\s*(\d+),\s*(.+)\)/) else
{ {
my ($is_unique, $index_name, $index_oid, $using) = $catalog{rowtype_oid} = '';
($1, $2, $3, $4); $catalog{rowtype_oid_clause} = '';
push @{ $catalog{indexing} }, $catalog{rowtype_oid_macro} = '';
sprintf(
"declare %sindex %s %s %s\n",
$is_unique ? 'unique ' : '',
$index_name, $index_oid, $using);
} }
elsif (/^BUILD_INDICES/) $catalog{schema_macro} = /BKI_SCHEMA_MACRO/ ? 1 : 0;
$declaring_attributes = 1;
}
elsif ($is_client_code)
{
if (/^#endif/)
{ {
push @{ $catalog{indexing} }, "build indices\n"; $is_client_code = 0;
} }
elsif (/^CATALOG\((\w+),(\d+),(\w+)\)/) else
{ {
$catalog{catname} = $1; push @{ $catalog{client_code} }, $_;
$catalog{relation_oid} = $2;
$catalog{relation_oid_macro} = $3;
$catalog{bootstrap} = /BKI_BOOTSTRAP/ ? ' bootstrap' : '';
$catalog{shared_relation} =
/BKI_SHARED_RELATION/ ? ' shared_relation' : '';
$catalog{without_oids} =
/BKI_WITHOUT_OIDS/ ? ' without_oids' : '';
if (/BKI_ROWTYPE_OID\((\d+),(\w+)\)/)
{
$catalog{rowtype_oid} = $1;
$catalog{rowtype_oid_clause} = " rowtype_oid $1";
$catalog{rowtype_oid_macro} = $2;
}
else
{
$catalog{rowtype_oid} = '';
$catalog{rowtype_oid_clause} = '';
$catalog{rowtype_oid_macro} = '';
}
$catalog{schema_macro} = /BKI_SCHEMA_MACRO/ ? 1 : 0;
$declaring_attributes = 1;
} }
elsif ($is_client_code) }
elsif ($declaring_attributes)
{
next if (/^{|^$/);
if (/^}/)
{ {
if (/^#endif/) $declaring_attributes = 0;
{
$is_client_code = 0;
}
else
{
push @{ $catalog{client_code} }, $_;
}
} }
elsif ($declaring_attributes) else
{ {
next if (/^{|^$/); my %column;
if (/^}/) my @attopts = split /\s+/, $_;
my $atttype = shift @attopts;
my $attname = shift @attopts;
die "parse error ($input_file)"
unless ($attname and $atttype);
if (exists $RENAME_ATTTYPE{$atttype})
{ {
$declaring_attributes = 0; $atttype = $RENAME_ATTTYPE{$atttype};
} }
else
# If the C name ends with '[]' or '[digits]', we have
# an array type, so we discard that from the name and
# prepend '_' to the type.
if ($attname =~ /(\w+)\[\d*\]/)
{ {
my %column; $attname = $1;
my @attopts = split /\s+/, $_; $atttype = '_' . $atttype;
my $atttype = shift @attopts; }
my $attname = shift @attopts;
die "parse error ($input_file)" $column{type} = $atttype;
unless ($attname and $atttype); $column{name} = $attname;
$column{is_varlen} = 1 if $is_varlen;
if (exists $RENAME_ATTTYPE{$atttype})
foreach my $attopt (@attopts)
{
if ($attopt eq 'BKI_FORCE_NULL')
{ {
$atttype = $RENAME_ATTTYPE{$atttype}; $column{forcenull} = 1;
} }
elsif ($attopt eq 'BKI_FORCE_NOT_NULL')
# If the C name ends with '[]' or '[digits]', we have
# an array type, so we discard that from the name and
# prepend '_' to the type.
if ($attname =~ /(\w+)\[\d*\]/)
{ {
$attname = $1; $column{forcenotnull} = 1;
$atttype = '_' . $atttype;
} }
$column{type} = $atttype; # We use quotes for values like \0 and \054, to
$column{name} = $attname; # make sure all compilers and syntax highlighters
$column{is_varlen} = 1 if $is_varlen; # can recognize them properly.
elsif ($attopt =~ /BKI_DEFAULT\(['"]?([^'"]+)['"]?\)/)
{
$column{default} = $1;
}
elsif ($attopt =~ /BKI_LOOKUP\((\w+)\)/)
{
$column{lookup} = $1;
}
else
{
die
"unknown column option $attopt on column $attname";
}
foreach my $attopt (@attopts) if ($column{forcenull} and $column{forcenotnull})
{ {
if ($attopt eq 'BKI_FORCE_NULL') die "$attname is forced both null and not null";
{
$column{forcenull} = 1;
}
elsif ($attopt eq 'BKI_FORCE_NOT_NULL')
{
$column{forcenotnull} = 1;
}
# We use quotes for values like \0 and \054, to
# make sure all compilers and syntax highlighters
# can recognize them properly.
elsif ($attopt =~ /BKI_DEFAULT\(['"]?([^'"]+)['"]?\)/)
{
$column{default} = $1;
}
elsif ($attopt =~ /BKI_LOOKUP\((\w+)\)/)
{
$column{lookup} = $1;
}
else
{
die
"unknown column option $attopt on column $attname";
}
if ($column{forcenull} and $column{forcenotnull})
{
die "$attname is forced both null and not null";
}
} }
push @{ $catalog{columns} }, \%column;
} }
push @{ $catalog{columns} }, \%column;
} }
} }
close $ifh; }
close $ifh;
return \%catalog; return \%catalog;
} }
...@@ -228,7 +229,7 @@ sub ParseData ...@@ -228,7 +229,7 @@ sub ParseData
$input_file =~ /(\w+)\.dat$/ $input_file =~ /(\w+)\.dat$/
or die "Input file $input_file needs to be a .dat file.\n"; or die "Input file $input_file needs to be a .dat file.\n";
my $catname = $1; my $catname = $1;
my $data = []; my $data = [];
# Scan the input file. # Scan the input file.
while (<$ifd>) while (<$ifd>)
...@@ -311,8 +312,9 @@ sub AddDefaultValues ...@@ -311,8 +312,9 @@ sub AddDefaultValues
{ {
$row->{$attname} = $column->{default}; $row->{$attname} = $column->{default};
} }
elsif ($catname eq 'pg_proc' && $attname eq 'pronargs' && elsif ($catname eq 'pg_proc'
defined($row->{proargtypes})) && $attname eq 'pronargs'
&& defined($row->{proargtypes}))
{ {
# pg_proc.pronargs can be derived from proargtypes. # pg_proc.pronargs can be derived from proargtypes.
my @proargtypes = split /\s+/, $row->{proargtypes}; my @proargtypes = split /\s+/, $row->{proargtypes};
...@@ -328,7 +330,7 @@ sub AddDefaultValues ...@@ -328,7 +330,7 @@ sub AddDefaultValues
if (@missing_fields) if (@missing_fields)
{ {
die sprintf "missing values for field(s) %s in %s.dat line %s\n", die sprintf "missing values for field(s) %s in %s.dat line %s\n",
join(', ', @missing_fields), $catname, $row->{line_number}; join(', ', @missing_fields), $catname, $row->{line_number};
} }
} }
...@@ -379,7 +381,7 @@ sub FindDefinedSymbol ...@@ -379,7 +381,7 @@ sub FindDefinedSymbol
sub FindDefinedSymbolFromData sub FindDefinedSymbolFromData
{ {
my ($data, $symbol) = @_; my ($data, $symbol) = @_;
foreach my $row (@{ $data }) foreach my $row (@{$data})
{ {
if ($row->{oid_symbol} eq $symbol) if ($row->{oid_symbol} eq $symbol)
{ {
......
...@@ -116,10 +116,12 @@ foreach my $header (@input_files) ...@@ -116,10 +116,12 @@ foreach my $header (@input_files)
# within a given Postgres release, such as fixed OIDs. Do not substitute # within a given Postgres release, such as fixed OIDs. Do not substitute
# anything that could depend on platform or configuration. (The right place # anything that could depend on platform or configuration. (The right place
# to handle those sorts of things is in initdb.c's bootstrap_template1().) # to handle those sorts of things is in initdb.c's bootstrap_template1().)
my $BOOTSTRAP_SUPERUSERID = Catalog::FindDefinedSymbolFromData( my $BOOTSTRAP_SUPERUSERID =
$catalog_data{pg_authid}, 'BOOTSTRAP_SUPERUSERID'); Catalog::FindDefinedSymbolFromData($catalog_data{pg_authid},
my $PG_CATALOG_NAMESPACE = Catalog::FindDefinedSymbolFromData( 'BOOTSTRAP_SUPERUSERID');
$catalog_data{pg_namespace}, 'PG_CATALOG_NAMESPACE'); my $PG_CATALOG_NAMESPACE =
Catalog::FindDefinedSymbolFromData($catalog_data{pg_namespace},
'PG_CATALOG_NAMESPACE');
# Build lookup tables for OID macro substitutions and for pg_attribute # Build lookup tables for OID macro substitutions and for pg_attribute
...@@ -138,8 +140,7 @@ foreach my $row (@{ $catalog_data{pg_opclass} }) ...@@ -138,8 +140,7 @@ foreach my $row (@{ $catalog_data{pg_opclass} })
{ {
# There is no unique name, so we need to combine access method # There is no unique name, so we need to combine access method
# and opclass name. # and opclass name.
my $key = sprintf "%s/%s", my $key = sprintf "%s/%s", $row->{opcmethod}, $row->{opcname};
$row->{opcmethod}, $row->{opcname};
$opcoids{$key} = $row->{oid}; $opcoids{$key} = $row->{oid};
} }
...@@ -160,8 +161,7 @@ foreach my $row (@{ $catalog_data{pg_opfamily} }) ...@@ -160,8 +161,7 @@ foreach my $row (@{ $catalog_data{pg_opfamily} })
{ {
# There is no unique name, so we need to combine access method # There is no unique name, so we need to combine access method
# and opfamily name. # and opfamily name.
my $key = sprintf "%s/%s", my $key = sprintf "%s/%s", $row->{opfmethod}, $row->{opfname};
$row->{opfmethod}, $row->{opfname};
$opfoids{$key} = $row->{oid}; $opfoids{$key} = $row->{oid};
} }
...@@ -179,6 +179,7 @@ foreach my $row (@{ $catalog_data{pg_proc} }) ...@@ -179,6 +179,7 @@ foreach my $row (@{ $catalog_data{pg_proc} })
{ {
$procoids{$prokey} = $row->{oid}; $procoids{$prokey} = $row->{oid};
} }
# Also generate an entry using proname(proargtypes). This is not quite # Also generate an entry using proname(proargtypes). This is not quite
# identical to regprocedure lookup because we don't worry much about # identical to regprocedure lookup because we don't worry much about
# special SQL names for types etc; we just use the names in the source # special SQL names for types etc; we just use the names in the source
...@@ -201,7 +202,7 @@ my %types; ...@@ -201,7 +202,7 @@ my %types;
foreach my $row (@{ $catalog_data{pg_type} }) foreach my $row (@{ $catalog_data{pg_type} })
{ {
$typeoids{ $row->{typname} } = $row->{oid}; $typeoids{ $row->{typname} } = $row->{oid};
$types{ $row->{typname} } = $row; $types{ $row->{typname} } = $row;
} }
# Map catalog name to OID lookup. # Map catalog name to OID lookup.
...@@ -211,8 +212,7 @@ my %lookup_kind = ( ...@@ -211,8 +212,7 @@ my %lookup_kind = (
pg_operator => \%operoids, pg_operator => \%operoids,
pg_opfamily => \%opfoids, pg_opfamily => \%opfoids,
pg_proc => \%procoids, pg_proc => \%procoids,
pg_type => \%typeoids pg_type => \%typeoids);
);
# Generate postgres.bki, postgres.description, postgres.shdescription, # Generate postgres.bki, postgres.description, postgres.shdescription,
...@@ -345,11 +345,14 @@ EOM ...@@ -345,11 +345,14 @@ EOM
# Complain about unrecognized keys; they are presumably misspelled # Complain about unrecognized keys; they are presumably misspelled
foreach my $key (keys %bki_values) foreach my $key (keys %bki_values)
{ {
next if $key eq "oid" || $key eq "oid_symbol" || $key eq "descr" next
|| $key eq "line_number"; if $key eq "oid"
|| $key eq "oid_symbol"
|| $key eq "descr"
|| $key eq "line_number";
die sprintf "unrecognized field name \"%s\" in %s.dat line %s\n", die sprintf "unrecognized field name \"%s\" in %s.dat line %s\n",
$key, $catname, $bki_values{line_number} $key, $catname, $bki_values{line_number}
if (!exists($attnames{$key})); if (!exists($attnames{$key}));
} }
# Perform required substitutions on fields # Perform required substitutions on fields
...@@ -379,8 +382,8 @@ EOM ...@@ -379,8 +382,8 @@ EOM
if ($atttype eq 'oidvector') if ($atttype eq 'oidvector')
{ {
@lookupnames = split /\s+/, $bki_values{$attname}; @lookupnames = split /\s+/, $bki_values{$attname};
@lookupoids = lookup_oids($lookup, $catname, @lookupoids = lookup_oids($lookup, $catname, \%bki_values,
\%bki_values, @lookupnames); @lookupnames);
$bki_values{$attname} = join(' ', @lookupoids); $bki_values{$attname} = join(' ', @lookupoids);
} }
elsif ($atttype eq '_oid') elsif ($atttype eq '_oid')
...@@ -389,17 +392,18 @@ EOM ...@@ -389,17 +392,18 @@ EOM
{ {
$bki_values{$attname} =~ s/[{}]//g; $bki_values{$attname} =~ s/[{}]//g;
@lookupnames = split /,/, $bki_values{$attname}; @lookupnames = split /,/, $bki_values{$attname};
@lookupoids = lookup_oids($lookup, $catname, @lookupoids =
\%bki_values, @lookupnames); lookup_oids($lookup, $catname, \%bki_values,
$bki_values{$attname} = @lookupnames);
sprintf "{%s}", join(',', @lookupoids); $bki_values{$attname} = sprintf "{%s}",
join(',', @lookupoids);
} }
} }
else else
{ {
$lookupnames[0] = $bki_values{$attname}; $lookupnames[0] = $bki_values{$attname};
@lookupoids = lookup_oids($lookup, $catname, @lookupoids = lookup_oids($lookup, $catname, \%bki_values,
\%bki_values, @lookupnames); @lookupnames);
$bki_values{$attname} = $lookupoids[0]; $bki_values{$attname} = $lookupoids[0];
} }
} }
...@@ -562,7 +566,7 @@ sub gen_pg_attribute ...@@ -562,7 +566,7 @@ sub gen_pg_attribute
morph_row_for_schemapg(\%row, $schema); morph_row_for_schemapg(\%row, $schema);
push @{ $schemapg_entries{$table_name} }, push @{ $schemapg_entries{$table_name} },
sprintf "{ %s }", sprintf "{ %s }",
join(', ', grep { defined $_ } @row{@attnames}); join(', ', grep { defined $_ } @row{@attnames});
} }
# Generate entries for system attributes. # Generate entries for system attributes.
...@@ -589,7 +593,7 @@ sub gen_pg_attribute ...@@ -589,7 +593,7 @@ sub gen_pg_attribute
# Omit the oid column if the catalog doesn't have them # Omit the oid column if the catalog doesn't have them
next next
if $table->{without_oids} if $table->{without_oids}
&& $attr->{name} eq 'oid'; && $attr->{name} eq 'oid';
morph_row_for_pgattr(\%row, $schema, $attr, 1); morph_row_for_pgattr(\%row, $schema, $attr, 1);
print_bki_insert(\%row, $schema); print_bki_insert(\%row, $schema);
...@@ -641,11 +645,11 @@ sub morph_row_for_pgattr ...@@ -641,11 +645,11 @@ sub morph_row_for_pgattr
# compare DefineAttr in bootstrap.c. oidvector and # compare DefineAttr in bootstrap.c. oidvector and
# int2vector are also treated as not-nullable. # int2vector are also treated as not-nullable.
$row->{attnotnull} = $row->{attnotnull} =
$type->{typname} eq 'oidvector' ? 't' $type->{typname} eq 'oidvector' ? 't'
: $type->{typname} eq 'int2vector' ? 't' : $type->{typname} eq 'int2vector' ? 't'
: $type->{typlen} eq 'NAMEDATALEN' ? 't' : $type->{typlen} eq 'NAMEDATALEN' ? 't'
: $type->{typlen} > 0 ? 't' : $type->{typlen} > 0 ? 't'
: 'f'; : 'f';
} }
else else
{ {
...@@ -686,7 +690,7 @@ sub print_bki_insert ...@@ -686,7 +690,7 @@ sub print_bki_insert
# the "id" pattern in bootscanner.l, currently "[-A-Za-z0-9_]+". # the "id" pattern in bootscanner.l, currently "[-A-Za-z0-9_]+".
$bki_value = sprintf(qq'"%s"', $bki_value) $bki_value = sprintf(qq'"%s"', $bki_value)
if length($bki_value) == 0 if length($bki_value) == 0
or $bki_value =~ /[^-A-Za-z0-9_]/; or $bki_value =~ /[^-A-Za-z0-9_]/;
push @bki_values, $bki_value; push @bki_values, $bki_value;
} }
...@@ -725,7 +729,7 @@ sub morph_row_for_schemapg ...@@ -725,7 +729,7 @@ sub morph_row_for_schemapg
# don't change. # don't change.
elsif ($atttype eq 'bool') elsif ($atttype eq 'bool')
{ {
$row->{$attname} = 'true' if $row->{$attname} eq 't'; $row->{$attname} = 'true' if $row->{$attname} eq 't';
$row->{$attname} = 'false' if $row->{$attname} eq 'f'; $row->{$attname} = 'false' if $row->{$attname} eq 'f';
} }
...@@ -756,9 +760,10 @@ sub lookup_oids ...@@ -756,9 +760,10 @@ sub lookup_oids
else else
{ {
push @lookupoids, $lookupname; push @lookupoids, $lookupname;
warn sprintf "unresolved OID reference \"%s\" in %s.dat line %s\n", warn sprintf
$lookupname, $catname, $bki_values->{line_number} "unresolved OID reference \"%s\" in %s.dat line %s\n",
if $lookupname ne '-' and $lookupname ne '0'; $lookupname, $catname, $bki_values->{line_number}
if $lookupname ne '-' and $lookupname ne '0';
} }
} }
return @lookupoids; return @lookupoids;
...@@ -772,10 +777,10 @@ sub form_pg_type_symbol ...@@ -772,10 +777,10 @@ sub form_pg_type_symbol
# Skip for rowtypes of bootstrap catalogs, since they have their # Skip for rowtypes of bootstrap catalogs, since they have their
# own naming convention defined elsewhere. # own naming convention defined elsewhere.
return return
if $typename eq 'pg_type' if $typename eq 'pg_type'
or $typename eq 'pg_proc' or $typename eq 'pg_proc'
or $typename eq 'pg_attribute' or $typename eq 'pg_attribute'
or $typename eq 'pg_class'; or $typename eq 'pg_class';
# Transform like so: # Transform like so:
# foo_bar -> FOO_BAROID # foo_bar -> FOO_BAROID
......
...@@ -68,7 +68,7 @@ foreach my $datfile (@input_files) ...@@ -68,7 +68,7 @@ foreach my $datfile (@input_files)
my $header = "$1.h"; my $header = "$1.h";
die "There in no header file corresponding to $datfile" die "There in no header file corresponding to $datfile"
if ! -e $header; if !-e $header;
my $catalog = Catalog::ParseHeader($header); my $catalog = Catalog::ParseHeader($header);
my $catname = $catalog->{catname}; my $catname = $catalog->{catname};
...@@ -79,10 +79,12 @@ foreach my $datfile (@input_files) ...@@ -79,10 +79,12 @@ foreach my $datfile (@input_files)
} }
# Fetch some values for later. # Fetch some values for later.
my $FirstBootstrapObjectId = Catalog::FindDefinedSymbol( my $FirstBootstrapObjectId =
'access/transam.h', \@include_path, 'FirstBootstrapObjectId'); Catalog::FindDefinedSymbol('access/transam.h', \@include_path,
my $INTERNALlanguageId = Catalog::FindDefinedSymbolFromData( 'FirstBootstrapObjectId');
$catalog_data{pg_language}, 'INTERNALlanguageId'); my $INTERNALlanguageId =
Catalog::FindDefinedSymbolFromData($catalog_data{pg_language},
'INTERNALlanguageId');
print "Generating fmgrtab.c, fmgroids.h, and fmgrprotos.h...\n"; print "Generating fmgrtab.c, fmgroids.h, and fmgrprotos.h...\n";
...@@ -230,7 +232,7 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) ...@@ -230,7 +232,7 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
print $tfh print $tfh
" { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} }"; " { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} }";
$fmgr_builtin_oid_index[$s->{oid}] = $fmgr_count++; $fmgr_builtin_oid_index[ $s->{oid} ] = $fmgr_count++;
if ($fmgr_count <= $#fmgr) if ($fmgr_count <= $#fmgr)
{ {
......
...@@ -49,12 +49,13 @@ mkdir $datadir; ...@@ -49,12 +49,13 @@ mkdir $datadir;
'successful creation'); 'successful creation');
# Permissions on PGDATA should be default # Permissions on PGDATA should be default
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 1 if ($windows_os); skip "unix-style permissions not supported on Windows", 1
if ($windows_os);
ok(check_mode_recursive($datadir, 0700, 0600), ok(check_mode_recursive($datadir, 0700, 0600),
"check PGDATA permissions"); "check PGDATA permissions");
} }
} }
command_ok([ 'initdb', '-S', $datadir ], 'sync only'); command_ok([ 'initdb', '-S', $datadir ], 'sync only');
...@@ -63,7 +64,8 @@ command_fails([ 'initdb', $datadir ], 'existing data directory'); ...@@ -63,7 +64,8 @@ command_fails([ 'initdb', $datadir ], 'existing data directory');
# Check group access on PGDATA # Check group access on PGDATA
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 2 if ($windows_os); skip "unix-style permissions not supported on Windows", 2
if ($windows_os);
# Init a new db with group access # Init a new db with group access
my $datadir_group = "$tempdir/data_group"; my $datadir_group = "$tempdir/data_group";
......
...@@ -10,11 +10,8 @@ program_options_handling_ok('pg_archivecleanup'); ...@@ -10,11 +10,8 @@ program_options_handling_ok('pg_archivecleanup');
my $tempdir = TestLib::tempdir; my $tempdir = TestLib::tempdir;
my @walfiles = ( my @walfiles = (
'00000001000000370000000C.gz', '00000001000000370000000C.gz', '00000001000000370000000D',
'00000001000000370000000D', '00000001000000370000000E', '00000001000000370000000F.partial',);
'00000001000000370000000E',
'00000001000000370000000F.partial',
);
sub create_files sub create_files
{ {
...@@ -28,32 +25,41 @@ sub create_files ...@@ -28,32 +25,41 @@ sub create_files
create_files(); create_files();
command_fails_like(['pg_archivecleanup'], command_fails_like(
qr/must specify archive location/, ['pg_archivecleanup'],
'fails if archive location is not specified'); qr/must specify archive location/,
'fails if archive location is not specified');
command_fails_like(['pg_archivecleanup', $tempdir], command_fails_like(
qr/must specify oldest kept WAL file/, [ 'pg_archivecleanup', $tempdir ],
'fails if oldest kept WAL file name is not specified'); qr/must specify oldest kept WAL file/,
'fails if oldest kept WAL file name is not specified');
command_fails_like(['pg_archivecleanup', 'notexist', 'foo'], command_fails_like(
qr/archive location .* does not exist/, [ 'pg_archivecleanup', 'notexist', 'foo' ],
'fails if archive location does not exist'); qr/archive location .* does not exist/,
'fails if archive location does not exist');
command_fails_like(['pg_archivecleanup', $tempdir, 'foo', 'bar'], command_fails_like(
qr/too many command-line arguments/, [ 'pg_archivecleanup', $tempdir, 'foo', 'bar' ],
'fails with too many command-line arguments'); qr/too many command-line arguments/,
'fails with too many command-line arguments');
command_fails_like(['pg_archivecleanup', $tempdir, 'foo'], command_fails_like(
qr/invalid file name argument/, [ 'pg_archivecleanup', $tempdir, 'foo' ],
'fails with invalid restart file name'); qr/invalid file name argument/,
'fails with invalid restart file name');
{ {
# like command_like but checking stderr # like command_like but checking stderr
my $stderr; my $stderr;
my $result = IPC::Run::run ['pg_archivecleanup', '-d', '-n', $tempdir, $walfiles[2]], '2>', \$stderr; my $result = IPC::Run::run [ 'pg_archivecleanup', '-d', '-n', $tempdir,
$walfiles[2] ], '2>', \$stderr;
ok($result, "pg_archivecleanup dry run: exit code 0"); ok($result, "pg_archivecleanup dry run: exit code 0");
like($stderr, qr/$walfiles[1].*would be removed/, "pg_archivecleanup dry run: matches"); like(
$stderr,
qr/$walfiles[1].*would be removed/,
"pg_archivecleanup dry run: matches");
foreach my $fn (@walfiles) foreach my $fn (@walfiles)
{ {
ok(-f "$tempdir/$fn", "$fn not removed"); ok(-f "$tempdir/$fn", "$fn not removed");
...@@ -66,16 +72,23 @@ sub run_check ...@@ -66,16 +72,23 @@ sub run_check
create_files(); create_files();
command_ok(['pg_archivecleanup', '-x', '.gz', $tempdir, $walfiles[2] . $suffix], command_ok(
"$test_name: runs"); [ 'pg_archivecleanup', '-x', '.gz', $tempdir,
$walfiles[2] . $suffix ],
ok(! -f "$tempdir/$walfiles[0]", "$test_name: first older WAL file was cleaned up"); "$test_name: runs");
ok(! -f "$tempdir/$walfiles[1]", "$test_name: second older WAL file was cleaned up");
ok(-f "$tempdir/$walfiles[2]", "$test_name: restartfile was not cleaned up"); ok(!-f "$tempdir/$walfiles[0]",
ok(-f "$tempdir/$walfiles[3]", "$test_name: newer WAL file was not cleaned up"); "$test_name: first older WAL file was cleaned up");
ok(-f "$tempdir/unrelated_file", "$test_name: unrelated file was not cleaned up"); ok(!-f "$tempdir/$walfiles[1]",
"$test_name: second older WAL file was cleaned up");
ok(-f "$tempdir/$walfiles[2]",
"$test_name: restartfile was not cleaned up");
ok(-f "$tempdir/$walfiles[3]",
"$test_name: newer WAL file was not cleaned up");
ok(-f "$tempdir/unrelated_file",
"$test_name: unrelated file was not cleaned up");
} }
run_check('', 'pg_archivecleanup'); run_check('', 'pg_archivecleanup');
run_check('.partial', 'pg_archivecleanup with .partial file'); run_check('.partial', 'pg_archivecleanup with .partial file');
run_check('.00000020.backup', 'pg_archivecleanup with .backup file'); run_check('.00000020.backup', 'pg_archivecleanup with .backup file');
...@@ -41,7 +41,8 @@ is($slot->{'slot_type'}, 'physical', 'physical replication slot was created'); ...@@ -41,7 +41,8 @@ is($slot->{'slot_type'}, 'physical', 'physical replication slot was created');
is($slot->{'restart_lsn'}, '', 'restart LSN of new slot is null'); is($slot->{'restart_lsn'}, '', 'restart LSN of new slot is null');
$primary->command_ok([ 'pg_receivewal', '--slot', $slot_name, '--drop-slot' ], $primary->command_ok([ 'pg_receivewal', '--slot', $slot_name, '--drop-slot' ],
'dropping a replication slot'); 'dropping a replication slot');
is($primary->slot($slot_name)->{'slot_type'}, '', 'replication slot was removed'); is($primary->slot($slot_name)->{'slot_type'},
'', 'replication slot was removed');
# Generate some WAL. Use --synchronous at the same time to add more # Generate some WAL. Use --synchronous at the same time to add more
# code coverage. Switch to the next segment first so that subsequent # code coverage. Switch to the next segment first so that subsequent
...@@ -63,8 +64,9 @@ $primary->command_ok( ...@@ -63,8 +64,9 @@ $primary->command_ok(
# Permissions on WAL files should be default # Permissions on WAL files should be default
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 1 if ($windows_os); skip "unix-style permissions not supported on Windows", 1
if ($windows_os);
ok(check_mode_recursive($stream_dir, 0700, 0600), ok(check_mode_recursive($stream_dir, 0700, 0600),
"check stream dir permissions"); "check stream dir permissions");
} }
...@@ -21,17 +21,20 @@ command_like([ 'pg_controldata', $node->data_dir ], ...@@ -21,17 +21,20 @@ command_like([ 'pg_controldata', $node->data_dir ],
# check with a corrupted pg_control # check with a corrupted pg_control
my $pg_control = $node->data_dir . '/global/pg_control'; my $pg_control = $node->data_dir . '/global/pg_control';
my $size = (stat($pg_control))[7]; my $size = (stat($pg_control))[7];
open my $fh, '>', $pg_control or BAIL_OUT($!); open my $fh, '>', $pg_control or BAIL_OUT($!);
binmode $fh; binmode $fh;
# fill file with zeros # fill file with zeros
print $fh pack("x[$size]"); print $fh pack("x[$size]");
close $fh; close $fh;
command_checks_all([ 'pg_controldata', $node->data_dir ], command_checks_all(
0, [ 'pg_controldata', $node->data_dir ],
[ qr/WARNING: Calculated CRC checksum does not match value stored in file/, 0,
qr/WARNING: invalid WAL segment size/ ], [
[ qr/^$/ ], qr/WARNING: Calculated CRC checksum does not match value stored in file/,
'pg_controldata with corrupted pg_control'); qr/WARNING: invalid WAL segment size/ ],
[qr/^$/],
'pg_controldata with corrupted pg_control');
...@@ -63,14 +63,14 @@ command_fails([ 'pg_ctl', 'stop', '-D', "$tempdir/data" ], ...@@ -63,14 +63,14 @@ command_fails([ 'pg_ctl', 'stop', '-D', "$tempdir/data" ],
# Windows but we still want to do the restart test. # Windows but we still want to do the restart test.
my $logFileName = "$tempdir/data/perm-test-600.log"; my $logFileName = "$tempdir/data/perm-test-600.log";
command_ok( command_ok([ 'pg_ctl', 'restart', '-D', "$tempdir/data", '-l', $logFileName ],
[ 'pg_ctl', 'restart', '-D', "$tempdir/data", '-l', $logFileName ],
'pg_ctl restart with server not running'); 'pg_ctl restart with server not running');
# Permissions on log file should be default # Permissions on log file should be default
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 2 if ($windows_os); skip "unix-style permissions not supported on Windows", 2
if ($windows_os);
ok(-f $logFileName); ok(-f $logFileName);
ok(check_mode_recursive("$tempdir/data", 0700, 0600)); ok(check_mode_recursive("$tempdir/data", 0700, 0600));
......
This diff is collapsed.
...@@ -13,14 +13,14 @@ my $node = get_new_node('main'); ...@@ -13,14 +13,14 @@ my $node = get_new_node('main');
$node->init; $node->init;
command_like([ 'pg_resetwal', '-n', $node->data_dir ], command_like([ 'pg_resetwal', '-n', $node->data_dir ],
qr/checkpoint/, qr/checkpoint/, 'pg_resetwal -n produces output');
'pg_resetwal -n produces output');
# Permissions on PGDATA should be default # Permissions on PGDATA should be default
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 1 if ($windows_os); skip "unix-style permissions not supported on Windows", 1
if ($windows_os);
ok(check_mode_recursive($node->data_dir, 0700, 0600), ok(check_mode_recursive($node->data_dir, 0700, 0600),
'check PGDATA permissions'); 'check PGDATA permissions');
......
...@@ -11,7 +11,7 @@ my $node = get_new_node('main'); ...@@ -11,7 +11,7 @@ my $node = get_new_node('main');
$node->init; $node->init;
my $pg_control = $node->data_dir . '/global/pg_control'; my $pg_control = $node->data_dir . '/global/pg_control';
my $size = (stat($pg_control))[7]; my $size = (stat($pg_control))[7];
# Read out the head of the file to get PG_CONTROL_VERSION in # Read out the head of the file to get PG_CONTROL_VERSION in
# particular. # particular.
...@@ -27,11 +27,14 @@ binmode $fh; ...@@ -27,11 +27,14 @@ binmode $fh;
print $fh pack("x[$size]"); print $fh pack("x[$size]");
close $fh; close $fh;
command_checks_all([ 'pg_resetwal', '-n', $node->data_dir ], command_checks_all(
0, [ 'pg_resetwal', '-n', $node->data_dir ],
[ qr/pg_control version number/ ], 0,
[ qr/pg_resetwal: pg_control exists but is broken or wrong version; ignoring it/ ], [qr/pg_control version number/],
'processes corrupted pg_control all zeroes'); [
qr/pg_resetwal: pg_control exists but is broken or wrong version; ignoring it/
],
'processes corrupted pg_control all zeroes');
# Put in the previously saved header data. This uses a different code # Put in the previously saved header data. This uses a different code
# path internally, allowing us to process a zero WAL segment size. # path internally, allowing us to process a zero WAL segment size.
...@@ -40,8 +43,11 @@ binmode $fh; ...@@ -40,8 +43,11 @@ binmode $fh;
print $fh $data, pack("x[" . ($size - 16) . "]"); print $fh $data, pack("x[" . ($size - 16) . "]");
close $fh; close $fh;
command_checks_all([ 'pg_resetwal', '-n', $node->data_dir ], command_checks_all(
0, [ 'pg_resetwal', '-n', $node->data_dir ],
[ qr/pg_control version number/ ], 0,
[ qr/\Qpg_resetwal: pg_control specifies invalid WAL segment size (0 bytes); proceed with caution\E/ ], [qr/pg_control version number/],
'processes zero WAL segment size'); [
qr/\Qpg_resetwal: pg_control specifies invalid WAL segment size (0 bytes); proceed with caution\E/
],
'processes zero WAL segment size');
...@@ -115,16 +115,18 @@ sub check_query ...@@ -115,16 +115,18 @@ sub check_query
sub setup_cluster sub setup_cluster
{ {
my $extra_name = shift; # Used to differentiate clusters my $extra_name = shift; # Used to differentiate clusters
my $extra = shift; # Extra params for initdb my $extra = shift; # Extra params for initdb
# Initialize master, data checksums are mandatory # Initialize master, data checksums are mandatory
$node_master = get_new_node('master' . ($extra_name ? "_${extra_name}" : '')); $node_master =
$node_master->init( get_new_node('master' . ($extra_name ? "_${extra_name}" : ''));
allows_streaming => 1, extra => $extra); $node_master->init(allows_streaming => 1, extra => $extra);
# Set wal_keep_segments to prevent WAL segment recycling after enforced # Set wal_keep_segments to prevent WAL segment recycling after enforced
# checkpoints in the tests. # checkpoints in the tests.
$node_master->append_conf('postgresql.conf', qq( $node_master->append_conf(
'postgresql.conf', qq(
wal_keep_segments = 20 wal_keep_segments = 20
)); ));
} }
...@@ -141,7 +143,8 @@ sub create_standby ...@@ -141,7 +143,8 @@ sub create_standby
{ {
my $extra_name = shift; my $extra_name = shift;
$node_standby = get_new_node('standby' . ($extra_name ? "_${extra_name}" : '')); $node_standby =
get_new_node('standby' . ($extra_name ? "_${extra_name}" : ''));
$node_master->backup('my_backup'); $node_master->backup('my_backup');
$node_standby->init_from_backup($node_master, 'my_backup'); $node_standby->init_from_backup($node_master, 'my_backup');
my $connstr_master = $node_master->connstr(); my $connstr_master = $node_master->connstr();
...@@ -239,10 +242,11 @@ sub run_pg_rewind ...@@ -239,10 +242,11 @@ sub run_pg_rewind
"$tmp_folder/master-postgresql.conf.tmp", "$tmp_folder/master-postgresql.conf.tmp",
"$master_pgdata/postgresql.conf"); "$master_pgdata/postgresql.conf");
chmod($node_master->group_access() ? 0640 : 0600, chmod(
"$master_pgdata/postgresql.conf") $node_master->group_access() ? 0640 : 0600,
or BAIL_OUT( "$master_pgdata/postgresql.conf")
"unable to set permissions for $master_pgdata/postgresql.conf"); or BAIL_OUT(
"unable to set permissions for $master_pgdata/postgresql.conf");
# Plug-in rewound node to the now-promoted standby node # Plug-in rewound node to the now-promoted standby node
my $port_standby = $node_standby->port; my $port_standby = $node_standby->port;
......
...@@ -87,9 +87,10 @@ in master, before promotion ...@@ -87,9 +87,10 @@ in master, before promotion
'tail-copy'); 'tail-copy');
# Permissions on PGDATA should be default # Permissions on PGDATA should be default
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 1 if ($windows_os); skip "unix-style permissions not supported on Windows", 1
if ($windows_os);
ok(check_mode_recursive($node_master->data_dir(), 0700, 0600), ok(check_mode_recursive($node_master->data_dir(), 0700, 0600),
'check PGDATA permissions'); 'check PGDATA permissions');
......
...@@ -43,9 +43,10 @@ template1 ...@@ -43,9 +43,10 @@ template1
'database names'); 'database names');
# Permissions on PGDATA should have group permissions # Permissions on PGDATA should have group permissions
SKIP: SKIP:
{ {
skip "unix-style permissions not supported on Windows", 1 if ($windows_os); skip "unix-style permissions not supported on Windows", 1
if ($windows_os);
ok(check_mode_recursive($node_master->data_dir(), 0750, 0640), ok(check_mode_recursive($node_master->data_dir(), 0750, 0640),
'check PGDATA permissions'); 'check PGDATA permissions');
......
...@@ -81,8 +81,10 @@ pgbench( ...@@ -81,8 +81,10 @@ pgbench(
# Initialize pgbench tables scale 1 # Initialize pgbench tables scale 1
pgbench( pgbench(
'-i', 0, [qr{^$}], '-i', 0,
[ qr{creating tables}, qr{vacuuming}, qr{creating primary keys}, qr{done\.} ], [qr{^$}],
[ qr{creating tables}, qr{vacuuming},
qr{creating primary keys}, qr{done\.} ],
'pgbench scale 1 initialization',); 'pgbench scale 1 initialization',);
# Again, with all possible options # Again, with all possible options
...@@ -100,8 +102,9 @@ pgbench( ...@@ -100,8 +102,9 @@ pgbench(
# Test interaction of --init-steps with legacy step-selection options # Test interaction of --init-steps with legacy step-selection options
pgbench( pgbench(
'--initialize --init-steps=dtpvgvv --no-vacuum --foreign-keys --unlogged-tables', '--initialize --init-steps=dtpvgvv --no-vacuum --foreign-keys --unlogged-tables',
0, [qr{^$}], 0,
[qr{^$}],
[ qr{dropping old tables}, [ qr{dropping old tables},
qr{creating tables}, qr{creating tables},
qr{creating primary keys}, qr{creating primary keys},
...@@ -218,15 +221,16 @@ COMMIT; ...@@ -218,15 +221,16 @@ COMMIT;
# test expressions # test expressions
# command 1..3 and 23 depend on random seed which is used to call srandom. # command 1..3 and 23 depend on random seed which is used to call srandom.
pgbench( pgbench(
'--random-seed=5432 -t 1 -Dfoo=-10.1 -Dbla=false -Di=+3 -Dminint=-9223372036854775808 -Dn=null -Dt=t -Df=of -Dd=1.0', '--random-seed=5432 -t 1 -Dfoo=-10.1 -Dbla=false -Di=+3 -Dminint=-9223372036854775808 -Dn=null -Dt=t -Df=of -Dd=1.0',
0, 0,
[ qr{type: .*/001_pgbench_expressions}, qr{processed: 1/1} ], [ qr{type: .*/001_pgbench_expressions}, qr{processed: 1/1} ],
[ qr{setting random seed to 5432\b}, [ qr{setting random seed to 5432\b},
# After explicit seeding, the four * random checks (1-3,20) should be # After explicit seeding, the four * random checks (1-3,20) should be
# deterministic, but not necessarily portable. # deterministic, but not necessarily portable.
qr{command=1.: int 1\d\b}, # uniform random: 12 on linux qr{command=1.: int 1\d\b}, # uniform random: 12 on linux
qr{command=2.: int 1\d\d\b}, # exponential random: 106 on linux qr{command=2.: int 1\d\d\b}, # exponential random: 106 on linux
qr{command=3.: int 1\d\d\d\b}, # gaussian random: 1462 on linux qr{command=3.: int 1\d\d\d\b}, # gaussian random: 1462 on linux
qr{command=4.: int 4\b}, qr{command=4.: int 4\b},
qr{command=5.: int 5\b}, qr{command=5.: int 5\b},
qr{command=6.: int 6\b}, qr{command=6.: int 6\b},
...@@ -240,7 +244,7 @@ pgbench( ...@@ -240,7 +244,7 @@ pgbench(
qr{command=16.: double 16\b}, qr{command=16.: double 16\b},
qr{command=17.: double 17\b}, qr{command=17.: double 17\b},
qr{command=18.: int 9223372036854775807\b}, qr{command=18.: int 9223372036854775807\b},
qr{command=20.: int \d\b}, # zipfian random: 1 on linux qr{command=20.: int \d\b}, # zipfian random: 1 on linux
qr{command=21.: double -27\b}, qr{command=21.: double -27\b},
qr{command=22.: double 1024\b}, qr{command=22.: double 1024\b},
qr{command=23.: double 1\b}, qr{command=23.: double 1\b},
...@@ -280,9 +284,9 @@ pgbench( ...@@ -280,9 +284,9 @@ pgbench(
qr{command=86.: int 86\b}, qr{command=86.: int 86\b},
qr{command=93.: int 93\b}, qr{command=93.: int 93\b},
qr{command=95.: int 0\b}, qr{command=95.: int 0\b},
qr{command=96.: int 1\b}, # :scale qr{command=96.: int 1\b}, # :scale
qr{command=97.: int 0\b}, # :client_id qr{command=97.: int 0\b}, # :client_id
qr{command=98.: int 5432\b}, # :random_seed qr{command=98.: int 5432\b}, # :random_seed
], ],
'pgbench expressions', 'pgbench expressions',
{ '001_pgbench_expressions' => q{-- integer functions { '001_pgbench_expressions' => q{-- integer functions
...@@ -411,18 +415,20 @@ SELECT :v0, :v1, :v2, :v3; ...@@ -411,18 +415,20 @@ SELECT :v0, :v1, :v2, :v3;
# random determinism when seeded # random determinism when seeded
$node->safe_psql('postgres', $node->safe_psql('postgres',
'CREATE UNLOGGED TABLE seeded_random(seed INT8 NOT NULL, rand TEXT NOT NULL, val INTEGER NOT NULL);'); 'CREATE UNLOGGED TABLE seeded_random(seed INT8 NOT NULL, rand TEXT NOT NULL, val INTEGER NOT NULL);'
);
# same value to check for determinism # same value to check for determinism
my $seed = int(rand(1000000000)); my $seed = int(rand(1000000000));
for my $i (1, 2) for my $i (1, 2)
{ {
pgbench("--random-seed=$seed -t 1", pgbench(
0, "--random-seed=$seed -t 1",
[qr{processed: 1/1}], 0,
[qr{setting random seed to $seed\b}], [qr{processed: 1/1}],
"random seeded with $seed", [qr{setting random seed to $seed\b}],
{ "001_pgbench_random_seed_$i" => q{-- test random functions "random seeded with $seed",
{ "001_pgbench_random_seed_$i" => q{-- test random functions
\set ur random(1000, 1999) \set ur random(1000, 1999)
\set er random_exponential(2000, 2999, 2.0) \set er random_exponential(2000, 2999, 2.0)
\set gr random_gaussian(3000, 3999, 3.0) \set gr random_gaussian(3000, 3999, 3.0)
...@@ -436,16 +442,20 @@ INSERT INTO seeded_random(seed, rand, val) VALUES ...@@ -436,16 +442,20 @@ INSERT INTO seeded_random(seed, rand, val) VALUES
} }
# check that all runs generated the same 4 values # check that all runs generated the same 4 values
my ($ret, $out, $err) = my ($ret, $out, $err) = $node->psql('postgres',
$node->psql('postgres', 'SELECT seed, rand, val, COUNT(*) FROM seeded_random GROUP BY seed, rand, val'
'SELECT seed, rand, val, COUNT(*) FROM seeded_random GROUP BY seed, rand, val'); );
ok($ret == 0, "psql seeded_random count ok"); ok($ret == 0, "psql seeded_random count ok");
ok($err eq '', "psql seeded_random count stderr is empty"); ok($err eq '', "psql seeded_random count stderr is empty");
ok($out =~ /\b$seed\|uniform\|1\d\d\d\|2/, "psql seeded_random count uniform"); ok($out =~ /\b$seed\|uniform\|1\d\d\d\|2/,
ok($out =~ /\b$seed\|exponential\|2\d\d\d\|2/, "psql seeded_random count exponential"); "psql seeded_random count uniform");
ok($out =~ /\b$seed\|gaussian\|3\d\d\d\|2/, "psql seeded_random count gaussian"); ok( $out =~ /\b$seed\|exponential\|2\d\d\d\|2/,
ok($out =~ /\b$seed\|zipfian\|4\d\d\d\|2/, "psql seeded_random count zipfian"); "psql seeded_random count exponential");
ok( $out =~ /\b$seed\|gaussian\|3\d\d\d\|2/,
"psql seeded_random count gaussian");
ok($out =~ /\b$seed\|zipfian\|4\d\d\d\|2/,
"psql seeded_random count zipfian");
$node->safe_psql('postgres', 'DROP TABLE seeded_random;'); $node->safe_psql('postgres', 'DROP TABLE seeded_random;');
...@@ -481,8 +491,8 @@ my @errors = ( ...@@ -481,8 +491,8 @@ my @errors = (
# SQL # SQL
[ 'sql syntax error', [ 'sql syntax error',
0, 0,
[ qr{ERROR: syntax error}, qr{prepared statement .* does not exist} [ qr{ERROR: syntax error},
], qr{prepared statement .* does not exist} ],
q{-- SQL syntax error q{-- SQL syntax error
SELECT 1 + ; SELECT 1 + ;
} ], } ],
...@@ -493,7 +503,7 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i); ...@@ -493,7 +503,7 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i);
} ], } ],
# SHELL # SHELL
[ 'shell bad command', 0, [ 'shell bad command', 0,
[qr{\(shell\) .* meta-command failed}], q{\shell no-such-command} ], [qr{\(shell\) .* meta-command failed}], q{\shell no-such-command} ],
[ 'shell undefined variable', 0, [ 'shell undefined variable', 0,
[qr{undefined variable ":nosuchvariable"}], [qr{undefined variable ":nosuchvariable"}],
...@@ -557,52 +567,34 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i); ...@@ -557,52 +567,34 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i);
0, 0,
[qr{exponential parameter must be greater }], [qr{exponential parameter must be greater }],
q{\set i random_exponential(0, 10, 0.0)} ], q{\set i random_exponential(0, 10, 0.0)} ],
[ 'set zipfian param to 1', [ 'set zipfian param to 1',
0, 0,
[qr{zipfian parameter must be in range \(0, 1\) U \(1, \d+\]}], [qr{zipfian parameter must be in range \(0, 1\) U \(1, \d+\]}],
q{\set i random_zipfian(0, 10, 1)} ], q{\set i random_zipfian(0, 10, 1)} ],
[ 'set zipfian param too large', [ 'set zipfian param too large',
0, 0,
[qr{zipfian parameter must be in range \(0, 1\) U \(1, \d+\]}], [qr{zipfian parameter must be in range \(0, 1\) U \(1, \d+\]}],
q{\set i random_zipfian(0, 10, 1000000)} ], q{\set i random_zipfian(0, 10, 1000000)} ],
[ 'set non numeric value', 0, [ 'set non numeric value', 0,
[qr{malformed variable "foo" value: "bla"}], q{\set i :foo + 1} ], [qr{malformed variable "foo" value: "bla"}], q{\set i :foo + 1} ],
[ 'set no expression', [ 'set no expression', 1, [qr{syntax error}], q{\set i} ],
1, [ 'set missing argument', 1, [qr{missing argument}i], q{\set} ],
[qr{syntax error}], [ 'set not a bool', 0,
q{\set i} ], [qr{cannot coerce double to boolean}], q{\set b NOT 0.0} ],
[ 'set missing argument', [ 'set not an int', 0,
[qr{cannot coerce boolean to int}], q{\set i TRUE + 2} ],
[ 'set not a double', 0,
[qr{cannot coerce boolean to double}], q{\set d ln(TRUE)} ],
[ 'set case error',
1, 1,
[qr{missing argument}i], [qr{syntax error in command "set"}],
q{\set} ],
[ 'set not a bool',
0,
[ qr{cannot coerce double to boolean} ],
q{\set b NOT 0.0} ],
[ 'set not an int',
0,
[ qr{cannot coerce boolean to int} ],
q{\set i TRUE + 2} ],
[ 'set not a double',
0,
[ qr{cannot coerce boolean to double} ],
q{\set d ln(TRUE)} ],
[ 'set case error',
1,
[ qr{syntax error in command "set"} ],
q{\set i CASE TRUE THEN 1 ELSE 0 END} ], q{\set i CASE TRUE THEN 1 ELSE 0 END} ],
[ 'set random error', [ 'set random error', 0,
0, [qr{cannot coerce boolean to int}], q{\set b random(FALSE, TRUE)} ],
[ qr{cannot coerce boolean to int} ], [ 'set number of args mismatch', 1,
q{\set b random(FALSE, TRUE)} ], [qr{unexpected number of arguments}], q{\set d ln(1.0, 2.0))} ],
[ 'set number of args mismatch', [ 'set at least one arg', 1,
1, [qr{at least one argument expected}], q{\set i greatest())} ],
[ qr{unexpected number of arguments} ],
q{\set d ln(1.0, 2.0))} ],
[ 'set at least one arg',
1,
[ qr{at least one argument expected} ],
q{\set i greatest())} ],
# SETSHELL # SETSHELL
[ 'setshell not an int', 0, [ 'setshell not an int', 0,
...@@ -625,8 +617,8 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i); ...@@ -625,8 +617,8 @@ SELECT LEAST(:i, :i, :i, :i, :i, :i, :i, :i, :i, :i, :i);
[ 'misc invalid backslash command', 1, [ 'misc invalid backslash command', 1,
[qr{invalid command .* "nosuchcommand"}], q{\nosuchcommand} ], [qr{invalid command .* "nosuchcommand"}], q{\nosuchcommand} ],
[ 'misc empty script', 1, [qr{empty command list for script}], q{} ], [ 'misc empty script', 1, [qr{empty command list for script}], q{} ],
[ 'bad boolean', 0, [qr{malformed variable.*trueXXX}], q{\set b :badtrue or true} ], [ 'bad boolean', 0,
); [qr{malformed variable.*trueXXX}], q{\set b :badtrue or true} ],);
for my $e (@errors) for my $e (@errors)
...@@ -635,7 +627,7 @@ for my $e (@errors) ...@@ -635,7 +627,7 @@ for my $e (@errors)
my $n = '001_pgbench_error_' . $name; my $n = '001_pgbench_error_' . $name;
$n =~ s/ /_/g; $n =~ s/ /_/g;
pgbench( pgbench(
'-n -t 1 -Dfoo=bla -Dnull=null -Dtrue=true -Done=1 -Dzero=0.0 -Dbadtrue=trueXXX -M prepared', '-n -t 1 -Dfoo=bla -Dnull=null -Dtrue=true -Done=1 -Dzero=0.0 -Dbadtrue=trueXXX -M prepared',
$status, $status,
[ $status ? qr{^$} : qr{processed: 0/1} ], [ $status ? qr{^$} : qr{processed: 0/1} ],
$re, $re,
...@@ -647,7 +639,7 @@ for my $e (@errors) ...@@ -647,7 +639,7 @@ for my $e (@errors)
pgbench( pgbench(
'-t 1', 0, '-t 1', 0,
[ qr{processed: 1/1}, qr{zipfian cache array overflowed 1 time\(s\)} ], [ qr{processed: 1/1}, qr{zipfian cache array overflowed 1 time\(s\)} ],
[ qr{^} ], [qr{^}],
'pgbench zipfian array overflow on random_zipfian', 'pgbench zipfian array overflow on random_zipfian',
{ '001_pgbench_random_zipfian' => q{ { '001_pgbench_random_zipfian' => q{
\set i random_zipfian(1, 100, 0.5) \set i random_zipfian(1, 100, 0.5)
......
...@@ -15,8 +15,7 @@ $testname =~ s/\.pl$//; ...@@ -15,8 +15,7 @@ $testname =~ s/\.pl$//;
my $testdir = "$TestLib::tmp_check/t_${testname}_stuff"; my $testdir = "$TestLib::tmp_check/t_${testname}_stuff";
mkdir $testdir mkdir $testdir
or or BAIL_OUT("could not create test directory \"${testdir}\": $!");
BAIL_OUT("could not create test directory \"${testdir}\": $!");
# invoke pgbench # invoke pgbench
sub pgbench sub pgbench
...@@ -38,8 +37,10 @@ sub pgbench_scripts ...@@ -38,8 +37,10 @@ sub pgbench_scripts
for my $fn (sort keys %$files) for my $fn (sort keys %$files)
{ {
my $filename = $testdir . '/' . $fn; my $filename = $testdir . '/' . $fn;
# cleanup file weight if any # cleanup file weight if any
$filename =~ s/\@\d+$//; $filename =~ s/\@\d+$//;
# cleanup from prior runs # cleanup from prior runs
unlink $filename; unlink $filename;
append_to_file($filename, $$files{$fn}); append_to_file($filename, $$files{$fn});
...@@ -105,14 +106,17 @@ my @options = ( ...@@ -105,14 +106,17 @@ my @options = (
[ 'ambiguous builtin', '-b s', [qr{ambiguous}] ], [ 'ambiguous builtin', '-b s', [qr{ambiguous}] ],
[ '--progress-timestamp => --progress', '--progress-timestamp', [ '--progress-timestamp => --progress', '--progress-timestamp',
[qr{allowed only under}] ], [qr{allowed only under}] ],
[ '-I without init option', '-I dtg', [ '-I without init option',
'-I dtg',
[qr{cannot be used in benchmarking mode}] ], [qr{cannot be used in benchmarking mode}] ],
[ 'invalid init step', '-i -I dta', [ 'invalid init step',
[qr{unrecognized initialization step}, '-i -I dta',
qr{allowed steps are} ] ], [ qr{unrecognized initialization step}, qr{allowed steps are} ] ],
[ 'bad random seed', '--random-seed=one', [ 'bad random seed',
[qr{unrecognized random seed option "one": expecting an unsigned integer, "time" or "rand"}, '--random-seed=one',
qr{error while setting random seed from --random-seed option} ] ], [
qr{unrecognized random seed option "one": expecting an unsigned integer, "time" or "rand"},
qr{error while setting random seed from --random-seed option} ] ],
# loging sub-options # loging sub-options
[ 'sampling => log', '--sampling-rate=0.01', [ 'sampling => log', '--sampling-rate=0.01',
...@@ -161,23 +165,44 @@ pgbench( ...@@ -161,23 +165,44 @@ pgbench(
'pgbench builtin list'); 'pgbench builtin list');
my @script_tests = ( my @script_tests = (
# name, err, { file => contents } # name, err, { file => contents }
[ 'missing endif', [qr{\\if without matching \\endif}], {'if-noendif.sql' => '\if 1'} ], [ 'missing endif',
[ 'missing if on elif', [qr{\\elif without matching \\if}], {'elif-noif.sql' => '\elif 1'} ], [qr{\\if without matching \\endif}],
[ 'missing if on else', [qr{\\else without matching \\if}], {'else-noif.sql' => '\else'} ], { 'if-noendif.sql' => '\if 1' } ],
[ 'missing if on endif', [qr{\\endif without matching \\if}], {'endif-noif.sql' => '\endif'} ], [ 'missing if on elif',
[ 'elif after else', [qr{\\elif after \\else}], {'else-elif.sql' => "\\if 1\n\\else\n\\elif 0\n\\endif"} ], [qr{\\elif without matching \\if}],
[ 'else after else', [qr{\\else after \\else}], {'else-else.sql' => "\\if 1\n\\else\n\\else\n\\endif"} ], { 'elif-noif.sql' => '\elif 1' } ],
[ 'if syntax error', [qr{syntax error in command "if"}], {'if-bad.sql' => "\\if\n\\endif\n"} ], [ 'missing if on else',
[ 'elif syntax error', [qr{syntax error in command "elif"}], {'elif-bad.sql' => "\\if 0\n\\elif +\n\\endif\n"} ], [qr{\\else without matching \\if}],
[ 'else syntax error', [qr{unexpected argument in command "else"}], {'else-bad.sql' => "\\if 0\n\\else BAD\n\\endif\n"} ], { 'else-noif.sql' => '\else' } ],
[ 'endif syntax error', [qr{unexpected argument in command "endif"}], {'endif-bad.sql' => "\\if 0\n\\endif BAD\n"} ], [ 'missing if on endif',
); [qr{\\endif without matching \\if}],
{ 'endif-noif.sql' => '\endif' } ],
[ 'elif after else',
[qr{\\elif after \\else}],
{ 'else-elif.sql' => "\\if 1\n\\else\n\\elif 0\n\\endif" } ],
[ 'else after else',
[qr{\\else after \\else}],
{ 'else-else.sql' => "\\if 1\n\\else\n\\else\n\\endif" } ],
[ 'if syntax error',
[qr{syntax error in command "if"}],
{ 'if-bad.sql' => "\\if\n\\endif\n" } ],
[ 'elif syntax error',
[qr{syntax error in command "elif"}],
{ 'elif-bad.sql' => "\\if 0\n\\elif +\n\\endif\n" } ],
[ 'else syntax error',
[qr{unexpected argument in command "else"}],
{ 'else-bad.sql' => "\\if 0\n\\else BAD\n\\endif\n" } ],
[ 'endif syntax error',
[qr{unexpected argument in command "endif"}],
{ 'endif-bad.sql' => "\\if 0\n\\endif BAD\n" } ],);
for my $t (@script_tests) for my $t (@script_tests)
{ {
my ($name, $err, $files) = @$t; my ($name, $err, $files) = @$t;
pgbench_scripts('', 1, [qr{^$}], $err, 'pgbench option error: ' . $name, $files); pgbench_scripts('', 1, [qr{^$}], $err, 'pgbench option error: ' . $name,
$files);
} }
done_testing(); done_testing();
...@@ -16,4 +16,5 @@ $node->init; ...@@ -16,4 +16,5 @@ $node->init;
$node->start; $node->start;
# use a long timeout for the benefit of very slow buildfarm machines # use a long timeout for the benefit of very slow buildfarm machines
$node->command_ok([qw(pg_isready --timeout=60)], 'succeeds with server running'); $node->command_ok([qw(pg_isready --timeout=60)],
'succeeds with server running');
...@@ -36,13 +36,17 @@ $node->issues_sql_like( ...@@ -36,13 +36,17 @@ $node->issues_sql_like(
$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)], $node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
'vacuumdb with connection string'); 'vacuumdb with connection string');
$node->command_fails([qw(vacuumdb -Zt pg_am;ABORT postgres)], $node->command_fails(
[qw(vacuumdb -Zt pg_am;ABORT postgres)],
'trailing command in "-t", without COLUMNS'); 'trailing command in "-t", without COLUMNS');
# Unwanted; better if it failed. # Unwanted; better if it failed.
$node->command_ok([qw(vacuumdb -Zt pg_am(amname);ABORT postgres)], $node->command_ok(
[qw(vacuumdb -Zt pg_am(amname);ABORT postgres)],
'trailing command in "-t", with COLUMNS'); 'trailing command in "-t", with COLUMNS');
$node->safe_psql('postgres', q| $node->safe_psql(
'postgres', q|
CREATE TABLE "need""q(uot" (")x" text); CREATE TABLE "need""q(uot" (")x" text);
CREATE FUNCTION f0(int) RETURNS int LANGUAGE SQL AS 'SELECT $1 * $1'; CREATE FUNCTION f0(int) RETURNS int LANGUAGE SQL AS 'SELECT $1 * $1';
...@@ -53,5 +57,6 @@ $node->safe_psql('postgres', q| ...@@ -53,5 +57,6 @@ $node->safe_psql('postgres', q|
|); |);
$node->command_ok([qw|vacuumdb -Z --table="need""q(uot"(")x") postgres|], $node->command_ok([qw|vacuumdb -Z --table="need""q(uot"(")x") postgres|],
'column list'); 'column list');
$node->command_fails([qw|vacuumdb -Zt funcidx postgres|], $node->command_fails(
[qw|vacuumdb -Zt funcidx postgres|],
'unqualifed name via functional index'); 'unqualifed name via functional index');
...@@ -15,11 +15,11 @@ while (<>) ...@@ -15,11 +15,11 @@ while (<>)
next if /^CATALOG\(.*BKI_BOOTSTRAP/; next if /^CATALOG\(.*BKI_BOOTSTRAP/;
next next
unless /\boid *=> *'(\d+)'/ unless /\boid *=> *'(\d+)'/
|| /^CATALOG\([^,]*, *(\d+).*BKI_ROWTYPE_OID\((\d+),/ || /^CATALOG\([^,]*, *(\d+).*BKI_ROWTYPE_OID\((\d+),/
|| /^CATALOG\([^,]*, *(\d+)/ || /^CATALOG\([^,]*, *(\d+)/
|| /^DECLARE_INDEX\([^,]*, *(\d+)/ || /^DECLARE_INDEX\([^,]*, *(\d+)/
|| /^DECLARE_UNIQUE_INDEX\([^,]*, *(\d+)/ || /^DECLARE_UNIQUE_INDEX\([^,]*, *(\d+)/
|| /^DECLARE_TOAST\([^,]*, *(\d+), *(\d+)/; || /^DECLARE_TOAST\([^,]*, *(\d+), *(\d+)/;
$oidcounts{$1}++; $oidcounts{$1}++;
$oidcounts{$2}++ if $2; $oidcounts{$2}++ if $2;
} }
......
...@@ -73,7 +73,7 @@ foreach my $datfile (@input_files) ...@@ -73,7 +73,7 @@ foreach my $datfile (@input_files)
my $header = "$1.h"; my $header = "$1.h";
die "There in no header file corresponding to $datfile" die "There in no header file corresponding to $datfile"
if ! -e $header; if !-e $header;
my $catalog = Catalog::ParseHeader($header); my $catalog = Catalog::ParseHeader($header);
my $catname = $catalog->{catname}; my $catname = $catalog->{catname};
...@@ -186,7 +186,7 @@ sub strip_default_values ...@@ -186,7 +186,7 @@ sub strip_default_values
{ {
my $attname = $column->{name}; my $attname = $column->{name};
die "strip_default_values: $catname.$attname undefined\n" die "strip_default_values: $catname.$attname undefined\n"
if ! defined $row->{$attname}; if !defined $row->{$attname};
# Delete values that match defaults. # Delete values that match defaults.
if (defined $column->{default} if (defined $column->{default}
...@@ -196,8 +196,9 @@ sub strip_default_values ...@@ -196,8 +196,9 @@ sub strip_default_values
} }
# Also delete pg_proc.pronargs, since that can be recomputed. # Also delete pg_proc.pronargs, since that can be recomputed.
if ($catname eq 'pg_proc' && $attname eq 'pronargs' && if ( $catname eq 'pg_proc'
defined($row->{proargtypes})) && $attname eq 'pronargs'
&& defined($row->{proargtypes}))
{ {
delete $row->{$attname}; delete $row->{$attname};
} }
...@@ -210,7 +211,7 @@ sub strip_default_values ...@@ -210,7 +211,7 @@ sub strip_default_values
# data files. # data files.
sub format_hash sub format_hash
{ {
my $data = shift; my $data = shift;
my @orig_attnames = @_; my @orig_attnames = @_;
# Copy attname to new array if it has a value, so we can determine # Copy attname to new array if it has a value, so we can determine
...@@ -228,7 +229,7 @@ sub format_hash ...@@ -228,7 +229,7 @@ sub format_hash
my $char_count = 1; my $char_count = 1;
my $threshold; my $threshold;
my $hash_str = ''; my $hash_str = '';
my $element_count = 0; my $element_count = 0;
foreach my $attname (@attnames) foreach my $attname (@attnames)
...@@ -262,7 +263,7 @@ sub format_hash ...@@ -262,7 +263,7 @@ sub format_hash
# Include a leading space in the key-value pair, since this will # Include a leading space in the key-value pair, since this will
# always go after either a comma or an additional padding space on # always go after either a comma or an additional padding space on
# the next line. # the next line.
my $element = " $attname => '$value'"; my $element = " $attname => '$value'";
my $element_length = length($element); my $element_length = length($element);
# If adding the element to the current line would expand the line # If adding the element to the current line would expand the line
......
...@@ -17,12 +17,12 @@ my ($krb5_bin_dir, $krb5_sbin_dir); ...@@ -17,12 +17,12 @@ my ($krb5_bin_dir, $krb5_sbin_dir);
if ($^O eq 'darwin') if ($^O eq 'darwin')
{ {
$krb5_bin_dir = '/usr/local/opt/krb5/bin'; $krb5_bin_dir = '/usr/local/opt/krb5/bin';
$krb5_sbin_dir = '/usr/local/opt/krb5/sbin'; $krb5_sbin_dir = '/usr/local/opt/krb5/sbin';
} }
elsif ($^O eq 'freebsd') elsif ($^O eq 'freebsd')
{ {
$krb5_bin_dir = '/usr/local/bin'; $krb5_bin_dir = '/usr/local/bin';
$krb5_sbin_dir = '/usr/local/sbin'; $krb5_sbin_dir = '/usr/local/sbin';
} }
elsif ($^O eq 'linux') elsif ($^O eq 'linux')
...@@ -30,45 +30,48 @@ elsif ($^O eq 'linux') ...@@ -30,45 +30,48 @@ elsif ($^O eq 'linux')
$krb5_sbin_dir = '/usr/sbin'; $krb5_sbin_dir = '/usr/sbin';
} }
my $krb5_config = 'krb5-config'; my $krb5_config = 'krb5-config';
my $kinit = 'kinit'; my $kinit = 'kinit';
my $kdb5_util = 'kdb5_util'; my $kdb5_util = 'kdb5_util';
my $kadmin_local = 'kadmin.local'; my $kadmin_local = 'kadmin.local';
my $krb5kdc = 'krb5kdc'; my $krb5kdc = 'krb5kdc';
if ($krb5_bin_dir && -d $krb5_bin_dir) if ($krb5_bin_dir && -d $krb5_bin_dir)
{ {
$krb5_config = $krb5_bin_dir . '/' . $krb5_config; $krb5_config = $krb5_bin_dir . '/' . $krb5_config;
$kinit = $krb5_bin_dir . '/' . $kinit; $kinit = $krb5_bin_dir . '/' . $kinit;
} }
if ($krb5_sbin_dir && -d $krb5_sbin_dir) if ($krb5_sbin_dir && -d $krb5_sbin_dir)
{ {
$kdb5_util = $krb5_sbin_dir . '/' . $kdb5_util; $kdb5_util = $krb5_sbin_dir . '/' . $kdb5_util;
$kadmin_local = $krb5_sbin_dir . '/' . $kadmin_local; $kadmin_local = $krb5_sbin_dir . '/' . $kadmin_local;
$krb5kdc = $krb5_sbin_dir . '/' . $krb5kdc; $krb5kdc = $krb5_sbin_dir . '/' . $krb5kdc;
} }
my $realm = 'EXAMPLE.COM'; my $realm = 'EXAMPLE.COM';
my $krb5_conf = "${TestLib::tmp_check}/krb5.conf"; my $krb5_conf = "${TestLib::tmp_check}/krb5.conf";
my $kdc_conf = "${TestLib::tmp_check}/kdc.conf"; my $kdc_conf = "${TestLib::tmp_check}/kdc.conf";
my $krb5_log = "${TestLib::tmp_check}/krb5libs.log"; my $krb5_log = "${TestLib::tmp_check}/krb5libs.log";
my $kdc_log = "${TestLib::tmp_check}/krb5kdc.log"; my $kdc_log = "${TestLib::tmp_check}/krb5kdc.log";
my $kdc_port = int(rand() * 16384) + 49152; my $kdc_port = int(rand() * 16384) + 49152;
my $kdc_datadir = "${TestLib::tmp_check}/krb5kdc"; my $kdc_datadir = "${TestLib::tmp_check}/krb5kdc";
my $kdc_pidfile = "${TestLib::tmp_check}/krb5kdc.pid"; my $kdc_pidfile = "${TestLib::tmp_check}/krb5kdc.pid";
my $keytab = "${TestLib::tmp_check}/krb5.keytab"; my $keytab = "${TestLib::tmp_check}/krb5.keytab";
note "setting up Kerberos"; note "setting up Kerberos";
my ($stdout, $krb5_version); my ($stdout, $krb5_version);
run_log [ $krb5_config, '--version' ], '>', \$stdout or BAIL_OUT("could not execute krb5-config"); run_log [ $krb5_config, '--version' ], '>', \$stdout
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]+)/ or BAIL_OUT("could not get Kerberos version"); $stdout =~ m/Kerberos 5 release ([0-9]+\.[0-9]+)/
or BAIL_OUT("could not get Kerberos version");
$krb5_version = $1; $krb5_version = $1;
append_to_file($krb5_conf, append_to_file(
qq![logging] $krb5_conf,
qq![logging]
default = FILE:$krb5_log default = FILE:$krb5_log
kdc = FILE:$kdc_log kdc = FILE:$kdc_log
...@@ -80,27 +83,32 @@ $realm = { ...@@ -80,27 +83,32 @@ $realm = {
kdc = localhost:$kdc_port kdc = localhost:$kdc_port
}!); }!);
append_to_file($kdc_conf, append_to_file(
qq![kdcdefaults] $kdc_conf,
qq![kdcdefaults]
!); !);
# For new-enough versions of krb5, use the _listen settings rather # For new-enough versions of krb5, use the _listen settings rather
# than the _ports settings so that we can bind to localhost only. # than the _ports settings so that we can bind to localhost only.
if ($krb5_version >= 1.15) if ($krb5_version >= 1.15)
{ {
append_to_file($kdc_conf, append_to_file(
qq!kdc_listen = localhost:$kdc_port $kdc_conf,
qq!kdc_listen = localhost:$kdc_port
kdc_tcp_listen = localhost:$kdc_port kdc_tcp_listen = localhost:$kdc_port
!); !);
} }
else else
{ {
append_to_file($kdc_conf, append_to_file(
qq!kdc_ports = $kdc_port $kdc_conf,
qq!kdc_ports = $kdc_port
kdc_tcp_ports = $kdc_port kdc_tcp_ports = $kdc_port
!); !);
} }
append_to_file($kdc_conf, append_to_file(
qq! $kdc_conf,
qq!
[realms] [realms]
$realm = { $realm = {
database_name = $kdc_datadir/principal database_name = $kdc_datadir/principal
...@@ -111,7 +119,7 @@ $realm = { ...@@ -111,7 +119,7 @@ $realm = {
mkdir $kdc_datadir or die; mkdir $kdc_datadir or die;
$ENV{'KRB5_CONFIG'} = $krb5_conf; $ENV{'KRB5_CONFIG'} = $krb5_conf;
$ENV{'KRB5_KDC_PROFILE'} = $kdc_conf; $ENV{'KRB5_KDC_PROFILE'} = $kdc_conf;
my $service_principal = "$ENV{with_krb_srvnam}/localhost"; my $service_principal = "$ENV{with_krb_srvnam}/localhost";
...@@ -128,7 +136,7 @@ system_or_bail $krb5kdc, '-P', $kdc_pidfile; ...@@ -128,7 +136,7 @@ system_or_bail $krb5kdc, '-P', $kdc_pidfile;
END END
{ {
kill 'INT', `cat $kdc_pidfile` if -f $kdc_pidfile; kill 'INT', `cat $kdc_pidfile` if -f $kdc_pidfile;
} }
note "setting up PostgreSQL instance"; note "setting up PostgreSQL instance";
...@@ -148,9 +156,12 @@ sub test_access ...@@ -148,9 +156,12 @@ sub test_access
my ($node, $role, $expected_res, $test_name) = @_; my ($node, $role, $expected_res, $test_name) = @_;
# need to connect over TCP/IP for Kerberos # need to connect over TCP/IP for Kerberos
my $res = $node->psql('postgres', 'SELECT 1', my $res = $node->psql(
extra_params => [ '-d', $node->connstr('postgres').' host=localhost', 'postgres',
'-U', $role ]); 'SELECT 1',
extra_params => [
'-d', $node->connstr('postgres') . ' host=localhost',
'-U', $role ]);
is($res, $expected_res, $test_name); is($res, $expected_res, $test_name);
} }
...@@ -171,7 +182,8 @@ test_access($node, 'test1', 0, 'succeeds with mapping'); ...@@ -171,7 +182,8 @@ test_access($node, 'test1', 0, 'succeeds with mapping');
truncate($node->data_dir . '/pg_ident.conf', 0); truncate($node->data_dir . '/pg_ident.conf', 0);
unlink($node->data_dir . '/pg_hba.conf'); unlink($node->data_dir . '/pg_hba.conf');
$node->append_conf('pg_hba.conf', qq{host all all localhost gss include_realm=0}); $node->append_conf('pg_hba.conf',
qq{host all all localhost gss include_realm=0});
$node->restart; $node->restart;
test_access($node, 'test1', 0, 'succeeds with include_realm=0'); test_access($node, 'test1', 0, 'succeeds with include_realm=0');
This diff is collapsed.
...@@ -15,25 +15,27 @@ $node->start; ...@@ -15,25 +15,27 @@ $node->start;
$node->safe_psql('postgres', 'create extension pageinspect'); $node->safe_psql('postgres', 'create extension pageinspect');
# Create a table with an autosummarizing BRIN index # Create a table with an autosummarizing BRIN index
$node->safe_psql('postgres', $node->safe_psql(
'postgres',
'create table brin_wi (a int) with (fillfactor = 10); 'create table brin_wi (a int) with (fillfactor = 10);
create index brin_wi_idx on brin_wi using brin (a) with (pages_per_range=1, autosummarize=on); create index brin_wi_idx on brin_wi using brin (a) with (pages_per_range=1, autosummarize=on);
' '
); );
my $count = $node->safe_psql('postgres', my $count = $node->safe_psql('postgres',
"select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)" "select count(*) from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)"
); );
is($count, '1', "initial index state is correct"); is($count, '1', "initial index state is correct");
$node->safe_psql('postgres', $node->safe_psql('postgres',
'insert into brin_wi select * from generate_series(1, 100)'); 'insert into brin_wi select * from generate_series(1, 100)');
$node->poll_query_until('postgres', $node->poll_query_until(
"select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)", 'postgres',
"select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)",
't'); 't');
$count = $node->safe_psql('postgres', $count = $node->safe_psql('postgres',
"select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)" "select count(*) > 1 from brin_page_items(get_raw_page('brin_wi_idx', 2), 'brin_wi_idx'::regclass)"
); );
is($count, 't', "index got summarized"); is($count, 't', "index got summarized");
$node->stop; $node->stop;
This diff is collapsed.
...@@ -284,7 +284,7 @@ sub group_access ...@@ -284,7 +284,7 @@ sub group_access
my $dir_stat = stat($self->data_dir); my $dir_stat = stat($self->data_dir);
defined($dir_stat) defined($dir_stat)
or die('unable to stat ' . $self->data_dir); or die('unable to stat ' . $self->data_dir);
return (S_IMODE($dir_stat->mode) == 0750); return (S_IMODE($dir_stat->mode) == 0750);
} }
...@@ -482,8 +482,8 @@ sub init ...@@ -482,8 +482,8 @@ sub init
} }
close $conf; close $conf;
chmod($self->group_access ? 0640 : 0600, "$pgdata/postgresql.conf") chmod($self->group_access ? 0640 : 0600, "$pgdata/postgresql.conf")
or die("unable to set permissions for $pgdata/postgresql.conf"); or die("unable to set permissions for $pgdata/postgresql.conf");
$self->set_replication_conf if $params{allows_streaming}; $self->set_replication_conf if $params{allows_streaming};
$self->enable_archiving if $params{has_archiving}; $self->enable_archiving if $params{has_archiving};
...@@ -510,8 +510,8 @@ sub append_conf ...@@ -510,8 +510,8 @@ sub append_conf
TestLib::append_to_file($conffile, $str . "\n"); TestLib::append_to_file($conffile, $str . "\n");
chmod($self->group_access() ? 0640 : 0600, $conffile) chmod($self->group_access() ? 0640 : 0600, $conffile)
or die("unable to set permissions for $conffile"); or die("unable to set permissions for $conffile");
} }
=pod =pod
...@@ -1535,7 +1535,7 @@ sub wait_for_catchup ...@@ -1535,7 +1535,7 @@ sub wait_for_catchup
} }
else else
{ {
$lsn_expr = 'pg_current_wal_lsn()' $lsn_expr = 'pg_current_wal_lsn()';
} }
print "Waiting for replication conn " print "Waiting for replication conn "
. $standby_name . "'s " . $standby_name . "'s "
...@@ -1686,8 +1686,8 @@ to check for timeout. retval is undef on timeout. ...@@ -1686,8 +1686,8 @@ to check for timeout. retval is undef on timeout.
sub pg_recvlogical_upto sub pg_recvlogical_upto
{ {
my ($self, $dbname, $slot_name, $endpos, $timeout_secs, %plugin_options) = my ($self, $dbname, $slot_name, $endpos, $timeout_secs, %plugin_options)
@_; = @_;
my ($stdout, $stderr); my ($stdout, $stderr);
my $timeout_exception = 'pg_recvlogical timed out'; my $timeout_exception = 'pg_recvlogical timed out';
......
...@@ -71,7 +71,7 @@ sub copypath ...@@ -71,7 +71,7 @@ sub copypath
{ {
croak "if specified, filterfn must be a subroutine reference" croak "if specified, filterfn must be a subroutine reference"
unless defined(ref $params{filterfn}) unless defined(ref $params{filterfn})
and (ref $params{filterfn} eq 'CODE'); and (ref $params{filterfn} eq 'CODE');
$filterfn = $params{filterfn}; $filterfn = $params{filterfn};
} }
......
...@@ -169,16 +169,17 @@ sub tempdir_short ...@@ -169,16 +169,17 @@ sub tempdir_short
# not under msys, return the input argument unchanged. # not under msys, return the input argument unchanged.
sub real_dir sub real_dir
{ {
my $dir = "$_[0]"; my $dir = "$_[0]";
return $dir unless -d $dir; return $dir unless -d $dir;
return $dir unless $Config{osname} eq 'msys'; return $dir unless $Config{osname} eq 'msys';
my $here = cwd; my $here = cwd;
chdir $dir; chdir $dir;
# this odd way of calling 'pwd -W' is the only way that seems to work. # this odd way of calling 'pwd -W' is the only way that seems to work.
$dir = qx{sh -c "pwd -W"}; $dir = qx{sh -c "pwd -W"};
chomp $dir; chomp $dir;
chdir $here; chdir $here;
return $dir; return $dir;
} }
sub system_log sub system_log
...@@ -254,12 +255,9 @@ sub check_mode_recursive ...@@ -254,12 +255,9 @@ sub check_mode_recursive
# Result defaults to true # Result defaults to true
my $result = 1; my $result = 1;
find find(
( { follow_fast => 1,
{follow_fast => 1, wanted => sub {
wanted =>
sub
{
my $file_stat = stat($File::Find::name); my $file_stat = stat($File::Find::name);
# Is file in the ignore list? # Is file in the ignore list?
...@@ -272,7 +270,7 @@ sub check_mode_recursive ...@@ -272,7 +270,7 @@ sub check_mode_recursive
} }
defined($file_stat) defined($file_stat)
or die("unable to stat $File::Find::name"); or die("unable to stat $File::Find::name");
my $file_mode = S_IMODE($file_stat->mode); my $file_mode = S_IMODE($file_stat->mode);
...@@ -281,35 +279,39 @@ sub check_mode_recursive ...@@ -281,35 +279,39 @@ sub check_mode_recursive
{ {
if ($file_mode != $expected_file_mode) if ($file_mode != $expected_file_mode)
{ {
print(*STDERR, print(
*STDERR,
sprintf("$File::Find::name mode must be %04o\n", sprintf("$File::Find::name mode must be %04o\n",
$expected_file_mode)); $expected_file_mode));
$result = 0; $result = 0;
return; return;
} }
} }
# Else a directory? # Else a directory?
elsif (S_ISDIR($file_stat->mode)) elsif (S_ISDIR($file_stat->mode))
{ {
if ($file_mode != $expected_dir_mode) if ($file_mode != $expected_dir_mode)
{ {
print(*STDERR, print(
*STDERR,
sprintf("$File::Find::name mode must be %04o\n", sprintf("$File::Find::name mode must be %04o\n",
$expected_dir_mode)); $expected_dir_mode));
$result = 0; $result = 0;
return; return;
} }
} }
# Else something we can't handle # Else something we can't handle
else else
{ {
die "unknown file type for $File::Find::name"; die "unknown file type for $File::Find::name";
} }
}}, }
$dir },
); $dir);
return $result; return $result;
} }
...@@ -319,23 +321,21 @@ sub chmod_recursive ...@@ -319,23 +321,21 @@ sub chmod_recursive
{ {
my ($dir, $dir_mode, $file_mode) = @_; my ($dir, $dir_mode, $file_mode) = @_;
find find(
( { follow_fast => 1,
{follow_fast => 1, wanted => sub {
wanted =>
sub
{
my $file_stat = stat($File::Find::name); my $file_stat = stat($File::Find::name);
if (defined($file_stat)) if (defined($file_stat))
{ {
chmod(S_ISDIR($file_stat->mode) ? $dir_mode : $file_mode, chmod(
$File::Find::name) S_ISDIR($file_stat->mode) ? $dir_mode : $file_mode,
or die "unable to chmod $File::Find::name"; $File::Find::name
) or die "unable to chmod $File::Find::name";
} }
}}, }
$dir },
); $dir);
} }
# Check presence of a given regexp within pg_config.h for the installation # Check presence of a given regexp within pg_config.h for the installation
...@@ -351,7 +351,7 @@ sub check_pg_config ...@@ -351,7 +351,7 @@ sub check_pg_config
chomp($stdout); chomp($stdout);
open my $pg_config_h, '<', "$stdout/pg_config.h" or die "$!"; open my $pg_config_h, '<', "$stdout/pg_config.h" or die "$!";
my $match = (grep {/^$regexp/} <$pg_config_h>); my $match = (grep { /^$regexp/ } <$pg_config_h>);
close $pg_config_h; close $pg_config_h;
return $match; return $match;
} }
......
...@@ -80,8 +80,7 @@ is($stdout_recv, $expected, ...@@ -80,8 +80,7 @@ is($stdout_recv, $expected,
$node_master->poll_query_until('postgres', $node_master->poll_query_until('postgres',
"SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_slot' AND active_pid IS NULL)" "SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'test_slot' AND active_pid IS NULL)"
) ) or die "slot never became inactive";
or die "slot never became inactive";
$stdout_recv = $node_master->pg_recvlogical_upto( $stdout_recv = $node_master->pg_recvlogical_upto(
'postgres', 'test_slot', $endpos, 10, 'postgres', 'test_slot', $endpos, 10,
......
...@@ -333,9 +333,9 @@ $cur_master->psql( ...@@ -333,9 +333,9 @@ $cur_master->psql(
# Ensure that last transaction is replayed on standby. # Ensure that last transaction is replayed on standby.
my $cur_master_lsn = my $cur_master_lsn =
$cur_master->safe_psql('postgres', "SELECT pg_current_wal_lsn()"); $cur_master->safe_psql('postgres', "SELECT pg_current_wal_lsn()");
my $caughtup_query = my $caughtup_query =
"SELECT '$cur_master_lsn'::pg_lsn <= pg_last_wal_replay_lsn()"; "SELECT '$cur_master_lsn'::pg_lsn <= pg_last_wal_replay_lsn()";
$cur_standby->poll_query_until('postgres', $caughtup_query) $cur_standby->poll_query_until('postgres', $caughtup_query)
or die "Timed out while waiting for standby to catch up"; or die "Timed out while waiting for standby to catch up";
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -34,7 +34,7 @@ $node_publisher->wait_for_catchup($appname); ...@@ -34,7 +34,7 @@ $node_publisher->wait_for_catchup($appname);
# Wait for initial sync to finish as well # Wait for initial sync to finish as well
my $synced_query = my $synced_query =
"SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('s', 'r');"; "SELECT count(1) = 0 FROM pg_subscription_rel WHERE srsubstate NOT IN ('s', 'r');";
$node_subscriber->poll_query_until('postgres', $synced_query) $node_subscriber->poll_query_until('postgres', $synced_query)
or die "Timed out while waiting for subscriber to synchronize data"; or die "Timed out while waiting for subscriber to synchronize data";
......
This diff is collapsed.
...@@ -28,7 +28,8 @@ $node_subscriber->safe_psql('postgres', ...@@ -28,7 +28,8 @@ $node_subscriber->safe_psql('postgres',
$node_publisher->wait_for_catchup($appname); $node_publisher->wait_for_catchup($appname);
$node_subscriber->safe_psql('postgres', q{ $node_subscriber->safe_psql(
'postgres', q{
BEGIN; BEGIN;
ALTER SUBSCRIPTION mysub DISABLE; ALTER SUBSCRIPTION mysub DISABLE;
ALTER SUBSCRIPTION mysub SET (slot_name = NONE); ALTER SUBSCRIPTION mysub SET (slot_name = NONE);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment