Upgrading PostgreSQL on Debian and Ubuntu with pg_upgradecluster

A planning guide for teams moving PostgreSQL clusters to a new major version with the postgresql-common tools. It covers method choice, preparation, the upgrade sequence, OS upgrade risks, rollback and what drives effort.

On this page

How to upgrade PostgreSQL on Debian and Ubuntu with pg_upgradecluster

If your self-managed PostgreSQL cluster runs on Debian or Ubuntu and must move to a supported major version, the first decision is the method, and it shapes everything after it. PostgreSQL 14 reaches end of life on November 12, 2026, so the planning window is shorter than it looks. On Debian and Ubuntu, the postgresql-common package provides pg_upgradecluster, which upgrades an existing cluster to a new major version. The supported target depends on where you start, and the versions you can move to are 15 through 18, as listed in the PostgreSQL versioning policy. The primary reference for flags and behavior is the Debian manpage for pg_upgradecluster, which you should read against the exact postgresql-common version installed on your hosts.

The choice is between a dump-based upgrade, which is the default, and --method=upgrade, which runs pg_upgrade underneath. The upgrade method is faster, but it needs more care, especially when the operating system is also changing. The manpage also covers the link and clone variants of the pg_upgrade method, which trade disk use and rollback options differently. Confirm which variants your installed version supports before you rehearse, because option names and defaults can differ between postgresql-common releases. Record the decision with its reason: dump-based upgrades take longer but leave the old cluster simpler to restore, while the pg_upgrade variants depend on binaries and data directories staying consistent on the same host.

Before running anything in production, confirm three things on a copy of the cluster: that the target major version packages are installed alongside the old ones, that every extension your cluster loads has a build for the new version, and that the expected downtime fits your change window. Ask your team to write down the rollback path for each method, including who makes the call to return to the old cluster. Running the old and new clusters side by side is an option the tool supports, but it also means two sets of ports, configuration files and backups to manage until cutover is finished and verified.

What changes between major versions and what it means for the upgrade

This table compares the release changes that matter for a pg_upgradecluster run on Debian or Ubuntu, with the impact on the run and the action to take before cutover. Read each row as a question to answer for your own cluster, starting with the version you are moving to. The main takeaway is that the storage format is only changed by major upgrades, so the planning work sits with the major step.

ChangeImpact on a pg_upgradecluster runAction before cutover
Minor releases never change the storage formatMinor updates only replace executables and restart, so they do not need a dump or conversion step. A major upgrade is the only point where the data directory is rewritten or copied to a new version.Apply the latest minor release on the old version first, then plan the major step separately. Read the release notes for any post-update steps.
PostgreSQL 18 pg_upgrade retains planner statisticsStatistics carried across the upgrade can reduce the period of poor query plans after cutover, so the first queries may behave closer to the old system than a dump-and-restore would.Confirm the method you choose supports this behavior in your target version. Still run ANALYZE on the new cluster if your checks show plan changes.
PostgreSQL 18 pg_upgrade adds parallel jobsParallel jobs can shorten the copy or check step on large clusters, which changes the time the cluster is unavailable during a --method=upgrade run.Measure the run on a rehearsal copy of production data and set the job count to what the host can sustain with its I/O and CPU.
PostgreSQL 18 pg_upgrade adds a --swap optionThe swap option changes how the new data directory is placed, so the rollback path depends on whether the old directory is kept intact.Confirm the exact behavior in the pg_upgrade documentation for your version and write the rollback steps before the cutover window.
PostgreSQL 18 deprecates MD5 password authentication in favor of SCRAMRoles with MD5 hashes and pg_hba.conf entries using md5 may fail or log warnings after the move, which can block application logins.Inventory roles and client authentication methods before cutover, reset passwords under SCRAM where needed, and test each application connection.
Major upgrades require a new cluster with a new data directoryA pg_upgradecluster run creates or converts a cluster on the new version, so the old and new clusters both exist during the change window.Check free disk space for the chosen method, keep the old cluster until the new one passes verification, and record the retention period.
Extensions must match the new major versionShared objects built for the old version will not load into the new cluster, which can stop the cluster from starting or stop an extension from working.Install matching extension packages for the target version and test the extension update script on a copy before cutover.

