diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 5452ae139a21ce8deac4483bf6ba90de65289595..959f4231873cbd8f9fe72049a715d9c48a7a5f2b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -60,7 +60,7 @@ #include "utils/timestamp.h" #include "pg_trace.h" -extern bool bootstrap_data_checksums; +extern uint32 bootstrap_data_checksum_version; /* File path names (all relative to $PGDATA) */ #define RECOVERY_COMMAND_FILE "recovery.conf" @@ -3797,7 +3797,7 @@ bool DataChecksumsEnabled(void) { Assert(ControlFile != NULL); - return ControlFile->data_checksums; + return (ControlFile->data_checksum_version > 0); } /* @@ -4126,7 +4126,7 @@ BootStrapXLOG(void) ControlFile->max_prepared_xacts = max_prepared_xacts; ControlFile->max_locks_per_xact = max_locks_per_xact; ControlFile->wal_level = wal_level; - ControlFile->data_checksums = bootstrap_data_checksums; + ControlFile->data_checksum_version = bootstrap_data_checksum_version; /* some additional ControlFile fields are set in WriteControlFile() */ diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 287f19b6eceefdeaa596f9679417fc3bd459349a..9e401ef7a30a0c43f7c11caf249d2dd156ccee86 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -34,6 +34,7 @@ #include "postmaster/walwriter.h" #include "replication/walreceiver.h" #include "storage/bufmgr.h" +#include "storage/bufpage.h" #include "storage/ipc.h" #include "storage/proc.h" #include "tcop/tcopprot.h" @@ -48,7 +49,7 @@ extern int optind; extern char *optarg; -bool bootstrap_data_checksums = false; +uint32 bootstrap_data_checksum_version = 0; /* No checksum */ #define ALLOC(t, c) ((t *) calloc((unsigned)(c), sizeof(t))) @@ -262,7 +263,7 @@ AuxiliaryProcessMain(int argc, char *argv[]) SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV); break; case 'k': - bootstrap_data_checksums = true; + bootstrap_data_checksum_version = PG_DATA_CHECKSUM_VERSION; break; case 'r': strlcpy(OutputFileName, optarg, MAXPGPATH); diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c index ceb412505bf2a51cd15bbde23aead4476d4d613c..a790f99cb51d3649d8bbd2f32ab0065470bccda8 100644 --- a/src/bin/pg_controldata/pg_controldata.c +++ b/src/bin/pg_controldata/pg_controldata.c @@ -287,7 +287,7 @@ main(int argc, char *argv[]) (ControlFile.float4ByVal ? _("by value") : _("by reference"))); printf(_("Float8 argument passing: %s\n"), (ControlFile.float8ByVal ? _("by value") : _("by reference"))); - printf(_("Data page checksums: %s\n"), - (ControlFile.data_checksums ? _("enabled") : _("disabled"))); + printf(_("Data page checksum version: %u\n"), + ControlFile.data_checksum_version); return 0; } diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c index 124dcfb7772ae4c963da1ffca68319ad7382516c..9c340b2db590bd1ff2fc5e11f3c50cb253ce3d5c 100644 --- a/src/bin/pg_resetxlog/pg_resetxlog.c +++ b/src/bin/pg_resetxlog/pg_resetxlog.c @@ -624,8 +624,8 @@ PrintControlValues(bool guessed) (ControlFile.float4ByVal ? _("by value") : _("by reference"))); printf(_("Float8 argument passing: %s\n"), (ControlFile.float8ByVal ? _("by value") : _("by reference"))); - printf(_("Data page checksums: %s\n"), - (ControlFile.data_checksums ? _("enabled") : _("disabled"))); + printf(_("Data page checksum version: %u\n"), + ControlFile.data_checksum_version); } diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h index 1d003d6d7a093a16ef468fe0cf0f260cf5ae70f4..dfe6aacdf70d8bfdaab1bc30e74e92f8051aad80 100644 --- a/src/include/catalog/pg_control.h +++ b/src/include/catalog/pg_control.h @@ -213,8 +213,8 @@ typedef struct ControlFileData bool float4ByVal; /* float4 pass-by-value? */ bool float8ByVal; /* float8, int8, etc pass-by-value? */ - /* Are data pages protected by checksums? */ - bool data_checksums; + /* Are data pages protected by checksums? Zero if no checksum version */ + uint32 data_checksum_version; /* CRC of all above ... MUST BE LAST! */ pg_crc32 crc; diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index b9ee7c27e10dc134c79a7addc71eb5c62523892f..df581b779f64ba5d523d1ba97fc54007707c92aa 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -189,9 +189,12 @@ typedef PageHeaderData *PageHeader; * Release 8.3 uses 4; it changed the HeapTupleHeader layout again, and * added the pd_flags field (by stealing some bits from pd_tli), * as well as adding the pd_prune_xid field (which enlarges the header). + * + * As of Release 9.3, the checksum version must also be considered when + * handling pages. */ #define PG_PAGE_LAYOUT_VERSION 4 - +#define PG_DATA_CHECKSUM_VERSION 1 /* ---------------------------------------------------------------- * page support macros