From 9c081ed3cff8354ad031498dfb219ab34a15315c Mon Sep 17 00:00:00 2001 From: Jacob Champion Date: Thu, 3 Sep 2026 10:42:48 -0700 Subject: [PATCH] WIP: pg_checksums: Ignore more stray files in directories Commit 025584a16 taught pg_basebackup to ignore files that don't belong to the cluster during checksum operations, but pg_checksums itself was left as-is. Align them better by having pg_checksums continue past files that don't contain a valid segment number. TODO: To align them completely, look into parse_filename_for_nontemp_relation() For PG20 only. The inconsistency is odd, but it doesn't seem to rise to bug level to me. Reported-by: Edwin Polkerman Discussion: https://postgr.es/m/CAOYmi%2B%3DE0zz%2B_MgQXAoOyn5C0vW53740izzRiTv6excqtCJfRg%40mail.gmail.com --- src/bin/pg_checksums/pg_checksums.c | 8 ++++---- src/bin/pg_checksums/t/002_actions.pl | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index 3b3ae23f1a6..fc3e9c5dc21 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -102,8 +102,6 @@ struct exclude_list_item /* * List of files excluded from checksum validation. - * - * Note: this list should be kept in sync with what basebackup.c includes. */ static const struct exclude_list_item skip[] = { {"pg_control", false}, @@ -360,8 +358,10 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly) *segmentpath++ = '\0'; segmentno = atoi(segmentpath); if (segmentno == 0) - pg_fatal("invalid segment number %d in file name \"%s\"", - segmentno, fn); + { + /* not a valid segment */ + continue; + } } forkpath = strchr(fnonly, '_'); diff --git a/src/bin/pg_checksums/t/002_actions.pl b/src/bin/pg_checksums/t/002_actions.pl index 94a11a534e9..bef9b0d2d13 100644 --- a/src/bin/pg_checksums/t/002_actions.pl +++ b/src/bin/pg_checksums/t/002_actions.pl @@ -124,6 +124,10 @@ append_to_file "$pgdata/global/pg_internal.init.123", "foo"; append_to_file "$pgdata/global/.DS_Store", "foo" unless ($Config{osname} eq 'darwin'); +# This is a file that doesn't look anything like our relfile segments, so it +# should be ignored. +append_to_file "$pgdata/global/bar.baz", "foo"; + # Enable checksums. command_ok([ 'pg_checksums', '--enable', '--no-sync', '--pgdata' => $pgdata ], "checksums successfully enabled in cluster"); -- 2.34.1