From 33cedf1474a356fe510d4ad32c040c968ef27307 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sun, 15 Apr 2018 14:05:56 +0200 Subject: [PATCH] Don't attempt to verify checksums on new pages Teach both base backups and pg_verify_checksums that if a page is new, it does not have a checksum yet, so it shouldn't be verified. Noted by Tomas Vondra, review by David Steele. --- src/backend/replication/basebackup.c | 4 +++- src/bin/pg_verify_checksums/pg_verify_checksums.c | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 50c052e993..a79048d233 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -1446,8 +1446,10 @@ sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf * written only halfway and the checksum would not be valid. * However, replaying WAL would reinstate the correct page in * this case. + * We also skip completely new pages, since they don't have + * a checksum yet. */ - if (PageGetLSN(page) < startptr) + if (!PageIsNew(page) && PageGetLSN(page) < startptr) { checksum = pg_checksum_page((char *) page, blkno + segmentno * RELSEG_SIZE); phdr = (PageHeader) page; diff --git a/src/bin/pg_verify_checksums/pg_verify_checksums.c b/src/bin/pg_verify_checksums/pg_verify_checksums.c index d472f1291c..b065d0bb89 100644 --- a/src/bin/pg_verify_checksums/pg_verify_checksums.c +++ b/src/bin/pg_verify_checksums/pg_verify_checksums.c @@ -106,6 +106,10 @@ scan_file(char *fn, int segmentno) } blocks++; + /* New pages have no checksum yet */ + if (PageIsNew(buf)) + continue; + csum = pg_checksum_page(buf, blockno + segmentno * RELSEG_SIZE); if (csum != header->pd_checksum) { -- 2.40.0