Full answer
pg_upgrade:
- Install the new version alongside the old.
- Run
pg_upgrade --check, then stop the old server and runpg_upgrade --link. - Start the new server, run
vacuumdb --analyze-in-stagesto rebuild statistics, which are not carried over in older releases. - Rollback after
--linkis hard once the new server has started, so take a backup or snapshot first.
Logical replication:
- Create the new cluster with the schema.
- Publish tables on the old server and subscribe from the new; initial copy then streaming changes.
- At cut-over: stop writes, wait for the subscriber to catch up, copy sequence values, point the application at the new server.
- The old server remains intact as a fallback.
Either way: test the application against the new version, check extensions are available, and rehearse the steps with timing on a production-sized copy. Described from documentation, not run here.
Key points
- pg_upgrade --link gives short downtime
- Logical replication gives near-zero downtime
- Sequences and DDL need manual handling with logical replication
- Analyze after upgrading
- Rehearse and plan rollback
Common mistakes
- Upgrading in place without a backup
- Forgetting to copy sequence values at cut-over
Follow-ups
- What breaks with extensions during upgrades?
- How would you verify data after switchover?
Tips
- Compare downtime and rollback for both