From a85112d87ec4bc4b00d22c105b9958a2c70c3758 Mon Sep 17 00:00:00 2001
From: Michael Paquier
Date: Mon, 18 Mar 2019 17:12:15 +0900
Subject: [PATCH] Add options to enable and disable checksums in pg_checksums
An offline cluster can now work with more modes in pg_checksums:
- --enable can enable checksums in a cluster, updating all blocks with a
correct checksum, and update the control file at the end.
- --disable can disable checksums in a cluster, updating the the control
file.
- --check is an extra option able to verify checksums for a cluster.
When using --disable, only the control file is updated and then
flushed. When using --enable, the process gets more complicated as the
operation can be long:
- Rename the control file to a temporary name, to prevent a parallel
startup of Postgres.
- Scan all files and update their checksums.
- Rename back the control file.
- Flush the data directory.
- Update the control file and then flush it, to make the change
durable.
If the operation is interrupted, the control file gets moved back in
place.
If no mode is specified in the options, then --check is used for
compatibility with older versions of pg_verify_checksums (now renamed to
pg_checksums in v12).
Author: Michael Banck, Michael Paquier
Reviewed-by: Fabien Coelho, Magnus Hagander, Sergei Kornilov
Discussion: https://postgr.es/m/20181221201616.GD4974@nighthawk.caipicrew.dd-dns.de
---
doc/src/sgml/ref/pg_checksums.sgml | 72 ++++++-
src/bin/pg_checksums/pg_checksums.c | 280 +++++++++++++++++++++++---
src/bin/pg_checksums/t/002_actions.pl | 76 +++++--
src/tools/pgindent/typedefs.list | 1 +
4 files changed, 381 insertions(+), 48 deletions(-)
diff --git a/doc/src/sgml/ref/pg_checksums.sgml b/doc/src/sgml/ref/pg_checksums.sgml
index 6a47dda683..a7f4ef1024 100644
--- a/doc/src/sgml/ref/pg_checksums.sgml
+++ b/doc/src/sgml/ref/pg_checksums.sgml
@@ -16,7 +16,7 @@ PostgreSQL documentation
pg_checksums
- verify data checksums in a PostgreSQL database cluster
+ enable, disable or check data checksums in a PostgreSQL database cluster
@@ -36,10 +36,24 @@ PostgreSQL documentation
Description
- pg_checksums verifies data checksums in a
- PostgreSQL cluster. The server must be shut
- down cleanly before running pg_checksums.
- The exit status is zero if there are no checksum errors, otherwise nonzero.
+ pg_checksums checks, enables or disables data
+ checksums in a PostgreSQL cluster. The server
+ must be shut down cleanly before running
+ pg_checksums. The exit status is zero if there
+ are no checksum errors when checking them, and nonzero if at least one
+ checksum failure is detected. If enabling or disabling checksums, the
+ exit status is nonzero if the operation failed.
+
+
+
+ Checking checksums requires to scan every file holding them in the data
+ folder. Disabling checksums requires only an update of the file
+ pg_control. Enabling checksums first renames
+ the file pg_control to
+ pg_control.pg_checksums_in_progress to prevent
+ a parallel startup of the cluster, then it updates all files with
+ checksums, and it finishes by renaming and updating
+ pg_control to mark checksums as enabled.
@@ -60,6 +74,37 @@ PostgreSQL documentation
+
+