2016-08-04 20:44:23 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use PostgresNode;
|
|
|
|
use TestLib;
|
|
|
|
use Test::More tests => 14;
|
|
|
|
|
|
|
|
# In a SQL_ASCII database, pgwin32_message_to_UTF16() needs to
|
|
|
|
# interpret everything as UTF8. We're going to use byte sequences
|
|
|
|
# that aren't valid UTF-8 strings, so that would fail. Use LATIN1,
|
|
|
|
# which accepts any byte and has a conversion from each byte to UTF-8.
|
2017-01-31 18:42:16 +01:00
|
|
|
$ENV{LC_ALL} = 'C';
|
2016-08-04 20:44:23 +02:00
|
|
|
$ENV{PGCLIENTENCODING} = 'LATIN1';
|
|
|
|
|
|
|
|
# Create database and user names covering the range of LATIN1
|
|
|
|
# characters, for use in a connection string by pg_dumpall. Skip ','
|
|
|
|
# because of pg_regress --create-role, skip [\n\r] because pg_dumpall
|
|
|
|
# does not allow them.
|
2017-01-31 18:42:16 +01:00
|
|
|
my $dbname1 =
|
|
|
|
generate_ascii_string(1, 9)
|
|
|
|
. generate_ascii_string(11, 12)
|
|
|
|
. generate_ascii_string(14, 33)
|
|
|
|
. ($TestLib::windows_os ? '' : '"x"')
|
|
|
|
. # IPC::Run mishandles '"' on Windows
|
|
|
|
generate_ascii_string(35, 43)
|
|
|
|
. generate_ascii_string(45, 63); # contains '='
|
|
|
|
my $dbname2 =
|
|
|
|
generate_ascii_string(67, 129); # skip 64-66 to keep length to 62
|
2016-08-04 20:44:23 +02:00
|
|
|
my $dbname3 = generate_ascii_string(130, 192);
|
|
|
|
my $dbname4 = generate_ascii_string(193, 255);
|
|
|
|
|
|
|
|
my $node = get_new_node('main');
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->init(extra => [ '--locale=C', '--encoding=LATIN1' ]);
|
|
|
|
|
2016-08-04 20:44:23 +02:00
|
|
|
# prep pg_hba.conf and pg_ident.conf
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->run_log(
|
|
|
|
[ $ENV{PG_REGRESS}, '--config-auth',
|
|
|
|
$node->data_dir, '--create-role',
|
|
|
|
"$dbname1,$dbname2,$dbname3,$dbname4" ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
$node->start;
|
|
|
|
|
|
|
|
my $backupdir = $node->backup_dir;
|
2017-01-31 18:42:16 +01:00
|
|
|
my $discard = "$backupdir/discard.sql";
|
|
|
|
my $plain = "$backupdir/plain.sql";
|
|
|
|
my $dirfmt = "$backupdir/dirfmt";
|
2016-08-04 20:44:23 +02:00
|
|
|
|
|
|
|
foreach my $dbname ($dbname1, $dbname2, $dbname3, $dbname4, 'CamelCase')
|
|
|
|
{
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->run_log([ 'createdb', $dbname ]);
|
|
|
|
$node->run_log([ 'createuser', '-s', $dbname ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# For these tests, pg_dumpall -r is used because it produces a short
|
|
|
|
# dump.
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_dumpall', '-r', '-f', $discard, '--dbname',
|
|
|
|
$node->connstr($dbname1),
|
|
|
|
'-U', $dbname4 ],
|
|
|
|
'pg_dumpall with long ASCII name 1');
|
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_dumpall', '-r', '-f', $discard, '--dbname',
|
|
|
|
$node->connstr($dbname2),
|
|
|
|
'-U', $dbname3 ],
|
|
|
|
'pg_dumpall with long ASCII name 2');
|
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_dumpall', '-r', '-f', $discard, '--dbname',
|
|
|
|
$node->connstr($dbname3),
|
|
|
|
'-U', $dbname2 ],
|
|
|
|
'pg_dumpall with long ASCII name 3');
|
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_dumpall', '-r', '-f', $discard, '--dbname',
|
|
|
|
$node->connstr($dbname4),
|
|
|
|
'-U', $dbname1 ],
|
|
|
|
'pg_dumpall with long ASCII name 4');
|
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_dumpall', '-r', '-l', 'dbname=template1' ],
|
|
|
|
'pg_dumpall -l accepts connection string');
|
|
|
|
|
|
|
|
$node->run_log([ 'createdb', "foo\n\rbar" ]);
|
|
|
|
|
2016-08-04 20:44:23 +02:00
|
|
|
# not sufficient to use -r here
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->command_fails(
|
|
|
|
[ 'pg_dumpall', '-f', $discard ],
|
|
|
|
'pg_dumpall with \n\r in database name');
|
|
|
|
$node->run_log([ 'dropdb', "foo\n\rbar" ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
# make a table, so the parallel worker has something to dump
|
|
|
|
$node->safe_psql($dbname1, 'CREATE TABLE t0()');
|
2017-01-31 18:42:16 +01:00
|
|
|
|
2016-08-04 20:44:23 +02:00
|
|
|
# XXX no printed message when this fails, just SIGPIPE termination
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_dump', '-Fd', '-j2', '-f', $dirfmt,
|
|
|
|
'-U', $dbname1, $node->connstr($dbname1) ],
|
|
|
|
'parallel dump');
|
2016-08-04 20:44:23 +02:00
|
|
|
|
|
|
|
# recreate $dbname1 for restore test
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->run_log([ 'dropdb', $dbname1 ]);
|
|
|
|
$node->run_log([ 'createdb', $dbname1 ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_restore', '-v', '-d', 'template1', '-j2', '-U', $dbname1, $dirfmt ],
|
|
|
|
'parallel restore');
|
2016-08-04 20:44:23 +02:00
|
|
|
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->run_log([ 'dropdb', $dbname1 ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->command_ok(
|
|
|
|
[ 'pg_restore', '-C', '-v', '-d',
|
|
|
|
'template1', '-j2', '-U', $dbname1,
|
|
|
|
$dirfmt ],
|
|
|
|
'parallel restore with create');
|
2016-08-04 20:44:23 +02:00
|
|
|
|
|
|
|
|
2017-01-31 18:42:16 +01:00
|
|
|
$node->command_ok([ 'pg_dumpall', '-f', $plain, '-U', $dbname1 ],
|
|
|
|
'take full dump');
|
2016-08-04 20:44:23 +02:00
|
|
|
system_log('cat', $plain);
|
2017-01-31 18:42:16 +01:00
|
|
|
my ($stderr, $result);
|
2016-08-04 20:44:23 +02:00
|
|
|
my $bootstrap_super = 'boot';
|
2017-01-31 18:42:16 +01:00
|
|
|
my $restore_super = qq{a'b\\c=d\\ne"f};
|
2016-08-04 20:44:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Restore full dump through psql using environment variables for
|
|
|
|
# dbname/user connection parameters
|
|
|
|
|
|
|
|
my $envar_node = get_new_node('destination_envar');
|
2017-01-31 18:42:16 +01:00
|
|
|
$envar_node->init(
|
|
|
|
extra => [ '-U', $bootstrap_super, '--locale=C', '--encoding=LATIN1' ]);
|
|
|
|
$envar_node->run_log(
|
|
|
|
[ $ENV{PG_REGRESS}, '--config-auth',
|
|
|
|
$envar_node->data_dir, '--create-role',
|
|
|
|
"$bootstrap_super,$restore_super" ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
$envar_node->start;
|
|
|
|
|
|
|
|
# make superuser for restore
|
2017-01-31 18:42:16 +01:00
|
|
|
$envar_node->run_log(
|
|
|
|
[ 'createuser', '-U', $bootstrap_super, '-s', $restore_super ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
local $ENV{PGPORT} = $envar_node->port;
|
|
|
|
local $ENV{PGUSER} = $restore_super;
|
2017-01-31 18:42:16 +01:00
|
|
|
$result = run_log([ 'psql', '-X', '-f', $plain ], '2>', \$stderr);
|
2016-08-04 20:44:23 +02:00
|
|
|
}
|
2017-01-31 18:42:16 +01:00
|
|
|
ok($result,
|
|
|
|
'restore full dump using environment variables for connection parameters'
|
|
|
|
);
|
2016-08-04 20:44:23 +02:00
|
|
|
is($stderr, '', 'no dump errors');
|
|
|
|
|
|
|
|
|
|
|
|
# Restore full dump through psql using command-line options for
|
|
|
|
# dbname/user connection parameters. "\connect dbname=" forgets
|
|
|
|
# user/port from command line.
|
|
|
|
|
2017-01-31 18:42:16 +01:00
|
|
|
$restore_super =~ s/"//g
|
|
|
|
if $TestLib::windows_os; # IPC::Run mishandles '"' on Windows
|
2016-08-04 20:44:23 +02:00
|
|
|
my $cmdline_node = get_new_node('destination_cmdline');
|
2017-01-31 18:42:16 +01:00
|
|
|
$cmdline_node->init(
|
|
|
|
extra => [ '-U', $bootstrap_super, '--locale=C', '--encoding=LATIN1' ]);
|
|
|
|
$cmdline_node->run_log(
|
|
|
|
[ $ENV{PG_REGRESS}, '--config-auth',
|
|
|
|
$cmdline_node->data_dir, '--create-role',
|
|
|
|
"$bootstrap_super,$restore_super" ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
$cmdline_node->start;
|
2017-01-31 18:42:16 +01:00
|
|
|
$cmdline_node->run_log(
|
|
|
|
[ 'createuser', '-U', $bootstrap_super, '-s', $restore_super ]);
|
2016-08-04 20:44:23 +02:00
|
|
|
{
|
2017-01-31 18:42:16 +01:00
|
|
|
$result = run_log(
|
|
|
|
[ 'psql', '-p', $cmdline_node->port, '-U',
|
|
|
|
$restore_super, '-X', '-f', $plain ],
|
|
|
|
'2>',
|
|
|
|
\$stderr);
|
2016-08-04 20:44:23 +02:00
|
|
|
}
|
2017-01-31 18:42:16 +01:00
|
|
|
ok($result,
|
|
|
|
'restore full dump with command-line options for connection parameters');
|
2016-08-04 20:44:23 +02:00
|
|
|
is($stderr, '', 'no dump errors');
|