Speed up pg_checksums in cases where checksum already set

Greg Sabino Mullane <htamfids@gmail.com>

From: Greg Sabino Mullane <htamfids@gmail.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-05-26T21:23:55Z
Lists: pgsql-hackers

Attachments

The attached patch makes an optimization to pg_checksums which prevents
rewriting the block if the checksum is already what we expect. This can
lead to much faster runs in cases where it is already set (e.g. enabled ->
disabled -> enable, external helper process, interrupted runs, future
parallel processes). There is also an effort to not sync the data directory
if no changes were written. Finally, added a bit more output on how many
files were actually changed, e.g.:

Checksum operation completed
Files scanned:   1236
Blocks scanned:  23283
Files modified:  38
Blocks modified: 19194
pg_checksums: syncing data directory
pg_checksums: updating control file
Checksums enabled in cluster

Cheers,
Greg

Commits

  1. Optimize pg_checksums --enable where checksum is already set