How the pg_upgradecluster methods fit together

The decision path starts at the existing cluster and first asks how much downtime the change can tolerate. It then asks whether the old cluster must stay runnable for rollback, and whether the operating system is changing at the same time. Each route ends in a method: a dump and restore, the --method=upgrade path, or one of its link or clone variants. Confirm the flags and their behavior against the Debian manpage for the installed postgresql-common version before choosing.

Decision path from the current cluster to each pg_upgradecluster method.

Choosing dump or --method=upgrade for each cluster

For a small, non-critical cluster with a maintenance window long enough to cover the work, the dump method is usually the simpler choice. The old cluster is exported logically and loaded into the new major version, so the process does not carry the old data files forward. The outage grows with data volume, index rebuilds and restore time, so this tab fits clusters whose restore time, measured on a rehearsal, fits inside the agreed window.

  • Downtime: writes stop for the dump and restore, so the window scales with data size. Measure it on a copy of production data.
  • Rollback: the original cluster normally stays in place until applications are pointed at the new one, so returning means redirecting clients. Confirm whether the old cluster is kept or removed by default.
  • OS upgrade: a logical dump does not carry the old on-disk files into the new system, so it is less tied to the operating system change. Locale and collation settings still need checking after the restore.
  • Configuration: confirm how the command handles configuration files and cluster options that differ between versions.

Check the default method and the options that keep the old cluster in the Debian pg_upgradecluster manpage before scripting the upgrade.

Preparing the host and the data before pg_upgradecluster runs

Most failed Debian and Ubuntu major upgrades are lost before the upgrade command runs. These five checks cover the backup, extensions, authentication, rehearsal and operating system record that every cluster should have in hand before the cutover window opens.

Verified backup on separate hardware

Take a fresh base backup of the old cluster and prove it restores on a different machine before anything else changes. The restore test is the evidence, not the backup job's success status. Record the restore time, the row counts on the largest tables, and the WAL archive range the restore needed. The database administrator owns this check, and the backup log, restore transcript and retention settings are the evidence to keep for the change record.

Continuous archiving docs

Extension inventory and target builds

List every extension in each database with its installed version, then confirm that a build for the target major version exists for your distribution's packages. Extensions that ship as compiled shared objects are the usual blocker, because pg_upgradecluster will not install them for you. The platform engineer owns the inventory, and the output of the extension query per database, plus the package versions confirmed for the target release, goes into the change record.

Authentication review and SCRAM migration

Review pg_hba.conf line by line and note every method in use, especially md5 entries and any password entries that send cleartext. Check which roles still store MD5 password hashes and plan the reset to SCRAM before the upgrade, so client drivers are confirmed to support SCRAM-SHA-256. The database security owner signs off on this review. Keep the annotated pg_hba.conf, the role list with hash types, and the driver versions in use.

Rehearsal on a copy of production data

Restore a recent copy of production to a staging host with the same OS, package set and configuration, then run the full pg_upgradecluster sequence there. Time each step and record every warning, including locale or collation messages and extension errors. Application teams should run their test suites against the upgraded copy. The database administrator owns the rehearsal, and the timed run log, warning list and application test results form the go or no-go evidence.

OS release and planned OS upgrade record

Record the current Debian or Ubuntu release, the PostgreSQL packages installed, and whether the operating system upgrade is planned before, during or after the PostgreSQL move. Operating system upgrades can change the C library and locale behavior that PostgreSQL indexes depend on, so the order of the two changes matters. The systems owner owns this record. Keep the /etc/os-release output, the package list and the written upgrade order approved by the change board.

Running the pg_upgradecluster sequence with checks and rollback points

