diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index a535180ba41..62e5138c29c 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -717,12 +717,11 @@ perform_base_backup(basebackup_options *opt) if (total_checksum_failures) { - if (total_checksum_failures > 1) - ereport(WARNING, - (errmsg_plural("%lld total checksum verification failure", - "%lld total checksum verification failures", - total_checksum_failures, - total_checksum_failures))); + ereport(WARNING, + (errmsg_plural("%lld total checksum verification failure", + "%lld total checksum verification failures", + total_checksum_failures, + total_checksum_failures))); ereport(ERROR, (errcode(ERRCODE_DATA_CORRUPTED), @@ -1810,7 +1809,7 @@ sendFile(const char *readfilename, const char *tarfilename, CloseTransientFile(fd); - if (checksum_failures > 1) + if (checksum_failures > 0) { ereport(WARNING, (errmsg_plural("file \"%s\" has a total of %d checksum verification failure", diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl index cc04417a3fe..6f9f98402f1 100644 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -9,7 +9,7 @@ use File::Basename qw(basename dirname); use File::Path qw(rmtree); use PostgresNode; use TestLib; -use Test::More tests => 110; +use Test::More tests => 112; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -581,6 +581,13 @@ $node->command_checks_all( 'pg_basebackup reports checksum mismatch'); rmtree("$tempdir/backup_corrupt"); +# Single failure counted in pg_stat_database. +ok( $node->poll_query_until( + 'postgres', + 'SELECT checksum_failures = 1 FROM pg_stat_database ' + . "WHERE datname = 'postgres';"), + 'checksum failure reported in pg_stat_database'); + # induce further corruption in 5 more blocks $node->stop; for my $i (1 .. 5) @@ -610,6 +617,13 @@ $node->command_checks_all( 'pg_basebackup correctly report the total number of checksum mismatches'); rmtree("$tempdir/backup_corrupt3"); +# Failures across all the backups. +ok( $node->poll_query_until( + 'postgres', + 'SELECT checksum_failures = 14 FROM pg_stat_database ' + . "WHERE datname = 'postgres';"), + 'checksum failures accumulated in pg_stat_database'); + # do not verify checksums, should return ok $node->command_ok( [