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
- Check compatibility — extensions available in 16? Deprecated features? Read release notes.
- Test the upgrade on a restored copy of production; run app tests against it.
- Back up right before.
- Choose the method:
Method Downtime Notes dump/restore Long for big DBs Simplest, also cleans bloat pg_upgrade --linkMinutes 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 - 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."
More on PostgreSQL
How do you set up PostgreSQL and log in with psql?BeginnerHow do you create a database, tables, users and query data in PostgreSQL?BeginnerHow do you back up and restore a PostgreSQL database?BeginnerWhat is PostgreSQL and why is it so popular?BeginnerHow is PostgreSQL organised: cluster, database, schema and table?BeginnerHow do you connect to PostgreSQL from the command line?Beginner