skip to content

Upgrading a PostgreSQL 14 cluster to 18, pg_upgrade --check stops with 'old cluster does not use data checksums but the new one does'. Why, and what are your options?

level: seniorimportance: should knowfreq 38%

answer

  1. 18 changed an initdb default
  2. pages are reused byte for byte
  3. initdb --no-data-checksums
  4. pg_checksums --enable runs offline
  5. standbys must match the primary

basics

~20 s

Since PostgreSQL 18, initdb enables data checksums by default, and pg_upgrade requires both clusters to match. Re-run initdb for 18 with --no-data-checksums, or enable checksums on the old cluster offline with pg_checksums --enable before upgrading.

solid answer

~40 s

`pg_upgrade` reuses the old data pages unchanged, and pages written by a cluster without checksums carry no valid checksum, so a checksum-enabled target would report failures on reads. It therefore compares the `Data page checksum version` in both `pg_controldata` outputs and refuses a mismatch. PostgreSQL 18 made this common because `initdb` now **enables** data checksums by default, while a 14 cluster usually has them off. Options: re-run the 18 `initdb` with `--no-data-checksums` and upgrade as planned, turning checksums on later with `pg_checksums --enable` on the cleanly stopped cluster; or run `pg_checksums --enable` on the stopped 14 cluster before the window. Both cost an offline pass that rewrites each block whose checksum changes, hours on 3 TB. A route that rewrites the data (dump and restore, or a logical cutover) gets checksums for free.

code

console · 4 lines
console
$ /usr/lib/postgresql/14/bin/pg_controldata /srv/pg/14/main | grep checksum
Data page checksum version:           0
$ /usr/lib/postgresql/18/bin/pg_controldata /srv/pg/18/main | grep checksum
Data page checksum version:           1

go deeper

for a junior

Remember that PostgreSQL 18's initdb turns data checksums on by default and that pg_upgrade needs old and new clusters to match.

for a middle

Explain where the setting lives, why pg_upgrade cannot add checksums to reused pages, and which tool takes the --no-data-checksums option.

for a senior

Plan the trade: a short upgrade now and an offline pg_checksums pass later, or the pass first, with every standby switched consistently.

for a principal

Decide checksum policy across the estate: whether integrity detection justifies a separate offline window per cluster or a rewrite-based upgrade route.

## What changed in PostgreSQL 18 **Data checksums** store a checksum in every data page so that corruption introduced by storage is detected when the page is read. Whether a cluster has them is fixed in its control file and visible as `Data page checksum version` in `pg_controldata` (0 means off) or `SHOW data_checksums`. Up to PostgreSQL 17, `initdb` created clusters **without** checksums unless you passed `--data-checksums`. PostgreSQL 18 flipped the default: `initdb` **enables** them, and the new option `--no-data-checksums` opts out. The release notes add that `pg_upgrade` requires matching checksum settings, which is exactly why the opt-out exists. ## Why pg_upgrade insists on a match `pg_upgrade` does not rewrite user data. Whether it copies, links, clones or swaps, the new cluster receives the **same pages** the old one wrote. A page from a non-checksum cluster has no valid checksum, so if the target verified checksums, reads would fail. The source therefore compares both control files and stops with one of three messages: - `old cluster does not use data checksums but the new one does` - `old cluster uses data checksums but the new one does not` - `old and new cluster pg_controldata checksum versions do not match` The first is the one a 14 to 18 upgrade hits whenever the 18 cluster was created with the new default, including by a packaging script that runs `initdb` for you. ## Option 1: create the 18 cluster without checksums 1. Remove the new, still-empty 18 data directory. 2. Re-run `initdb` with `--no-data-checksums` and the other options matching the old cluster. 3. Re-run `pg_upgrade --check`, then the upgrade, in the planned mode. 4. Turn checksums on later in a separate window: stop the cluster cleanly and run `pg_checksums --enable`. This keeps the upgrade outage as short as planned and moves the checksum cost elsewhere. ## Option 2: enable checksums on the old cluster first Run `pg_checksums --enable` against the cleanly stopped 14 cluster before the upgrade window, then upgrade into the default 18 cluster. Same cost, earlier date. ## What pg_checksums --enable costs - The server must be **shut down cleanly**; nothing may write to the data directory during the run, or data loss may occur. - Each relation block whose checksum changes is **rewritten in place**; on a cluster that had none, that is effectively the whole data set, so a 3 TB cluster means hours offline. - If it is interrupted, the checksum configuration stays unchanged and the command can be re-run. - `pg_checksums --disable`, by contrast, only updates `pg_control` and is quick. - In a replication setup, do it **consistently on every node**: stop all clusters and switch each, or rebuild the standbys from the primary afterwards. Mixed settings plus tools that copy blocks directly, such as `pg_rewind`, produce pages with wrong checksums. ## Option 3: a route that rewrites the data Dump and restore or a logical-replication cutover writes every row afresh into the new cluster, so the new default can simply stay on. If the upgrade already needs one of those routes, checksums come at no extra cost. ## Catching it before the window - Compare `Data page checksum version` from `pg_controldata` on both data directories as soon as the 18 cluster exists; a mismatch is visible long before any `pg_upgrade` run. - Read the packaging. The `pg_upgrade` manual notes that many prebuilt installers run `initdb` for you, and on 18 that means checksums on unless the wrapper passes `--no-data-checksums`. - Put the decision in the runbook explicitly: leaving checksums off is a valid choice, but it should be a choice rather than whatever the installer did. - Re-run `pg_upgrade --check` after re-creating the target; the check is cheap and confirms that the control data now matches. ## Comparing the options | Option | Upgrade outage | Extra offline time | When checksums arrive | |---|---|---|---| | `initdb --no-data-checksums`, enable later | As planned | A later `pg_checksums --enable` pass | Later window | | `pg_checksums --enable` on 14 first | As planned | Before the upgrade | Before the upgrade | | Dump and restore or logical cutover | Route-dependent | None | Immediately | | Stay without checksums | As planned | None | Never |

  • After upgrading without checksums, how do you turn them on and what does it cost on a 3 TB database?
    Stop the cluster cleanly and run `pg_checksums --enable -D` on the data directory. It rewrites every block whose checksum changes, which on a cluster that had none is essentially all of it, so plan hours offline. An interrupted run leaves the setting unchanged and can be restarted. Do every node consistently or rebuild the standbys from the primary.
  • Why do the standbys matter when you change the checksum setting?
    Standbys and tools such as `pg_rewind` copy relation blocks directly. If one node has checksums and another does not, copied pages carry wrong checksums and look corrupt. The manual recommends stopping all clusters and switching them consistently, or destroying the standbys, switching the primary and recreating the standbys from it.

  • pg_upgrade recalculates page checksums while it links or copies the data files.
  • Checksums can be turned on in the running 18 server with ALTER SYSTEM SET data_checksums = on.
  • pg_checksums --enable is quick because it only flips a flag in pg_control.
  • The fix is to pass --no-data-checksums to pg_upgrade itself.
  • PostgreSQL 17's initdb already enabled data checksums by default.

Assumes PostgreSQL 18, whose initdb enables data checksums by default; with a 17 or older target, initdb left them off unless asked.