How would you upgrade a PostgreSQL major version (e.g. 14 to 16)?

IntermediateScenarioPostgreSQL
Answer

Short answer

Major versions change the on-disk format, so you can't just restart on new binaries. Options: pg_dump/pg_restore into a new server (simple, longer downtime), pg_upgrade (fast, in place with --link), or logical replication to a new-version server and switch over (near-zero downtime). Managed services offer an in-place major upgrade or blue/green.

Plan

  1. Check compatibility — extensions available in 16? Deprecated features? Read release notes.
  2. Test the upgrade on a restored copy of production; run app tests against it.
  3. Back up right before.
  4. Choose the method:
    Method Downtime Notes
    dump/restore Long for big DBs Simplest, also cleans bloat
    pg_upgrade --link Minutes Same host, needs both versions installed
    Logical replication Seconds Replicate to new server, cut over, more steps
    RDS Blue/Green / Azure in-place Minutes Managed, test in staging first
  5. After: ANALYZE (vacuumdb --analyze-in-stages) — planner statistics aren't carried over by pg_upgrade; update extensions.

What to say in the interview

"Major upgrades need dump/restore, pg_upgrade or logical replication. I test on a production copy, verify extensions, back up, then pick based on downtime tolerance — pg_upgrade with link mode for minutes, logical replication or RDS blue/green for near-zero — and run ANALYZE afterwards."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: PostgreSQL basics

More on PostgreSQL