Major PostgreSQL upgrades in a Patroni cluster

A planned major PostgreSQL upgrade in a Patroni cluster is a controlled sequence: pause failover, upgrade the primary, rebuild or upgrade replicas, restore DCS state and keep a rollback path open.

On this page

Major PostgreSQL upgrades in a Patroni cluster: why the path matters

A team running a Patroni-managed PostgreSQL cluster on a major version that is close to the end of its support window needs a planned path, not an ad hoc upgrade. PostgreSQL 14 is supported until November 12, 2026, so a cluster still on 14 has a fixed deadline. The supported path is to move to a version that still receives fixes for years, and the current PostgreSQL 18 line is the reference point for that choice. Confirm the exact target with the PostgreSQL versioning policy before the plan is written, because the support windows for 15, 16 and 17 end at different dates and the target version affects extension compatibility and the work ahead.

The key distinction is storage format. Minor releases never change the internal storage format, so they only replace executables and restart the server. Major upgrades do change how data is laid out on disk, which means the data must be converted, dumped and restored, or replicated into a new cluster. That is why a Patroni cluster cannot be upgraded the way it receives a minor patch. Each member of the cluster holds data in the old format, and the replicas cannot simply follow a new primary binary. The method you choose, whether pg_upgrade or logical replication, decides how much data movement happens and how much downtime the cutover causes, so the choice belongs in the plan before any change is made.

Patroni will try to heal the cluster whenever it sees a failed or stopped primary, and that behavior is the main operational risk during the work. Before the first step, the team must decide how automatic failover is suspended for the duration of the upgrade, using the pause mode described in the Patroni documentation, and confirm who is responsible for resuming it. Keep the cluster state in the distributed configuration store under review at each stage, and agree in advance which failure during the window triggers a manual decision and which triggers a rollback. A failover that happens in the middle of a major upgrade is the outcome the plan is designed to prevent.

What changes between PostgreSQL versions and what it means for the cluster

This table maps each release change relevant to a major upgrade to its effect on a Patroni-managed cluster and marks whether it requires action or only review. Read the action column first, then confirm each review item against the release notes for your exact source and target versions before scheduling the cutover.

ChangeWhat it means for the clusterAction or review
PostgreSQL 14 end of life on November 12, 2026Clusters on 14 stop receiving fixes after this date, so the upgrade window must close before it or the risk must be documented.Action: set the target version and schedule
PostgreSQL 18 supported until November 14, 2030Target 18 gives the longest supported window of the currently supported releases, so plan extension and client testing against it.Action: confirm target version
pg_upgrade keeps planner statistics in PostgreSQL 18Fewer post-upgrade ANALYZE runs may be needed, so the cutover runbook can shorten, but confirm the statistics step in your rehearsal.Review
pg_upgrade --swap option in PostgreSQL 18Swap mode changes how the old data directory is retained for rollback, so the Patroni data directory layout and rollback steps must be written around it.Action: test in a rehearsal
MD5 password deprecation in favor of SCRAMRole passwords, pg_hba.conf methods and replica or client authentication must use SCRAM before the upgrade is verified, or connections fail after cutover.Action: audit roles and pg_hba.conf
Asynchronous I/O in PostgreSQL 18Changes I/O behavior on the primary and replicas, so compare performance before and after and keep the rollback plan ready.Review
OAuth 2.0 authentication methodOnly relevant if your organization adopts OAuth for database login, so it does not change the upgrade itself.Review
Logical replication across major versionsAllows a cutover with only several seconds of downtime, but it requires a separate cluster and replication setup, which Patroni does not manage for you during the switch.Review: choose method first
Minor release binary replacementMinor updates need only a binary swap and restart, so keep the target minor release current on the new major version.Action: confirm latest minor release

What to prepare before touching the cluster

Four things need to be in place before anyone pauses failover or runs a utility against the primary. Each one is a way to get back to a known state if the upgrade goes wrong, and each one is easy to skip under schedule pressure.

Verified base backup and archived WAL

Point-in-time recovery depends on a base backup plus the archived WAL files that follow it. Before the window, take a fresh base backup, confirm the archive command is succeeding, and restore that backup to a scratch host to prove it is usable. A backup that has never been restored is a hope, not a rollback plan. Confirm which backup tool your team uses, since pg_basebackup can also take incremental backups that pg_combinebackup reconstructs at restore time, and test whichever path you rely on.

Continuous archiving docs

Extension inventory

