2021-05-07 16:56:14 +02:00
2022-01-08 01:04:57 +01:00
# Copyright (c) 2021-2022, PostgreSQL Global Development Group
2021-05-07 16:56:14 +02:00
2014-04-15 03:33:46 +02:00
use strict ;
use warnings ;
use Cwd ;
2015-07-29 18:17:02 +02:00
use Config ;
2018-03-27 15:14:40 +02:00
use File::Basename qw( basename dirname ) ;
2018-04-06 22:26:31 +02:00
use File::Path qw( rmtree ) ;
2021-04-19 03:15:35 +02:00
use Fcntl qw( :seek ) ;
2021-10-24 16:28:19 +02:00
use PostgreSQL::Test::Cluster ;
use PostgreSQL::Test::Utils ;
2022-01-08 01:12:21 +01:00
use Test::More tests = > 115 ;
2014-04-15 03:33:46 +02:00
program_help_ok ( 'pg_basebackup' ) ;
program_version_ok ( 'pg_basebackup' ) ;
program_options_handling_ok ( 'pg_basebackup' ) ;
2021-10-24 16:28:19 +02:00
my $ tempdir = PostgreSQL::Test::Utils:: tempdir ;
2014-04-15 03:33:46 +02:00
2021-10-24 16:28:19 +02:00
my $ node = PostgreSQL::Test::Cluster - > new ( 'main' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
2022-01-18 00:40:00 +01:00
# For nearly all pg_basebackup invocations some options should be specified,
# to keep test times reasonable. Using @pg_basebackup_defs as the first
# element of the array passed to to IPC::Run interpolate the array (as it is
# not a reference to an array)...
my @ pg_basebackup_defs = ( 'pg_basebackup' , '--no-sync' , '-cfast' ) ;
2018-04-07 23:45:39 +02:00
# Set umask so test directories and files are created with default permissions
umask ( 0077 ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
# Initialize node without replication settings
2018-04-03 13:47:16 +02:00
$ node - > init ( extra = > [ '--data-checksums' ] ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > start ;
my $ pgdata = $ node - > data_dir ;
$ node - > command_fails ( [ 'pg_basebackup' ] ,
2014-04-15 03:33:46 +02:00
'pg_basebackup needs target directory specified' ) ;
2015-06-22 02:04:36 +02:00
# Some Windows ANSI code pages may reject this filename, in which case we
# quietly proceed without this bit of test coverage.
2017-03-27 04:24:13 +02:00
if ( open my $ badchars , '>>' , "$tempdir/pgdata/FOO\xe0\xe0\xe0BAR" )
2015-06-22 02:04:36 +02:00
{
2017-03-27 04:24:13 +02:00
print $ badchars "test backup of file with non-UTF8 name\n" ;
close $ badchars ;
2015-06-22 02:04:36 +02:00
}
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > set_replication_conf ( ) ;
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'reload' ;
2014-04-15 03:33:46 +02:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup" ] ,
2014-04-15 03:33:46 +02:00
'pg_basebackup fails because of WAL configuration' ) ;
2016-09-12 18:00:00 +02:00
ok ( ! - d "$tempdir/backup" , 'backup directory was cleaned up' ) ;
2019-06-03 06:44:03 +02:00
# Create a backup directory that is not empty so the next command will fail
2018-04-07 23:45:39 +02:00
# but leave the data directory behind
mkdir ( "$tempdir/backup" )
or BAIL_OUT ( "unable to create $tempdir/backup" ) ;
2018-04-09 21:45:48 +02:00
append_to_file ( "$tempdir/backup/dir-not-empty.txt" , "Some data" ) ;
2018-04-07 23:45:39 +02:00
2022-01-18 00:40:00 +01:00
$ node - > command_fails ( [ @ pg_basebackup_defs , '-D' , "$tempdir/backup" , '-n' ] ,
2016-10-19 18:00:00 +02:00
'failing run with no-clean option' ) ;
2016-09-12 18:00:00 +02:00
ok ( - d "$tempdir/backup" , 'backup directory was created and left behind' ) ;
2018-04-07 23:45:39 +02:00
rmtree ( "$tempdir/backup" ) ;
2016-09-12 18:00:00 +02:00
2017-03-27 04:24:13 +02:00
open my $ conf , '>>' , "$pgdata/postgresql.conf" ;
print $ conf "max_replication_slots = 10\n" ;
print $ conf "max_wal_senders = 10\n" ;
print $ conf "wal_level = replica\n" ;
close $ conf ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > restart ;
2014-04-15 03:33:46 +02:00
2016-09-28 18:00:00 +02:00
# Write some files to test that they are not copied.
2017-03-03 07:02:45 +01:00
foreach my $ filename (
2020-02-24 10:13:25 +01:00
qw( backup_label tablespace_map postgresql.auto.conf.tmp
current_logfiles . tmp global / pg_internal . init .123 ) )
2016-09-28 18:00:00 +02:00
{
2017-03-27 04:24:13 +02:00
open my $ file , '>>' , "$pgdata/$filename" ;
print $ file "DONOTCOPY" ;
close $ file ;
2016-09-28 18:00:00 +02:00
}
2017-11-07 18:28:35 +01:00
# Connect to a database to create global/pg_internal.init. If this is removed
# the test to ensure global/pg_internal.init is not copied will return a false
# positive.
$ node - > safe_psql ( 'postgres' , 'SELECT 1;' ) ;
2018-03-23 17:14:12 +01:00
# Create an unlogged table to test that forks other than init are not copied.
$ node - > safe_psql ( 'postgres' , 'CREATE UNLOGGED TABLE base_unlogged (id int)' ) ;
my $ baseUnloggedPath = $ node - > safe_psql ( 'postgres' ,
q{ select pg_relation_filepath('base_unlogged') } ) ;
# Make sure main and init forks exist
ok ( - f "$pgdata/${baseUnloggedPath}_init" , 'unlogged init fork in base' ) ;
ok ( - f "$pgdata/$baseUnloggedPath" , 'unlogged main fork in base' ) ;
2018-03-27 15:14:40 +02:00
# Create files that look like temporary relations to ensure they are ignored.
my $ postgresOid = $ node - > safe_psql ( 'postgres' ,
q{ select oid from pg_database where datname = 'postgres' } ) ;
my @ tempRelationFiles =
qw( t999_999 t9999_999.1 t999_9999_vm t99999_99999_vm.1 ) ;
foreach my $ filename ( @ tempRelationFiles )
{
append_to_file ( "$pgdata/base/$postgresOid/$filename" , 'TEMP_RELATION' ) ;
}
# Run base backup.
2022-01-18 00:40:00 +01:00
$ node - > command_ok ( [ @ pg_basebackup_defs , '-D' , "$tempdir/backup" , '-X' , 'none' ] ,
2014-04-15 03:33:46 +02:00
'pg_basebackup runs' ) ;
ok ( - f "$tempdir/backup/PG_VERSION" , 'backup was created' ) ;
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
ok ( - f "$tempdir/backup/backup_manifest" , 'backup manifest included' ) ;
2014-04-15 03:33:46 +02:00
2018-04-07 23:45:39 +02:00
# Permissions on backup should be default
SKIP:
{
skip "unix-style permissions not supported on Windows" , 1
if ( $ windows_os ) ;
ok ( check_mode_recursive ( "$tempdir/backup" , 0700 , 0600 ) ,
"check backup dir permissions" ) ;
}
2016-10-20 17:24:37 +02:00
# Only archive_status directory should be copied in pg_wal/.
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
is_deeply (
2016-10-20 17:24:37 +02:00
[ sort ( slurp_dir ( "$tempdir/backup/pg_wal/" ) ) ] ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
[ sort qw( . .. archive_status ) ] ,
'no WAL files copied' ) ;
2015-07-01 03:15:29 +02:00
2016-09-28 18:00:00 +02:00
# Contents of these directories should not be copied.
foreach my $ dirname (
qw( pg_dynshmem pg_notify pg_replslot pg_serial pg_snapshots pg_stat_tmp pg_subtrans )
2017-05-18 01:01:23 +02:00
)
2016-09-28 18:00:00 +02:00
{
is_deeply (
[ sort ( slurp_dir ( "$tempdir/backup/$dirname/" ) ) ] ,
[ sort qw( . .. ) ] ,
"contents of $dirname/ not copied" ) ;
}
# These files should not be copied.
2017-03-03 07:02:45 +01:00
foreach my $ filename (
2017-11-07 18:28:35 +01:00
qw( postgresql.auto.conf.tmp postmaster.opts postmaster.pid tablespace_map current_logfiles.tmp
2020-02-24 10:13:25 +01:00
global /pg_internal.init global/ pg_internal . init .123 ) )
2016-09-28 18:00:00 +02:00
{
ok ( ! - f "$tempdir/backup/$filename" , "$filename not copied" ) ;
}
2018-03-23 17:14:12 +01:00
# Unlogged relation forks other than init should not be copied
ok ( - f "$tempdir/backup/${baseUnloggedPath}_init" ,
'unlogged init fork in backup' ) ;
ok ( ! - f "$tempdir/backup/$baseUnloggedPath" ,
'unlogged main fork not in backup' ) ;
2018-03-27 15:14:40 +02:00
# Temp relations should not be copied.
foreach my $ filename ( @ tempRelationFiles )
{
ok ( ! - f "$tempdir/backup/base/$postgresOid/$filename" ,
"base/$postgresOid/$filename not copied" ) ;
}
2016-09-28 18:00:00 +02:00
# Make sure existing backup_label was ignored.
isnt ( slurp_file ( "$tempdir/backup/backup_label" ) ,
'DONOTCOPY' , 'existing backup_label not copied' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backup" ) ;
2016-09-28 18:00:00 +02:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_ok (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
"$tempdir/backup2" , '--no-manifest' ,
'--waldir' , "$tempdir/xlog2"
2018-05-09 16:14:46 +02:00
] ,
2014-04-15 03:33:46 +02:00
'separate xlog directory' ) ;
ok ( - f "$tempdir/backup2/PG_VERSION" , 'backup was created' ) ;
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
ok ( ! - f "$tempdir/backup2/backup_manifest" , 'manifest was suppressed' ) ;
2014-04-15 03:33:46 +02:00
ok ( - d "$tempdir/xlog2/" , 'xlog directory was created' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backup2" ) ;
rmtree ( "$tempdir/xlog2" ) ;
2014-04-15 03:33:46 +02:00
2022-01-18 00:40:00 +01:00
$ node - > command_ok ( [ @ pg_basebackup_defs , '-D' , "$tempdir/tarbackup" , '-Ft' ] ,
2014-04-15 03:33:46 +02:00
'tar format' ) ;
ok ( - f "$tempdir/tarbackup/base.tar" , 'backup tar was created' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/tarbackup" ) ;
2014-04-15 03:33:46 +02:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_foo" , '-Fp' , "-T=/foo" ] ,
2014-04-15 03:33:46 +02:00
'-T with empty old directory fails' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_foo" , '-Fp' , "-T/foo=" ] ,
2014-04-15 03:33:46 +02:00
'-T with empty new directory fails' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' , "$tempdir/backup_foo" , '-Fp' ,
2018-05-09 16:14:46 +02:00
"-T/foo=/bar=/baz"
] ,
2014-04-15 03:33:46 +02:00
'-T with multiple = fails' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_foo" , '-Fp' , "-Tfoo=/bar" ] ,
2014-04-15 03:33:46 +02:00
'-T with old directory not absolute fails' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_foo" , '-Fp' , "-T/foo=bar" ] ,
2014-04-15 03:33:46 +02:00
'-T with new directory not absolute fails' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_foo" , '-Fp' , "-Tfoo" ] ,
2014-04-15 03:33:46 +02:00
'-T with invalid format fails' ) ;
2015-02-24 19:41:07 +01:00
2015-07-29 18:17:02 +02:00
# Tar format doesn't support filenames longer than 100 bytes.
my $ superlongname = "superlongname_" . ( "x" x 100 ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
my $ superlongpath = "$pgdata/$superlongname" ;
2015-07-29 18:17:02 +02:00
2017-03-27 04:24:13 +02:00
open my $ file , '>' , "$superlongpath"
or die "unable to create file $superlongpath" ;
close $ file ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/tarbackup_l1" , '-Ft' ] ,
2015-07-29 18:17:02 +02:00
'pg_basebackup tar with long name fails' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
unlink "$pgdata/$superlongname" ;
2015-07-29 18:17:02 +02:00
2020-07-16 20:48:37 +02:00
# The following tests are for symlinks.
# Move pg_replslot out of $pgdata and create a symlink to it.
$ node - > stop ;
# Set umask so test directories and files are created with group permissions
umask ( 0027 ) ;
# Enable group permissions on PGDATA
chmod_recursive ( "$pgdata" , 0750 , 0640 ) ;
rename ( "$pgdata/pg_replslot" , "$tempdir/pg_replslot" )
or BAIL_OUT "could not move $pgdata/pg_replslot" ;
dir_symlink ( "$tempdir/pg_replslot" , "$pgdata/pg_replslot" )
or BAIL_OUT "could not symlink to $pgdata/pg_replslot" ;
$ node - > start ;
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
# Test backup of a tablespace using tar format.
2020-07-16 20:48:37 +02:00
# Create a temporary directory in the system location and symlink it
# to our physical temp location. That way we can use shorter names
# for the tablespace directories, which hopefully won't run afoul of
# the 99 character length limit.
2021-10-24 16:28:19 +02:00
my $ sys_tempdir = PostgreSQL::Test::Utils:: tempdir_short ;
my $ real_sys_tempdir = PostgreSQL::Test::Utils:: perl2host ( $ sys_tempdir ) . "/tempdir" ;
2021-07-29 18:15:03 +02:00
my $ shorter_tempdir = $ sys_tempdir . "/tempdir" ;
2020-07-16 20:48:37 +02:00
dir_symlink "$tempdir" , $ shorter_tempdir ;
mkdir "$tempdir/tblspc1" ;
2021-07-29 18:15:03 +02:00
my $ realTsDir = "$real_sys_tempdir/tblspc1" ;
2021-10-24 16:28:19 +02:00
my $ real_tempdir = PostgreSQL::Test::Utils:: perl2host ( $ tempdir ) ;
2020-07-16 20:48:37 +02:00
$ node - > safe_psql ( 'postgres' ,
"CREATE TABLESPACE tblspc1 LOCATION '$realTsDir';" ) ;
$ node - > safe_psql ( 'postgres' ,
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
"CREATE TABLE test1 (a int) TABLESPACE tblspc1;"
. "INSERT INTO test1 VALUES (1234);" ) ;
$ node - > backup ( 'tarbackup2' , backup_options = > [ '-Ft' ] ) ;
# empty test1, just so that it's different from the to-be-restored data
$ node - > safe_psql ( 'postgres' , "TRUNCATE TABLE test1;" ) ;
# basic checks on the output
my $ backupdir = $ node - > backup_dir . '/tarbackup2' ;
ok ( - f "$backupdir/base.tar" , 'backup tar was created' ) ;
ok ( - f "$backupdir/pg_wal.tar" , 'WAL tar was created' ) ;
my @ tblspc_tars = glob "$backupdir/[0-9]*.tar" ;
2020-07-16 20:48:37 +02:00
is ( scalar ( @ tblspc_tars ) , 1 , 'one tablespace tar was created' ) ;
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
# Try to verify the tar-format backup by restoring it.
# For this, we use the tar program identified by configure.
SKIP:
{
my $ tar = $ ENV { TAR } ;
2021-12-08 22:45:39 +01:00
# don't check for a working tar here, to accomodate various odd
# cases such as AIX. If tar doesn't work the init_from_backup below
# will fail.
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
skip "no tar program available" , 1
2021-12-08 22:45:39 +01:00
if ( ! defined $ tar || $ tar eq '' ) ;
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
2021-10-24 16:28:19 +02:00
my $ node2 = PostgreSQL::Test::Cluster - > new ( 'replica' ) ;
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
# Recover main data directory
$ node2 - > init_from_backup ( $ node , 'tarbackup2' , tar_program = > $ tar ) ;
# Recover tablespace into a new directory (not where it was!)
2021-03-19 03:43:03 +01:00
my $ repTsDir = "$tempdir/tblspc1replica" ;
2021-07-29 18:15:03 +02:00
my $ realRepTsDir = "$real_sys_tempdir/tblspc1replica" ;
2021-03-19 03:43:03 +01:00
mkdir $ repTsDir ;
2021-10-24 16:28:19 +02:00
PostgreSQL::Test::Utils:: system_or_bail ( $ tar , 'xf' , $ tblspc_tars [ 0 ] , '-C' , $ repTsDir ) ;
Add end-to-end testing of pg_basebackup's tar-format output.
The existing test script does run pg_basebackup with the -Ft option,
but it makes no real attempt to verify the sanity of the results.
We wouldn't know if the output is incompatible with standard "tar"
programs, nor if the server fails to start from the restored output.
Notably, this means that xlog.c's read_tablespace_map() is not being
meaningfully tested, since that code is used only in the tar-format
case. (We do have reasonable coverage of restoring from plain-format
output, though it's over in src/test/recovery not here.)
Hence, attempt to untar the output and start a server from it,
rather just hoping it's OK.
This test assumes that the local "tar" has the "-C directory"
switch. Although that's not promised by POSIX, my research
suggests that all non-extinct tar implementations have it.
Should the buildfarm's opinion differ, we can complicate the
test a bit to avoid requiring that.
Possibly this should be back-patched, but I'm unsure about
whether it could work on Windows before d66b23b03.
2021-03-17 19:52:55 +01:00
# Update tablespace map to point to new directory.
# XXX Ideally pg_basebackup would handle this.
$ tblspc_tars [ 0 ] =~ m | / ( [ 0 - 9 ] * ) \ . tar $| ;
my $ tblspcoid = $ 1 ;
my $ escapedRepTsDir = $ realRepTsDir ;
$ escapedRepTsDir =~ s/\\/\\\\/g ;
open my $ mapfile , '>' , $ node2 - > data_dir . '/tablespace_map' ;
print $ mapfile "$tblspcoid $escapedRepTsDir\n" ;
close $ mapfile ;
$ node2 - > start ;
my $ result = $ node2 - > safe_psql ( 'postgres' , 'SELECT * FROM test1' ) ;
is ( $ result , '1234' , "tablespace data restored from tar-format backup" ) ;
$ node2 - > stop ;
}
2020-07-16 20:48:37 +02:00
# Create an unlogged table to test that forks other than init are not copied.
$ node - > safe_psql ( 'postgres' ,
'CREATE UNLOGGED TABLE tblspc1_unlogged (id int) TABLESPACE tblspc1;' ) ;
my $ tblspc1UnloggedPath = $ node - > safe_psql ( 'postgres' ,
q{ select pg_relation_filepath('tblspc1_unlogged') } ) ;
# Make sure main and init forks exist
ok ( - f "$pgdata/${tblspc1UnloggedPath}_init" ,
'unlogged init fork in tablespace' ) ;
ok ( - f "$pgdata/$tblspc1UnloggedPath" , 'unlogged main fork in tablespace' ) ;
# Create files that look like temporary relations to ensure they are ignored
# in a tablespace.
@ tempRelationFiles = qw( t888_888 t888888_888888_vm.1 ) ;
my $ tblSpc1Id = basename (
dirname (
dirname (
$ node - > safe_psql (
'postgres' , q{ select pg_relation_filepath('test1') } ) ) ) ) ;
foreach my $ filename ( @ tempRelationFiles )
{
append_to_file (
"$shorter_tempdir/tblspc1/$tblSpc1Id/$postgresOid/$filename" ,
'TEMP_RELATION' ) ;
}
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup1" , '-Fp' ] ,
2020-07-16 20:48:37 +02:00
'plain format with tablespaces fails without tablespace mapping' ) ;
$ node - > command_ok (
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
"$tempdir/backup1" , '-Fp' ,
"-T$realTsDir=$real_tempdir/tbackup/tblspc1" ,
2020-07-16 20:48:37 +02:00
] ,
'plain format with tablespaces succeeds with tablespace mapping' ) ;
ok ( - d "$tempdir/tbackup/tblspc1" , 'tablespace was relocated' ) ;
# This symlink check is not supported on Windows as -l
# doesn't work with junctions
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
SKIP:
{
2020-07-16 20:48:37 +02:00
skip "symlink check not implemented on Windows" , 1
if ( $ windows_os ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
opendir ( my $ dh , "$pgdata/pg_tblspc" ) or die ;
2015-07-29 18:17:02 +02:00
ok ( ( grep {
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
- l "$tempdir/backup1/pg_tblspc/$_"
and readlink "$tempdir/backup1/pg_tblspc/$_" eq
"$tempdir/tbackup/tblspc1"
} readdir ( $ dh ) ) ,
2015-07-29 18:17:02 +02:00
"tablespace symlink was updated" ) ;
closedir $ dh ;
2020-07-16 20:48:37 +02:00
}
# Group access should be enabled on all backup files
SKIP:
{
skip "unix-style permissions not supported on Windows" , 1
if ( $ windows_os ) ;
2015-07-29 18:17:02 +02:00
2018-04-07 23:45:39 +02:00
ok ( check_mode_recursive ( "$tempdir/backup1" , 0750 , 0640 ) ,
"check backup dir permissions" ) ;
2020-07-16 20:48:37 +02:00
}
# Unlogged relation forks other than init should not be copied
my ( $ tblspc1UnloggedBackupPath ) =
$ tblspc1UnloggedPath =~ /[^\/]*\/[^\/]*\/[^\/]*$/g ;
ok ( - f "$tempdir/tbackup/tblspc1/${tblspc1UnloggedBackupPath}_init" ,
'unlogged init fork in tablespace backup' ) ;
ok ( ! - f "$tempdir/tbackup/tblspc1/$tblspc1UnloggedBackupPath" ,
'unlogged main fork not in tablespace backup' ) ;
2018-04-07 23:45:39 +02:00
2020-07-16 20:48:37 +02:00
# Temp relations should not be copied.
foreach my $ filename ( @ tempRelationFiles )
{
ok ( ! - f "$tempdir/tbackup/tblspc1/$tblSpc1Id/$postgresOid/$filename" ,
"[tblspc1]/$postgresOid/$filename not copied" ) ;
# Also remove temp relation files or tablespace drop will fail.
my $ filepath =
"$shorter_tempdir/tblspc1/$tblSpc1Id/$postgresOid/$filename" ;
unlink ( $ filepath )
or BAIL_OUT ( "unable to unlink $filepath" ) ;
2015-07-29 18:17:02 +02:00
}
2015-07-01 03:15:05 +02:00
2020-07-16 20:48:37 +02:00
ok ( - d "$tempdir/backup1/pg_replslot" ,
'pg_replslot symlink copied as directory' ) ;
rmtree ( "$tempdir/backup1" ) ;
mkdir "$tempdir/tbl=spc2" ;
2021-07-29 18:15:03 +02:00
$ realTsDir = "$real_sys_tempdir/tbl=spc2" ;
2020-07-16 20:48:37 +02:00
$ node - > safe_psql ( 'postgres' , "DROP TABLE test1;" ) ;
$ node - > safe_psql ( 'postgres' , "DROP TABLE tblspc1_unlogged;" ) ;
$ node - > safe_psql ( 'postgres' , "DROP TABLESPACE tblspc1;" ) ;
$ node - > safe_psql ( 'postgres' ,
"CREATE TABLESPACE tblspc2 LOCATION '$realTsDir';" ) ;
$ realTsDir =~ s/=/\\=/ ;
$ node - > command_ok (
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
"$tempdir/backup3" , '-Fp' ,
"-T$realTsDir=$real_tempdir/tbackup/tbl\\=spc2" ,
2020-07-16 20:48:37 +02:00
] ,
'mapping tablespace with = sign in path' ) ;
ok ( - d "$tempdir/tbackup/tbl=spc2" , 'tablespace with = sign was relocated' ) ;
$ node - > safe_psql ( 'postgres' , "DROP TABLESPACE tblspc2;" ) ;
rmtree ( "$tempdir/backup3" ) ;
mkdir "$tempdir/$superlongname" ;
2021-07-29 18:15:03 +02:00
$ realTsDir = "$real_sys_tempdir/$superlongname" ;
2020-07-16 20:48:37 +02:00
$ node - > safe_psql ( 'postgres' ,
"CREATE TABLESPACE tblspc3 LOCATION '$realTsDir';" ) ;
2022-01-18 00:40:00 +01:00
$ node - > command_ok ( [ @ pg_basebackup_defs , '-D' , "$tempdir/tarbackup_l3" , '-Ft' ] ,
2020-07-16 20:48:37 +02:00
'pg_basebackup tar with long symlink target' ) ;
$ node - > safe_psql ( 'postgres' , "DROP TABLESPACE tblspc3;" ) ;
rmtree ( "$tempdir/tarbackup_l3" ) ;
2022-01-18 00:40:00 +01:00
$ node - > command_ok ( [ @ pg_basebackup_defs , '-D' , "$tempdir/backupR" , '-R' ] ,
2015-07-01 03:15:05 +02:00
'pg_basebackup -R runs' ) ;
2018-11-25 16:31:16 +01:00
ok ( - f "$tempdir/backupR/postgresql.auto.conf" , 'postgresql.auto.conf exists' ) ;
ok ( - f "$tempdir/backupR/standby.signal" , 'standby.signal was created' ) ;
my $ recovery_conf = slurp_file "$tempdir/backupR/postgresql.auto.conf" ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupR" ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
2015-12-07 23:25:31 +01:00
my $ port = $ node - > port ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
like (
$ recovery_conf ,
Change qr/foo$/m to qr/foo\n/m, for Perl 5.8.8.
In each case, absence of a trailing newline would itself constitute a
PostgreSQL bug. Therefore, this slightly enhances the changed tests.
This works around a bug that last appeared in Perl 5.8.8, fixing
src/test/modules/test_pg_dump when run against that version. Commit
e7293e3271bf618eeb2d4779a15fc516a69fe463 worked around the bug, but the
subsequent addition of test_pg_dump introduced affected code. As that
commit had shown, slight increases in pattern complexity can suppress
the bug. This commit edits qr/foo$/m patterns too complex to encounter
the bug today, for style consistency and robustness against unrelated
pattern changes. Back-patch to 9.6, where test_pg_dump was introduced.
As of this writing, a fresh MSYS installation includes an affected Perl
5.8.8. The Perl 5.8.8 in Red Hat Enterprise Linux 5.11 carries a patch
that renders it unaffected, but the Perl 5.8.5 of Red Hat Enterprise
Linux 4.4 is affected.
2016-11-08 02:27:30 +01:00
qr/^primary_conninfo = '.*port=$port.*'\n/ m ,
2018-11-25 16:31:16 +01:00
'postgresql.auto.conf sets primary_conninfo' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
2017-01-04 10:40:38 +01:00
$ node - > command_ok (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxd" ] ,
2017-01-04 10:40:38 +01:00
'pg_basebackup runs in default xlog mode' ) ;
ok ( grep ( /^[0-9A-F]{24}$/ , slurp_dir ( "$tempdir/backupxd/pg_wal" ) ) ,
'WAL files copied' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxd" ) ;
2017-01-04 10:40:38 +01:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_ok (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxf" , '-X' , 'fetch' ] ,
2015-07-01 03:15:29 +02:00
'pg_basebackup -X fetch runs' ) ;
2016-10-20 17:24:37 +02:00
ok ( grep ( /^[0-9A-F]{24}$/ , slurp_dir ( "$tempdir/backupxf/pg_wal" ) ) ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
'WAL files copied' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxf" ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_ok (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxs" , '-X' , 'stream' ] ,
2015-07-01 03:15:29 +02:00
'pg_basebackup -X stream runs' ) ;
2018-04-06 22:23:23 +02:00
ok ( grep ( /^[0-9A-F]{24}$/ , slurp_dir ( "$tempdir/backupxs/pg_wal" ) ) ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
'WAL files copied' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxs" ) ;
2016-10-23 15:16:31 +02:00
$ node - > command_ok (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxst" , '-X' , 'stream' , '-Ft' ] ,
2016-10-23 15:16:31 +02:00
'pg_basebackup -X stream runs in tar mode' ) ;
ok ( - f "$tempdir/backupxst/pg_wal.tar" , "tar file was created" ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxst" ) ;
2017-01-16 13:56:43 +01:00
$ node - > command_ok (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
2017-01-16 13:56:43 +01:00
"$tempdir/backupnoslot" , '-X' ,
2018-05-09 16:14:46 +02:00
'stream' , '--no-slot'
] ,
2017-01-16 13:56:43 +01:00
'pg_basebackup -X stream runs with --no-slot' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupnoslot" ) ;
2015-07-22 03:06:45 +02:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_fails (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
"$tempdir/backupxs_sl_fail" , '-X' ,
'stream' , '-S' ,
2018-05-09 16:14:46 +02:00
'slot0'
] ,
2015-07-22 03:06:45 +02:00
'pg_basebackup fails with nonexistent replication slot' ) ;
2017-09-26 22:07:52 +02:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxs_slot" , '-C' ] ,
2017-09-26 22:07:52 +02:00
'pg_basebackup -C fails without slot name' ) ;
$ node - > command_fails (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
2017-09-26 22:07:52 +02:00
"$tempdir/backupxs_slot" , '-C' ,
'-S' , 'slot0' ,
2018-05-09 16:14:46 +02:00
'--no-slot'
] ,
2017-09-26 22:07:52 +02:00
'pg_basebackup fails with -C -S --no-slot' ) ;
$ node - > command_ok (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxs_slot" , '-C' , '-S' , 'slot0' ] ,
2017-09-26 22:07:52 +02:00
'pg_basebackup -C runs' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxs_slot" ) ;
2017-09-26 22:07:52 +02:00
is ( $ node - > safe_psql (
'postgres' ,
2018-04-26 17:52:52 +02:00
q{ SELECT slot_name FROM pg_replication_slots WHERE slot_name = 'slot0' }
) ,
2017-09-26 22:07:52 +02:00
'slot0' ,
'replication slot was created' ) ;
isnt (
$ node - > safe_psql (
'postgres' ,
2018-04-26 17:52:52 +02:00
q{ SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot0' }
) ,
2017-09-26 22:07:52 +02:00
'' ,
'restart LSN of new slot is not null' ) ;
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backupxs_slot1" , '-C' , '-S' , 'slot0' ] ,
2017-09-26 22:07:52 +02:00
'pg_basebackup fails with -C -S and a previously existing slot' ) ;
2016-03-03 21:58:30 +01:00
$ node - > safe_psql ( 'postgres' ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
q{ SELECT * FROM pg_create_physical_replication_slot('slot1') } ) ;
2016-03-03 21:58:30 +01:00
my $ lsn = $ node - > safe_psql ( 'postgres' ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
q{ SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot1' }
) ;
2015-07-22 03:06:45 +02:00
is ( $ lsn , '' , 'restart LSN of new slot is null' ) ;
2017-09-24 04:59:26 +02:00
$ node - > command_fails (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/fail" , '-S' , 'slot1' , '-X' , 'none' ] ,
2017-09-24 04:59:26 +02:00
'pg_basebackup with replication slot fails without WAL streaming' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_ok (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' , "$tempdir/backupxs_sl" , '-X' ,
'stream' , '-S' , 'slot1'
2018-05-09 16:14:46 +02:00
] ,
2015-07-22 03:06:45 +02:00
'pg_basebackup -X stream with replication slot runs' ) ;
2016-03-03 21:58:30 +01:00
$ lsn = $ node - > safe_psql ( 'postgres' ,
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
q{ SELECT restart_lsn FROM pg_replication_slots WHERE slot_name = 'slot1' }
) ;
2015-07-29 18:17:02 +02:00
like ( $ lsn , qr!^0/[0-9A-Z]{7,8}$! , 'restart LSN of slot has advanced' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxs_sl" ) ;
2015-07-22 03:06:45 +02:00
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
$ node - > command_ok (
2018-05-09 16:14:46 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' , "$tempdir/backupxs_sl_R" , '-X' ,
'stream' , '-S' , 'slot1' , '-R' ,
2018-05-09 16:14:46 +02:00
] ,
2015-07-22 03:06:45 +02:00
'pg_basebackup with replication slot and -R runs' ) ;
Refactor Perl test code
The original code was a bit clunky; make it more amenable for further
reuse by creating a new Perl package PostgresNode, which is an
object-oriented representation of a single server, with some support
routines such as init, start, stop, psql. This serves as a better basis
on which to build further test code, and enables writing tests that use
more than one server without too much complication.
This commit modifies a lot of the existing test files, mostly to remove
explicit calls to system commands (pg_ctl) replacing them with method
calls of a PostgresNode object. The result is quite a bit more
straightforward.
Also move some initialization code to BEGIN and INIT blocks instead of
having it straight in as top-level code.
This commit also introduces package RecursiveCopy so that we can copy
whole directories without having to depend on packages that may not be
present on vanilla Perl 5.8 installations.
I also ran perltidy on the modified files, which changes some code sites
that are not otherwise touched by this patch. I tried to avoid this,
but it ended up being more trouble than it's worth.
Authors: Michael Paquier, Álvaro Herrera
Review: Noah Misch
2015-12-02 22:46:16 +01:00
like (
2018-11-25 16:31:16 +01:00
slurp_file ( "$tempdir/backupxs_sl_R/postgresql.auto.conf" ) ,
Change qr/foo$/m to qr/foo\n/m, for Perl 5.8.8.
In each case, absence of a trailing newline would itself constitute a
PostgreSQL bug. Therefore, this slightly enhances the changed tests.
This works around a bug that last appeared in Perl 5.8.8, fixing
src/test/modules/test_pg_dump when run against that version. Commit
e7293e3271bf618eeb2d4779a15fc516a69fe463 worked around the bug, but the
subsequent addition of test_pg_dump introduced affected code. As that
commit had shown, slight increases in pattern complexity can suppress
the bug. This commit edits qr/foo$/m patterns too complex to encounter
the bug today, for style consistency and robustness against unrelated
pattern changes. Back-patch to 9.6, where test_pg_dump was introduced.
As of this writing, a fresh MSYS installation includes an affected Perl
5.8.8. The Perl 5.8.8 in Red Hat Enterprise Linux 5.11 carries a patch
that renders it unaffected, but the Perl 5.8.5 of Red Hat Enterprise
Linux 4.4 is affected.
2016-11-08 02:27:30 +01:00
qr/^primary_slot_name = 'slot1'\n/ m ,
2018-11-25 16:31:16 +01:00
'recovery conf file sets primary_slot_name' ) ;
2018-04-03 13:47:16 +02:00
my $ checksum = $ node - > safe_psql ( 'postgres' , 'SHOW data_checksums;' ) ;
is ( $ checksum , 'on' , 'checksums are enabled' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backupxs_sl_R" ) ;
2018-04-03 13:47:16 +02:00
2018-04-04 11:35:48 +02:00
# create tables to corrupt and get their relfilenodes
my $ file_corrupt1 = $ node - > safe_psql ( 'postgres' ,
2021-01-28 14:01:41 +01:00
q{ CREATE TABLE corrupt1 AS SELECT a FROM generate_series(1,10000) AS a; ALTER TABLE corrupt1 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt1') }
2018-04-03 13:47:16 +02:00
) ;
2018-04-04 11:35:48 +02:00
my $ file_corrupt2 = $ node - > safe_psql ( 'postgres' ,
2021-01-28 14:01:41 +01:00
q{ CREATE TABLE corrupt2 AS SELECT b FROM generate_series(1,2) AS b; ALTER TABLE corrupt2 SET (autovacuum_enabled=false); SELECT pg_relation_filepath('corrupt2') }
2018-04-03 13:47:16 +02:00
) ;
2018-04-04 11:35:48 +02:00
# set page header and block sizes
my $ pageheader_size = 24 ;
2020-07-16 20:48:37 +02:00
my $ block_size = $ node - > safe_psql ( 'postgres' , 'SHOW block_size;' ) ;
2018-04-04 11:35:48 +02:00
2018-04-03 13:47:16 +02:00
# induce corruption
2018-04-04 11:35:48 +02:00
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'stop' ;
open $ file , '+<' , "$pgdata/$file_corrupt1" ;
2021-04-19 03:15:35 +02:00
seek ( $ file , $ pageheader_size , SEEK_SET ) ;
2019-02-18 06:23:30 +01:00
syswrite ( $ file , "\0\0\0\0\0\0\0\0\0" ) ;
2018-04-03 13:47:16 +02:00
close $ file ;
2018-04-04 11:35:48 +02:00
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'start' ;
2018-04-03 13:47:16 +02:00
$ node - > command_checks_all (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_corrupt" ] ,
2018-04-03 13:47:16 +02:00
1 ,
[ qr{ ^$ } ] ,
[ qr/^WARNING.*checksum verification failed/ s ] ,
'pg_basebackup reports checksum mismatch' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backup_corrupt" ) ;
2018-04-03 13:47:16 +02:00
# induce further corruption in 5 more blocks
2018-04-04 11:35:48 +02:00
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'stop' ;
open $ file , '+<' , "$pgdata/$file_corrupt1" ;
for my $ i ( 1 .. 5 )
{
my $ offset = $ pageheader_size + $ i * $ block_size ;
2021-04-19 03:15:35 +02:00
seek ( $ file , $ offset , SEEK_SET ) ;
2019-02-18 06:23:30 +01:00
syswrite ( $ file , "\0\0\0\0\0\0\0\0\0" ) ;
2018-04-03 13:47:16 +02:00
}
close $ file ;
2018-04-04 11:35:48 +02:00
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'start' ;
2018-04-03 13:47:16 +02:00
$ node - > command_checks_all (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_corrupt2" ] ,
2018-04-03 13:47:16 +02:00
1 ,
[ qr{ ^$ } ] ,
[ qr/^WARNING.*further.*failures.*will.not.be.reported/ s ] ,
'pg_basebackup does not report more than 5 checksum mismatches' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backup_corrupt2" ) ;
2018-04-03 13:47:16 +02:00
# induce corruption in a second file
2018-04-04 11:35:48 +02:00
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'stop' ;
open $ file , '+<' , "$pgdata/$file_corrupt2" ;
2021-04-19 03:15:35 +02:00
seek ( $ file , $ pageheader_size , SEEK_SET ) ;
2019-02-18 06:23:30 +01:00
syswrite ( $ file , "\0\0\0\0\0\0\0\0\0" ) ;
2018-04-03 13:47:16 +02:00
close $ file ;
2018-04-04 11:35:48 +02:00
system_or_bail 'pg_ctl' , '-D' , $ pgdata , 'start' ;
2018-04-03 13:47:16 +02:00
$ node - > command_checks_all (
2022-01-18 00:40:00 +01:00
[ @ pg_basebackup_defs , '-D' , "$tempdir/backup_corrupt3" ] ,
2018-04-03 13:47:16 +02:00
1 ,
[ qr{ ^$ } ] ,
[ qr/^WARNING.*7 total checksum verification failures/ s ] ,
'pg_basebackup correctly report the total number of checksum mismatches' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backup_corrupt3" ) ;
2018-04-03 13:47:16 +02:00
# do not verify checksums, should return ok
$ node - > command_ok (
2018-05-21 16:01:49 +02:00
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
"$tempdir/backup_corrupt4" , '--no-verify-checksums' ,
2018-05-21 16:01:49 +02:00
] ,
2018-04-03 13:47:16 +02:00
'pg_basebackup with -k does not report checksum mismatch' ) ;
2018-04-06 22:26:31 +02:00
rmtree ( "$tempdir/backup_corrupt4" ) ;
2018-04-04 11:35:48 +02:00
$ node - > safe_psql ( 'postgres' , "DROP TABLE corrupt1;" ) ;
$ node - > safe_psql ( 'postgres' , "DROP TABLE corrupt2;" ) ;
2022-01-07 06:13:35 +01:00
note "Testing pg_basebackup with compression methods" ;
# Check ZLIB compression if available.
SKIP:
{
2022-01-08 01:12:21 +01:00
skip "postgres was not built with ZLIB support" , 5
2022-01-07 06:13:35 +01:00
if ( ! check_pg_config ( "#define HAVE_LIBZ 1" ) ) ;
$ node - > command_ok (
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
2022-01-07 06:13:35 +01:00
"$tempdir/backup_gzip" , '--compress' ,
2022-01-18 00:40:00 +01:00
'1' , '--format' ,
't'
2022-01-07 06:13:35 +01:00
] ,
'pg_basebackup with --compress' ) ;
2022-01-08 01:12:21 +01:00
$ node - > command_ok (
[
2022-01-18 00:40:00 +01:00
@ pg_basebackup_defs , '-D' ,
2022-01-08 01:12:21 +01:00
"$tempdir/backup_gzip2" , '--gzip' ,
2022-01-18 00:40:00 +01:00
'--format' , 't'
2022-01-08 01:12:21 +01:00
] ,
'pg_basebackup with --gzip' ) ;
2022-01-07 06:13:35 +01:00
# Verify that the stored files are generated with their expected
# names.
my @ zlib_files = glob "$tempdir/backup_gzip/*.tar.gz" ;
is ( scalar ( @ zlib_files ) , 2 ,
2022-01-08 01:12:21 +01:00
"two files created with --compress (base.tar.gz and pg_wal.tar.gz)" ) ;
my @ zlib_files2 = glob "$tempdir/backup_gzip2/*.tar.gz" ;
is ( scalar ( @ zlib_files2 ) , 2 ,
"two files created with --gzip (base.tar.gz and pg_wal.tar.gz)" ) ;
2022-01-07 06:13:35 +01:00
# Check the integrity of the files generated.
my $ gzip = $ ENV { GZIP_PROGRAM } ;
skip "program gzip is not found in your system" , 1
if ( ! defined $ gzip
|| $ gzip eq ''
|| system_log ( $ gzip , '--version' ) != 0 ) ;
2022-01-08 01:12:21 +01:00
my $ gzip_is_valid =
system_log ( $ gzip , '--test' , @ zlib_files , @ zlib_files2 ) ;
2022-01-07 06:13:35 +01:00
is ( $ gzip_is_valid , 0 , "gzip verified the integrity of compressed data" ) ;
rmtree ( "$tempdir/backup_gzip" ) ;
2022-01-08 01:12:21 +01:00
rmtree ( "$tempdir/backup_gzip2" ) ;
2022-01-07 06:13:35 +01:00
}