This sequence moves a Debian or Ubuntu PostgreSQL cluster to a new major version with a checked rollback point after each change. It produces a tested backup, a rehearsed command log, a verified new cluster and an old cluster kept intact for the rollback window.

  1. Confirm the source cluster state

    The database administrator lists clusters with pg_lsclusters and records the version, data directory, port, status and any standbys that follow this primary. They also save the installed extensions, custom settings from postgresql.conf, the entries in pg_hba.conf and the current replication lag. The cluster should start cleanly with no pending maintenance work. The step is done when this inventory is saved, so later checks have a baseline to compare against.

  2. Take and verify a restorable backup

    The platform engineer takes a full backup using the method the recovery plan already relies on and stores it outside the host being upgraded. They verify it by restoring to a separate scratch server, then comparing row counts and running a set of application queries against the restored copy. This backup is the first rollback point. Every later step can be undone by restoring it, so the step is done only when the restore has been tested successfully.

  3. Install target packages beside the old version

    The platform engineer installs the target major version packages from the distribution or the PostgreSQL apt repository, first confirming which version the package index offers. The existing cluster keeps running on its current binaries, so no data changes at this point. They check with apt policy or dpkg that the new server binaries, the matching extension packages and the postgresql-common tools are present. The step is done when the new binaries are installed and the old cluster still reports healthy. Removing the new packages reverses this step.

  4. Rehearse the upgrade on a restored copy

    The team runs the chosen pg_upgradecluster method against the restored copy from the backup step, never against production. They use the dump method or --method=upgrade, with any variant option the manpage requires, and capture the full log, exit status and elapsed time. Reviewers look for warnings about removed settings, extensions that fail to load and collation issues. The rehearsal is done when the upgrade completes cleanly more than once from the same backup and the exact commands are written into the runbook.

  5. Run the production upgrade

    The team schedules a maintenance window, stops application writes and runs pg_upgradecluster on production with the exact command from the rehearsal. Before starting, they confirm in the Debian manpage whether the chosen variant leaves the old data directory usable. With the link variant, the old and new clusters share data files, so once the new cluster accepts writes, restarting the old cluster is no longer a safe rollback and recovery means restoring the backup. The step is done when pg_lsclusters shows the new cluster online.

  6. Check configuration and extensions on the new cluster

    The platform engineer compares postgresql.conf and pg_hba.conf on the new cluster with the inventory from the first step and reviews any setting the new version renamed or removed. They load each extension, run ALTER EXTENSION UPDATE where needed and confirm package versions match the server. If the dump method was used, they run ANALYZE on each database, since planner statistics are not carried over by that path. The step is done when psql reports the expected version, every extension loads and the check log is saved.

  7. Run application tests against the new cluster

    The team points a staging copy of the application, or a test instance on a non-public port, at the new cluster and runs the functional, integration and batch tests they already own. They include driver version checks and authentication tests, especially where pg_hba.conf or password methods changed. Failing queries are recorded from the server log. The step is done when the suite passes or every failure has an owner and a decision. Test data written here stays on the new cluster, so the team schedules its cleanup before cutover.

  8. Cut over and hold the old cluster

    During the agreed window, the team switches application connection strings, DNS entries or the PgBouncer target to the new cluster, then watches errors, slow queries and connection counts. The old cluster stays defined with its data intact for the rollback window set by the change process, and this step does not drop it. Writes accepted by the new cluster are lost if the team falls back, unless they are replayed, so the cutover time and last old-cluster write are recorded. The old cluster is removed with pg_dropcluster only after the window closes, the backup is confirmed and the owners sign off.

Running clusters side by side and the care an OS upgrade needs

Keeping the old and new clusters side by side is the main safety margin in a pg_upgradecluster run. When the original cluster is left in place, you can start the new major version against a copy, run your application test suite and reporting queries against it, and still have a known-good cluster to fall back to if something fails. The Debian tooling is built around this idea: pg_upgradecluster creates the new cluster under the same name on a different major version, and the old cluster is kept until you remove it with pg_dropcluster. Confirm in the Debian manpage exactly what each method leaves behind on disk and in the cluster list, because that determines how far back a rollback can go once the old data directory is reused or removed.