List every installed extension, its installed version and the version available for the target major release. Extensions with compiled shared objects must be installed for the new version before pg_upgrade runs, and some extensions lag behind new major releases. Record the output of the extension list from each database, not only the default database, because extensions are created per database.

Authentication rules and roles

Copy pg_hba.conf, the password encryption setting and the role definitions from the current primary. Note every authentication method in use, including any LDAP, certificate or GSSAPI rules, and confirm that the new cluster will accept the same clients. Check whether any role still stores MD5 password hashes, because that affects the cutover plan and client compatibility.

Authentication methods docs

Custom configuration and Patroni settings

Capture postgresql.conf overrides, the Patroni configuration file and the cluster's dynamic configuration as stored in the DCS. Patroni may apply settings that are not visible in the local postgresql.conf, so export the effective configuration rather than relying on memory. Keep this capture with the rollback runbook so the team can restore the exact settings on either cluster.

Staging cluster with matching layout

Build a staging cluster that mirrors production: the same Patroni version, the same number of nodes, the same DCS type and layout, and the same PostgreSQL extensions. Rehearse the full sequence there, including pausing the cluster, running the upgrade on the primary and bringing replicas back. Record how long each step takes on staging so the production window is based on measured timings, and note any step that behaved differently from the runbook.

Patroni documentation

Choosing pg_upgrade or logical replication for a Patroni primary

The first question is how long the primary can be unavailable during the cutover. The PostgreSQL upgrading documentation states that logical replication works between different major versions and allows a major upgrade with only several seconds of downtime. pg_upgrade is an in-place operation whose outage is the time needed to stop the cluster, run the upgrade and restart, which depends on the data directory size, the mode chosen and how much work the upgrade must do. Measure both on a copy of your largest cluster before deciding, because your own numbers are what matter for a service-level commitment.

  • Cutover window: Logical replication shortens the outage to the switch of application connections, while pg_upgrade places the full stop-upgrade-start sequence inside the window.
  • Data volume: Large databases lengthen pg_upgrade's link or copy steps in different ways, so test with a representative data size.
  • Write load: Logical replication must keep up with write traffic before cutover, which a busy primary can make harder to achieve.
  • Application behavior: Confirm how clients reconnect after a failover or endpoint change, including any connection pooler in front of the cluster.
  • Business constraints: Record the agreed maintenance window and who can approve an overrun before the method is chosen.

Confirm the downtime your service owners will accept in writing, and rehearse the cutover against that number.

How to sequence the upgrade across the cluster

This sequence moves a Patroni-managed PostgreSQL cluster from the old major version to the new one with automatic failover paused for the whole window. Each irreversible step follows a checkpoint that confirms a rollback path still exists.

  1. Record a rollback baseline

    Before anything changes, take a fresh base backup and restore it to a separate host to confirm it works. Save the output of patronictl list and the cluster configuration, and export the Patroni keys held in your DCS (etcd, Consul, ZooKeeper or Kubernetes, depending on how you deployed it). The DBA owns this step. It is done when the restore test passes and the saved state is stored outside the cluster, so you can return to a known leader, member list and configuration if the upgrade stops.

  2. Pause Patroni automatic failover

    Run patronictl pause --wait to stop automatic failover for the maintenance window. Confirm with patronictl list that the cluster reports maintenance mode, then check that the current primary still accepts writes. While paused, Patroni will not promote a replica, so a failure during the window needs a person to act. Pausing is reversible: patronictl resume returns control to Patroni. The step is done when the pause flag is visible and the leader matches your baseline.

  3. Stop replicas before the primary

    Stop the PostgreSQL service on each replica host, using the same service manager Patroni runs under, so no standby keeps streaming while the primary is prepared. On the primary, query pg_stat_replication and confirm no standby clients remain connected. Stopped replicas keep their data directories, so this step can be undone by starting them again. Keep them stopped until the primary upgrade is complete. The step is done when every replica reports stopped and the primary lists no streaming clients.

  4. Run pg_upgrade check on the primary

    Install the new major version binaries alongside the old ones, then initialize a new data directory with settings that match the old cluster, including the data checksum setting. Run pg_upgrade --check with the old and new binary and data paths. Fix every reported incompatibility, including extension versions and removed settings, and rerun the check until it passes. Nothing on disk has changed yet, so this is the last point where you can stop without any rollback. The step is done when the check completes with no errors.

  5. Upgrade the primary with a rollback path

    Stop the primary's PostgreSQL service, then run pg_upgrade in the mode chosen for your downtime budget. Confirm the baseline backup from the first step is intact before you start, because in link mode the old cluster cannot be started again once the new one runs. Point Patroni at the new binaries and data directory through postgresql.bin_dir and postgresql.data_dir in its configuration, start the new primary, then run the analyze script that pg_upgrade generated. The step is done when the new primary accepts connections, reports the new major version and logs no errors.

  6. Rebuild or upgrade the replicas

    Rebuild each replica from the new primary, most simply with patronictl reinit for each member, which creates the replica from a base backup of the new primary. Physical streaming does not cross major versions, so a replica still running the old version cannot follow the new primary. Reinitializing replaces the replica's data directory, which is why the baseline from the first step matters. Watch each member with patronictl list until it reports streaming on the new version. The step is done when every member is running and none still holds an old-version data directory.

  7. Check and clean DCS state before resuming

    Inspect the DCS keys before Patroni takes control again. Confirm the leader key names the new primary, the config key holds the intended settings, and member entries exist only for hosts still in the cluster. Remove stale member entries for decommissioned hosts using Patroni tooling where possible, and avoid hand-editing the leader key. Record the cleaned state in your change log. The step is done when patronictl list matches the expected member set and the DCS holds no entry for a host that no longer belongs to the cluster.

  8. Resume Patroni and verify replication

    Run patronictl resume and confirm Patroni has returned to automatic management. Check patronictl list for one leader and replicas with low lag, and query pg_stat_replication on the primary to confirm each standby is streaming. Run a planned switchover only if your change window allows it, and record the result. Keep the rollback baseline until replication, application connections and monitoring have all been confirmed on the new version. The step is done when the cluster reports healthy members and the rollback plan is formally closed.

