@@ -117,8 +117,28 @@ func upgradeCommand(spec *v1beta1.PGUpgradeSettings, fetchKeyCommand string) []s
117
117
// steps used and command flag specifics can be found in the documentation:
118
118
// - https://www.postgresql.org/docs/current/pgupgrade.html
119
119
120
+ // Examine the old data directory.
121
+ `control=$(LC_ALL=C PGDATA="${old_data}" "${old_bin}/pg_controldata")` ,
122
+ `read -r checksums <<< "${control##*page checksum version:}"` ,
123
+
124
+ // Data checksums on the old and new data directories must match.
125
+ // Configuring these checksums depends on the version of initdb:
126
+ //
127
+ // - PostgreSQL v17 and earlier: disabled by default, enable with "--data-checksums"
128
+ // - PostgreSQL v18: enabled by default, enable with "--data-checksums", disable with "--no-data-checksums"
129
+ //
130
+ // https://www.postgresql.org/docs/release/18#RELEASE-18-MIGRATION
131
+ //
132
+ // Data page checksum version zero means checksums are disabled.
133
+ // Produce an initdb argument that enables or disables data checksums.
134
+ //
135
+ // https://git.postgresql.org/gitweb/?p=postgresql.git;hb=refs/tags/REL_11_0;f=src/bin/pg_verify_checksums/pg_verify_checksums.c#l303
136
+ // https://git.postgresql.org/gitweb/?p=postgresql.git;hb=refs/tags/REL_12_0;f=src/bin/pg_checksums/pg_checksums.c#l523
137
+ // https://git.postgresql.org/gitweb/?p=postgresql.git;hb=refs/tags/REL_18_0;f=src/bin/pg_checksums/pg_checksums.c#l571
138
+ `checksums=$(if [[ "${checksums}" -gt 0 ]]; then echo '--data-checksums'; elif [[ "${new_version}" -ge 18 ]]; then echo '--no-data-checksums'; fi)` ,
139
+
120
140
`section 'Step 3 of 7: Initializing new data directory...'` ,
121
- `PGDATA="${new_data}" "${new_bin}/initdb" --allow-group-access --data- checksums` + argEncryptionKeyCommand ,
141
+ `PGDATA="${new_data}" "${new_bin}/initdb" --allow-group-access ${ checksums} ` + argEncryptionKeyCommand ,
122
142
123
143
// Read the configured value then quote it; every single-quote U+0027 is replaced by two.
124
144
//
0 commit comments