The risk grows when the operating system is upgraded in the same window. A distribution upgrade can change the glibc version, locale data and the shared libraries your PostgreSQL binaries link against, and the old and new clusters may then depend on different system components. With the default dump-based path, the new cluster is built fresh, so OS changes mostly affect the restore. With --method=upgrade, which the Debian manpage describes as faster but in need of care during an operating system upgrade, the new binaries run against the existing data files, so a library or collation change can surface as a startup failure or as index corruption that appears only later. Treat that variant as the one that needs the most rehearsal before any combined OS and database change.

Where possible, sequence the operating system upgrade and the PostgreSQL major upgrade as separate changes, each with its own rollback point. Finish and verify the OS upgrade on the current PostgreSQL major version first, then run the database upgrade on the stable platform. Before either change, rehearse the full sequence on a copy of production hardware or a restored backup, and check the collation and index behavior the rehearsal produces. For collation-related risks during OS upgrades, read the sibling guidance on operating system upgrades and PostgreSQL collation changes, which covers the glibc locale change and reindexing. Record the exact package versions before and after each step so that a rollback decision is based on evidence rather than memory.

What makes a pg_upgradecluster upgrade take longer

This table lists the factors that change how much work a pg_upgradecluster upgrade involves on Debian or Ubuntu. Read each row as a question to answer about your own estate before asking for a quote, since the same tool can be a short job on one server and a multi-stage project on another.

DriverEffect on effortWhat to check
Number and size of clustersEach cluster on a host needs its own upgrade run, verification and rollback path, and larger data directories lengthen dump or copy steps.Count clusters per host with pg_lsclusters, and record data directory sizes and free disk space on the same volume.
Extensions needing matching buildsEach extension must have a build for the target major version installed before the upgrade, and a missing package can stop the cluster from starting.List installed extensions in every database and confirm packages exist for the target version in your Debian or Ubuntu repositories.
Customized configurationNon-default postgresql.conf settings, custom include files and tuned memory or WAL parameters must be reviewed and carried into the new cluster.Diff the old and new configuration files and note settings that the new major version renamed, removed or changed defaults for.
Authentication configurationCustom pg_hba.conf rules, LDAP or Kerberos setup and password hashing choices need checking, and MD5 passwords must be migrated to SCRAM where used.Review pg_hba.conf entries and confirm which roles still store MD5 hashes before cutover.
OS upgrade in scopeUpgrading the operating system in the same change adds package, library and locale work, and the upgrade method chosen must fit the OS path.Confirm whether the OS version changes, which PostgreSQL packages the target release ships, and how locale and collation changes will be handled.
Rehearsal depthEach rehearsal on a copy of production data adds test, timing and fix cycles, and skipping rehearsal moves the cost into the production window.Ask whether the plan includes a restored copy of production data, application test runs and timed runs of the actual upgrade steps.
Rollback window the business requiresA longer window to return to the old cluster means keeping the old data directory intact, managing replication or write freezes, and planning how writes made after cutover are handled.Define how long the old cluster must stay available and who approves a rollback decision, and confirm whether applications can tolerate a reverse move.
Side-by-side runningRunning old and new clusters together during testing needs spare ports, memory, disk and monitoring, and can complicate backups and access.Check that backup jobs, monitoring and connection targets are clearly assigned to one cluster at a time.

Questions teams ask before upgrading PostgreSQL on Debian or Ubuntu

What does a PostgreSQL major upgrade on Debian or Ubuntu cost?

The cost is mostly labor, and the size of that labor depends on the environment rather than on the tool itself. pg_upgradecluster is included in the postgresql-common packages at no license cost, since PostgreSQL is released under the PostgreSQL License. The one-time costs are planning, rehearsal on a copy of production, the cutover window, and verification. Recurring costs appear only if you buy ongoing support, upgrades or testing as a retainer, or if you carry the upgrade work into each future major release. Ask any partner for a written quote that lists each phase separately, names who performs it, and states which items are one-time and which recur.

How long does a PostgreSQL upgrade take and what drives that time?