How the Patroni, DCS and PostgreSQL parts fit during the upgrade

The diagram starts with the operator pausing the cluster through the Patroni agents, which stops automatic failover while the DCS keeps the cluster state. The upgrade then moves through the primary (upgraded with pg_upgrade), the replicas (rebuilt or upgraded), and the backup store, which holds the restore point that the rollback path depends on. Check that the pause is set and that a verified backup exists before the primary is touched, and that the DCS state is consistent before the cluster is resumed.

Patroni pause, DCS state and the upgrade phases with the rollback path.

How DCS state and the rollback plan protect the cluster

Patroni keeps its view of the cluster in the distributed configuration store (DCS), so the keys there must describe the cluster you actually end up running before you resume automatic failover. After a major upgrade the primary is a new cluster with a new system identifier, and the leader and member keys, the cluster configuration and the failover state recorded for the old cluster no longer match it. Check the DCS contents against the new cluster before you run the resume step, and confirm that the leader key points at the upgraded primary and that every member key reports the new major version. If Patroni resumes while a replica is still on the old major version, the replica cannot replay the new primary's WAL, so it will fall behind, fail to rejoin, or be promoted into a state the rest of the cluster cannot follow. Keep replicas out of the rotation until each one has been rebuilt or upgraded and has reconnected cleanly.

Rollback is a decision you make before the cutover, not after it. The first option is restoring from the verified backup taken immediately before the upgrade, which returns you to the pre-upgrade data but discards every write committed to the new cluster since the cutover. The second option is keeping the old binaries and the old data directory intact for a window you define in advance, so you can start the previous major version and resume service. The pg_upgrade --link mode makes this option fragile, because linked files are shared between the old and new data directories, and starting the new cluster changes them, so the old cluster may not be recoverable. Confirm which pg_upgrade mode you chose before you rely on the second option. Neither option can undo writes once clients have committed to the new primary. Agree with the application owners on a point of no return, the time after which rollback means data loss and a reconciliation effort, and write that point into the runbook.

What makes a Patroni major upgrade take longer

How does the number of replicas change the length of a Patroni major upgrade?

Each additional replica adds work, because every one must be rebuilt or upgraded and brought back into sync before the cluster is healthy again. Replicas are usually handled one at a time so the cluster keeps redundancy, which means the total window grows with the count even when each rebuild is quick. Clusters with a single standby have less room for error, since losing the standby during the work leaves no fallback. Ask your team how many replicas must stay in service at each step and whether the rebuild method is a full base backup or an in-place upgrade on each node.

Does database size affect how long a pg_upgrade or replica rebuild takes?

