Home›Operate›Major version upgrades
Course · ArchitectureLesson 28 of 330 read
Decision 11 · Major version upgrades

How do you upgrade a database without a long outage or a surprise?

Which upgrade path, and how do you know the new version will not be slower?

Major upgrades come every year or two and are easy to put off until the old version is out of support. This page picks a side, shows each engine's paths, and lists what actually goes wrong: usually not the upgrade itself, but plans, settings and clients afterwards.

The decision

Upgrade through a replica on the new version, rehearsed on a copy, with a way back

I prefer to build the new version next to the old one, keep it in step with replication, test against it, and switch over in a short window. The old primary stays untouched, so going back is a switch, not a restore, but only for data written before cutover. Once the new version accepts writes, switching back loses those writes, because no replication runs from the new version back to the old one. In-place upgrades are fine for small databases or when a short outage is acceptable, but they leave no easy way back.

Before any of it, I rehearse on a restored copy: run the upgrade, replay a sample of real queries, compare their plans and timings, and write down how long each step took.

In one line. New version beside the old, kept in step, tested with real queries, switched in minutes, with the old primary kept as the way back for data written before cutover only.

How each engine does it

The paths, from simplest to safest

PostgreSQL

  • In place: pg_upgrade. With --link (hard links) or --clone it takes minutes even for large databases, but the old cluster cannot be started again after the new one runs with --link.
  • Beside: logical replication from the old version to a new cluster (publications and subscriptions, version 10 and later), then switch. Sequences and DDL are not replicated; copy sequence values at the switch.
  • Afterwards: before 18, pg_upgrade did not carry planner statistics, so run vacuumdb --all --analyze-in-stages straight away. 18 keeps them, except extended statistics, which still need regenerating after the upgrade.
  • Every extension must exist in a version built for the new release.

MySQL

  • In place: stop, install the new binaries, start. Since 8.0.16 the server upgrades the data dictionary and system tables itself.
  • Beside: add a replica on the new version (a newer replica can replicate from an older source, not the other way), let it catch up, then switch.
  • Run MySQL Shell's util.checkForServerUpgrade() first. It lists removed features, reserved words and settings that will fail.
  • 8.0 reached end of life in April 2026. 8.4 is the long-term release; 9.x are short-lived innovation releases.

MongoDB

  • Rolling: upgrade the secondaries one at a time, step the primary down, upgrade it. One major version at a time: 6.0 to 7.0 to 8.0.
  • The binaries change first; new features and on-disk formats wait for setFeatureCompatibilityVersion. Until you set it, going back to the old binaries is possible.
  • Set the feature compatibility version only after the cluster has run well for a while on the new binaries.
  • Check that every driver is a version that supports the new server.

On managed services, the same ideas have product names: Amazon RDS and Aurora blue/green deployments build the new version beside the old with replication and switch in about a minute; Atlas upgrades replica sets in a rolling way.

What breaks

Usually after the upgrade, not during it

What happensWhyWhat I do
Queries are slow for the first hourPlanner statistics missing after pg_upgrade (before 18)Analyze in stages as the first step after starting.
A few queries are slower for goodThe new optimizer picks a different planCapture plans for the top queries before; compare after, on the rehearsal copy.
Applications cannot log inAuthentication defaults changed: MySQL 8.4 disables mysql_native_password by defaultCheck client libraries and user plugins during the rehearsal.
The upgrade refuses to startAn extension, a removed setting, or a reserved word in the schemaRun the upgrade checks (pg_upgrade --check, util.checkForServerUpgrade()) weeks before.
No way backIn-place upgrade with links, or MongoDB feature compatibility already setKeep the old primary or a backup taken just before; set FCV late. Either option loses writes made on the new version after cutover; the way back is only safe before cutover traffic.
Replication breaks during the switchWrites still going to the old primaryStop writes, wait for zero lag, then switch; check sequences and identity values.
Alternatives rejected

Why not just...

How to operate it

The rehearsal checklist

-- PostgreSQL: check, then upgrade with hard links
pg_upgrade --check -b /usr/lib/postgresql/17/bin -B /usr/lib/postgresql/18/bin \
  -d /data/17 -D /data/18
pg_upgrade --link   -b /usr/lib/postgresql/17/bin -B /usr/lib/postgresql/18/bin \
  -d /data/17 -D /data/18
vacuumdb --all --analyze-in-stages      # needed before 18

-- MySQL: what will fail?
mysqlsh -- util checkForServerUpgrade root@localhost:3306 --target-version=8.4.0

-- MongoDB: where is the cluster now?
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 })
db.adminCommand({ setFeatureCompatibilityVersion: "8.0", confirm: true })
Version notes

Support windows and recent changes

Your turn

A 3 TB PostgreSQL 14 database must move to 18. The business accepts 15 minutes of downtime. Which path, and what would you check first?

Write your answer down first. Then open mine.

Show my answer

Path: logical replication into a new 18 cluster, or a managed blue/green deployment if it is on RDS. pg_upgrade --link would also fit inside 15 minutes, but leaves no quick way back.

Check first: every table has a primary key or replica identity (logical replication needs it for updates and deletes); extensions exist for 18; large objects and DDL are not replicated; sequences need copying at the switch.

Then: rehearse on a restored copy, compare the top queries' plans, and keep the 14 primary running, read-only, as the way back until cutover traffic starts. Once the new version accepts writes, switching back loses them, so the rollback window closes at cutover.

Connected

Where this shows up

The same mechanism, migrations and upgrades, elsewhere on the site: in real incidents, in measurements, and in designs.

Check yourself · 4 questions

Check yourself

Pick an answer. You will see whether it is right, and why.

1. Which way can MySQL replicate across versions?

2. After pg_upgrade on PostgreSQL 17, queries are slow. What is the first thing to run?

3. In MongoDB, what keeps a downgrade possible after upgrading the binaries?

4. Why rehearse on a restored copy of production?

Part 4 of 4 · Operate · 15 pagesAll pages

How do I run it in production? What to check when it is slow or broken, where it runs and what it costs, how big it must be, pooling, backups, security, upgrades and other changes made safely.