Duration depends on the upgrade method, the data volume, the number of clusters, and how many extensions and applications must be checked. The dump and restore route scales with database size, while the --method=upgrade route runs pg_upgrade and is faster, but it still needs rehearsal and careful handling during an operating system upgrade. Other drivers include the number of replicas to rebuild, how many applications connect to each cluster, and whether maintenance windows are short. Time spent on testing usually outweighs the time spent on the upgrade command itself. Ask for a schedule that shows rehearsal, cutover and rollback steps as separate line items.

What must our team provide before an upgrade starts?

Before work starts, your team needs to provide the following:

  • Shell and sudo access to the database hosts, plus access to the backup system and any configuration management in use
  • Agreed maintenance windows, with a named approver who can call a rollback
  • Application owners who can confirm which services connect, which drivers they use, and what a successful test looks like
  • Test data or a recent copy of production that can be restored into a non-production environment for rehearsal
  • A current, tested backup and a written record of the current PostgreSQL version, installed extensions and cluster layout

Without these inputs, rehearsal results will not match production behavior.

Can an in-house team run pg_upgradecluster alone?

Yes, a team with Linux and PostgreSQL administration skills can run pg_upgradecluster without a partner, and the Debian manual documents the options. The harder part is the surrounding work: checking extensions for the new version, confirming how the OS upgrade interacts with the old and new clusters, verifying application behavior, and writing a rollback plan. If your team has run few upgrades, or if the database supports systems with strict audit or availability expectations, a partner can review the plan and rehearse it alongside your staff. Confirm your team's experience with the --method=upgrade path before deciding.

When is it worth bringing in an implementation partner?

A partner is worth engaging when the upgrade carries more risk than your team can absorb in one window. Common triggers include a PostgreSQL version nearing end of support, a combined OS and database upgrade, several clusters with replicas, regulated data that needs documented controls, or no recent experience with a major upgrade. DeployOpen plans, implements, documents and supports self-hosted open-source platforms in your own infrastructure, so an engagement can cover planning, rehearsal and cutover support in your environment. Most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.

What happens if a PostgreSQL upgrade fails partway through?

The outcome depends on the method chosen and on whether the rollback path was written and rehearsed beforehand. With pg_upgrade, the old cluster may remain available for rollback if the plan keeps it intact, but only if no one starts the new cluster against the same data in a way that makes returning impossible. Dump and restore leaves the original cluster untouched until cutover, which simplifies rollback. In every case, a verified backup is the final safety net. Ask any provider to document the exact rollback steps, the decision point after which rollback is no longer simple, and who has authority to make that call during the window.

How DeployOpen scopes and delivers a PostgreSQL upgrade

DeployOpen plans and runs Debian and Ubuntu PostgreSQL upgrades inside infrastructure you control, starting from a written scope that names each cluster, its version and the upgrade method. The work covers the OS and PostgreSQL change together, so the method choice, rehearsal and rollback path are settled before any production cluster is touched.

How we scope

  • Inventory every cluster with its current PostgreSQL version, OS release, extensions and the postgresql-common version in use.
  • Agree in writing whether the upgrade uses the dump path or --method=upgrade, and whether the OS upgrade runs in the same window.
  • Define which clusters run side by side, which stay on the old version for rollback, and who approves the cutover.

How we build

  • Rehearse pg_upgradecluster on a copy of production data in a staging environment that matches your server build.
  • Test extension compatibility, authentication settings and connection pooler configuration against the new cluster before cutover.
  • Run the upgrade, check the results and record the steps, timings and any manual fixes in the runbook.

How we hand over

  • Deliver the written runbook, rehearsal results, rollback steps and the post-upgrade checklist for your operations team.
  • Document the final cluster layout, configuration files, backup jobs and the removal plan for old clusters once they are no longer needed.
  • Walk your administrators through the procedure so your team can repeat it for later minor and major releases.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer if you want DeployOpen to handle future releases.
  • Ask for a quote that separates rehearsal, cutover and post-upgrade support so each cost component is visible.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.