Yes. The size of the data directory drives the time for file copying, base backups, and the statistics and verification steps that run after the upgrade. The pg_upgrade mode you choose changes how much data is physically copied, so link or clone modes shorten the work compared with a full copy, while a dump and restore is the slowest path for large databases. Replica rebuilds scale the same way, because each new standby must receive a full copy of the data before it can stream changes. Measure the actual data size and the throughput of your storage and network during a rehearsal rather than relying on a general estimate.

Why do extensions with matching builds extend the upgrade window?

Extensions must have shared libraries built for the new major version before pg_upgrade can load the old objects into the new cluster. If a build is missing, or the extension version pairing is not supported on the target release, the upgrade stops or the team must find a compatible version first. Each extension adds a compatibility check, a package installation on every node, and a test of its functions after the cutover. Extensions that are no longer maintained can turn a planned task into a dependency decision, so confirm the build and version for each one before the change window.

How do custom pg_hba.conf and TLS settings affect upgrade effort?

Custom authentication and TLS configuration adds checks that must pass on the new cluster before applications can connect. Settings such as certificate paths, file permissions, cipher choices, and authentication methods are often copied by hand, so mismatches appear only after cutover. Password hash changes, such as moving away from MD5, can also require role resets and driver checks for each client. Plan a review of pg_hba.conf, certificate files and the ssl settings on every node, and test a client connection with each authentication method in use.

How does PgBouncer configuration change the cutover work?

Connection poolers point applications at the primary through a fixed host, port or database entry, so they must be repointed or paused during the switch. The number of pool definitions, user mappings, and pool modes determines how many settings must be checked on the new primary. Pooler configuration that references old hostnames or certificates adds steps before the cutover can be called complete. Confirm the pooler configuration inventory, the pause and resume procedure, and how client connections are drained before the primary changes.

How does backup verification lengthen the upgrade plan?

A current, tested backup is a precondition for the rollback plan, and restoring it to a separate host takes time that must be scheduled before the upgrade. Teams that have never restored from their backup tooling often need extra time to prepare, which is why backup verification belongs in the rehearsal. Point-in-time recovery depends on archived WAL files being complete, so gaps found during verification may delay the change. Ask for proof that a restore completes and that the restored cluster starts on the target configuration.

How many environments should be rehearsed before the production upgrade?

Most teams rehearse on at least one non-production copy that matches production topology, configuration and extensions, and more environments add time but reduce surprises. Each environment you rehearse needs its own data copy, replicas, pooler setup and test run, so the effort scales with the number of environments and their fidelity. Staging copies that differ from production in extension versions or authentication settings tend to hide the problems that matter most. Decide early which environments will be used, what must match production exactly, and who signs off each rehearsal result.

What is the cost of a longer Patroni upgrade window?

The main cost is the staff time and change-window coverage needed for each step, plus the risk exposure while redundancy is reduced. Costs are one-time for the upgrade itself and the rehearsals, while ongoing costs come from keeping the rehearsal environments and backup tests current. Longer windows also raise the cost of a failed step, because rollback work and extra verification run in the same period. When requesting a quote, ask for the work broken down by replica count, data copy method, extension checks, pooler changes, backup restore tests and rehearsal environments.

How DeployOpen scopes and delivers a Patroni major upgrade

DeployOpen plans and delivers Patroni-managed PostgreSQL major upgrades inside infrastructure you control, starting with a written scope that names the cluster, the target version and the rollback position. The work is built as a rehearsed sequence with tested fallback steps, and the handover leaves your team with runbooks and evidence they can review.

How we scope

  • Inventory the cluster topology, Patroni configuration, DCS type and every node that participates in failover.
  • Agree the source and target PostgreSQL versions, the upgrade method and the downtime window in the written scope.
  • List extensions, client drivers and authentication methods that must be verified on the new cluster before cutover.

How we build

  • Rehearse the full sequence on a staging copy of the cluster, including pausing Patroni, running pg_upgrade and resuming.
  • Test the rollback path on the rehearsal copy so the fallback steps are proven before production work starts.
  • Confirm tested point-in-time recovery backups exist and can be restored before any change is made to the primary.

How we hand over

  • Deliver a runbook with pause, upgrade, replica rebuild, resume and rollback steps for your operators to follow.
  • Document the DCS state checks, replication health checks and post-upgrade verification queries used during cutover.
  • Record the rehearsal results and the production cutover log so your compliance and operations teams can review them.

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 for later minor releases and maintenance.
  • Confirm with us during scoping which post-upgrade monitoring and follow-up checks are included in your written scope.

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.