diff --git a/src/bin/pg_resetwal/.gitignore b/src/bin/pg_resetwal/.gitignore index 236abb4323..a950255fd7 100644 --- a/src/bin/pg_resetwal/.gitignore +++ b/src/bin/pg_resetwal/.gitignore @@ -1 +1,2 @@ /pg_resetwal +/tmp_check diff --git a/src/bin/pg_resetwal/Makefile b/src/bin/pg_resetwal/Makefile index 5ab7ad33e0..13c9ca6279 100644 --- a/src/bin/pg_resetwal/Makefile +++ b/src/bin/pg_resetwal/Makefile @@ -33,3 +33,9 @@ uninstall: clean distclean maintainer-clean: rm -f pg_resetwal$(X) $(OBJS) + +check: + $(prove_check) + +installcheck: + $(prove_installcheck) diff --git a/src/bin/pg_resetwal/t/001_basic.pl b/src/bin/pg_resetwal/t/001_basic.pl new file mode 100644 index 0000000000..234bd70303 --- /dev/null +++ b/src/bin/pg_resetwal/t/001_basic.pl @@ -0,0 +1,53 @@ +use strict; +use warnings; + +use Config; +use PostgresNode; +use TestLib; +use Test::More tests => 13; + +my $tempdir = TestLib::tempdir; +my $tempdir_short = TestLib::tempdir_short; + +program_help_ok('pg_resetwal'); +program_version_ok('pg_resetwal'); +program_options_handling_ok('pg_resetwal'); + +# Initialize node without replication settings +my $node = get_new_node('main'); +my $pgdata = $node->data_dir; +my $pgwal = "$pgdata/pg_wal"; +$node->init; +$node->start; + +# Remove WAL from pg_wal and make sure it gets rebuilt +$node->stop; + +unlink("$pgwal/000000010000000000000001") == 1 + or die("unable to remove 000000010000000000000001"); + +is_deeply( + [sort(slurp_dir($pgwal))], [sort(qw(. .. archive_status))], 'no WAL'); + +$node->command_ok(['pg_resetwal', '-D', $pgdata], 'recreate pg_wal'); + +is_deeply( + [sort(slurp_dir($pgwal))], + [sort(qw(. .. archive_status 000000010000000000000002))], + 'WAL recreated'); + +$node->start; + +# Reset to specific WAL segment +$node->stop; + +$node->command_ok( + ['pg_resetwal', '-l', '000000070000000700000007', '-D', $pgdata], + 'set to specific WAL'); + +is_deeply( + [sort(slurp_dir($pgwal))], + [sort(qw(. .. archive_status 000000070000000700000007))], + 'WAL recreated'); + +$node->start;