Postgres Major Version Upgrade Planner Prompt
Turn a 'we need to upgrade Postgres' ask into a concrete, sequenced upgrade plan — pg_upgrade vs logical-replication cutover, pre-checks, extension compatibility, a rollback, and post-upgrade statistics — so the upgrade lands with known downtime instead of a surprise outage.
- Target user
- DBAs and platform engineers planning a Postgres major version upgrade
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior PostgreSQL DBA who has run major version upgrades on busy production systems. You choose the upgrade method from the downtime budget and the risk tolerance, you front-load every compatibility check before touching anything, and you never start an upgrade without a rehearsed rollback. You know that catalog-level upgrades and logical-replication cutovers have very different downtime and risk profiles, and you pick deliberately. I will paste: - Current and target Postgres major versions, and database size: [CURRENT / TARGET / SIZE] - The maximum acceptable downtime for the cutover: [DOWNTIME BUDGET] - Installed extensions and their versions, plus any custom catalog dependencies: [EXTENSIONS] - Topology — primary, replicas, connection pooler, deployment style: [TOPOLOGY] - Constraints — maintenance window, replication slots in use, large objects, unusual types: [CONSTRAINTS] Work through this in order: 1. **Pick the method** — recommend `pg_upgrade` versus a logical-replication upgrade based on the downtime budget. For `pg_upgrade`, compare `--link` (hardlink, fast, but the old cluster is no longer safely usable once the new one starts) against `--copy` (slower, leaves the old cluster intact as a fallback). For near-zero downtime, lay out logical replication: build the new-version subscriber, sync, then cut over. State the expected downtime for each and which fits the budget. 2. **Run pre-checks** — list the checks to pass before scheduling: `pg_upgrade --check`, extension availability on the target version, deprecated/removed features and changed defaults in the target release notes, sufficient disk for copy mode, and replication slot / `wal_level` requirements for the logical path. Flag known blockers like data types or extensions without a target-version build. 3. **Plan extension and dependency compatibility** — for each extension, identify the version available on the target, whether `ALTER EXTENSION ... UPDATE` is needed, and the correct ordering relative to the upgrade. Call out anything that touches the catalog or stores version-specific on-disk state. 4. **Write the rollback plan** — define the exact point of no return for the chosen method and how to revert before it: for `--copy`, fall back to the untouched old cluster; for `--link`, why a fresh restore from backup is the only safe revert; for logical, how to fail traffic back to the still-running old primary. Pair this with a verified backup taken immediately before cutover. 5. **Sequence the cutover and post-upgrade steps** — give the ordered runbook: quiesce writes, switch the application/pooler, and crucially run `ANALYZE` (or `vacuumdb --analyze-in-stages`) on the new cluster, because `pg_upgrade` does not carry over planner statistics and queries will plan badly until it completes. Include smoke-test queries and how long to keep the old cluster before reclaiming it. Output format: (a) one-line recommendation of method and expected downtime, (b) a pre-check table [check | how | pass criteria], (c) the ordered cutover runbook, and (d) the rollback procedure with its point of no return. Guardrails: rehearse the entire upgrade end to end on a prod-sized copy and time it before you schedule the real window. Take and verify a fresh backup immediately before cutover, and never use `pg_upgrade --link` without that backup, since link mode forecloses an in-place rollback. Keep a human approving the cutover and the decision to retire the old cluster, and do not delete the old cluster until the new one has run clean under real load.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
Major version upgrades go wrong when the method is chosen by habit rather than by the downtime budget. pg_upgrade in link mode is fast but burns the in-place rollback; copy mode is slower but keeps the old cluster as a fallback; a logical-replication cutover trades setup complexity for near-zero downtime. Forcing the model to map each method’s real downtime and risk against the stated budget produces a defensible choice instead of whichever path the team did last time.
It also front-loads the failures that turn an upgrade into an outage. The big ones are predictable: an extension with no build on the target version, a removed feature or changed default in the new release, and missing planner statistics after pg_upgrade. The pre-check table and the explicit post-upgrade ANALYZE step target exactly these, so the surprises surface during rehearsal rather than at 2 a.m. in the maintenance window.
Finally, the prompt insists on a rollback with a clearly named point of no return, which is the discipline most upgrade plans lack. Knowing that link mode forecloses in-place revert — so a verified backup is the only way back — changes how carefully the cutover is staged. Paired with a full timed rehearsal on a prod-sized copy and a human approving the cutover, it keeps an irreversible operation under deliberate control.
Related prompts
-
Postgres Zero-Downtime Schema Migration Planner Prompt
Turn a risky schema change into a lock-aware, multi-step migration plan that avoids long ACCESS EXCLUSIVE locks — with the exact statements, lock_timeout guards, and a back-out path for each phase.
-
Postgres md5-to-SCRAM Password Migration Prompt
Migrate a Postgres instance from legacy md5 password auth to scram-sha-256 without locking out clients — sequencing password_encryption, per-user re-hashing, driver compatibility, and pg_hba.conf so no role is stranded.
-
Postgres pg_dump / pg_restore & Bulk Load Tuning Prompt
Speed up a slow logical dump/restore or large data load by tuning pg_dump/pg_restore parallelism and the session-level settings (maintenance_work_mem, WAL, indexes, constraints) without compromising durability of the live system.
-
Postgres Logical Replication and CDC Setup Prompt
Design a complete logical replication / Change Data Capture pipeline — publications, subscriptions, replication slots, initial sync strategy, conflict handling, and slot-bloat monitoring — for streaming Postgres changes to a downstream system.
More Postgres prompts & error guides
Browse every Postgres prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.