summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2026-08-19 00:51:59 +0000
committerMichael Paquier2026-08-19 00:51:59 +0000
commitf555ada9e149bb9430c1597ba60b21fb119be04d (patch)
treefd8bc9011b0c74db4a44b32399e1e68633277a22
parentaecc864821ad868618166d06f1bbdd892a73e19d (diff)
Report single-page checksum failures in pg_stat_database
Base backups reported checksum failures to pg_stat_database only for files with more than one failing page. Commit 6b9e875f728 placed the report inside the block emitting the per-file summary WARNING, which was skipped for a single failure. As a result, a backup failing on files with one corrupted page each left checksum_failures untouched. To fix, emit the per-file summary and the pgstat report for any non-zero failure count. The end-of-backup total WARNING had the same off-by-one and is now also emitted for a single failure. Author: Zsolt Parragi <zsolt.parragi@percona.com> Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/CAN4CZFN+Bi6XmaH8zOdMWjoycYFx9nKtOr+dzQf0o-UQ+Rdqmw@mail.gmail.com Backpatch-through: 14
-rw-r--r--src/backend/backup/basebackup.c13
-rw-r--r--src/bin/pg_basebackup/t/010_pg_basebackup.pl14
2 files changed, 20 insertions, 7 deletions
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index cb87612d490..5458aefbb1c 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -625,12 +625,11 @@ perform_base_backup(basebackup_options *opt, bbsink *sink)
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),
@@ -1709,7 +1708,7 @@ sendFile(bbsink *sink, 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 ef82297d659..d7f878a44db 100644
--- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl
+++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
@@ -802,6 +802,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)
@@ -831,6 +838,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(
[