For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

PostgreSQL major-version upgrade stalls

This document explains a known issue in the upstream Percona Operator for PostgreSQL that can make a major-version upgrade of a PostgreSQLInstance stall permanently, and how to recover from it. The issue starts when you change spec.image.tag to a higher PostgreSQL major version on the PostgreSQLInstance resource (see Upgrade the PostgreSQL major version), and the upgrade never finishes.

To avoid the issue, make sure the spec.instances[].replicas of the PostgreSQLInstance resource is 2 or more before you start an upgrade.

Upgrade stalls on a single-replica instance

A major-version upgrade of a PostgreSQLInstance with only 1 replica configured in spec.instances[].replicas can stall before the upgrade completes.

Symptoms

  • The underlying PerconaPGCluster shows spec.image and spec.postgresVersion already at the new version, but status.state stays at initializing and never reaches ready, even after several minutes.

  • The instance pod is not fully ready (for example 1/2 containers ready) and does not recover on its own.

  • The database container logs of that pod repeat an error similar to:

    text
  • The logs of the database operator Pod repeat a reconciler error similar to the one below. The Pod runs in the namespace set by spec.operatorNamespace of the PostgreSQLOperator and carries the app.kubernetes.io/name=pg-operator label, so you can read the logs with kubectl logs -n {OPERATOR-NAMESPACE} -l app.kubernetes.io/name=pg-operator:

    text

Cause

The upgrade Job that migrates the data directory to the new major version's on-disk format (pg_upgrade) completes successfully, and the operator writes the new image and version onto the live PerconaPGCluster as part of finalizing the upgrade. The instance's StatefulSet uses updateStrategy: OnDelete, so the operator is expected to delete the old pod itself as a later step of the same reconcile, letting it restart on the new image.

With only one replica, that step never runs. Before reaching it, the operator's reconciler tries to reconfigure Patroni on the currently running pod, which is still on the old PostgreSQL binary, while its data directory has already been converted to the new major's format by the upgrade Job. Patroni on that pod cannot start, so the reconfiguration step fails and the whole reconcile returns an error before it gets to the pod-recreation step. The reconciler keeps retrying the same failing step.

With 2 or more replicas, this does not happen, because the reconciler always finds a healthy pod to work with.

No data is lost while the cluster is stuck in this state, and the migrated data directory is intact. The Pod only needs to restart to mount it with the new binary.

Recovery

To resolve the issue of the stalled upgrade:

  1. Confirm that the instance StatefulSet's Pod template already references the new PostgreSQL image. The operator updates this before the upgrade stalls, so usually it is already correct:

    bash
  2. Delete the stuck instance pod. The StatefulSet uses updateStrategy: OnDelete, so the StatefulSet controller recreates the pod from the current pod template:

    bash

    Caution

    Delete the pod only after step 1 confirms the pod template already references the new PostgreSQL image. If it still references the old image, the recreated pod hits the same failure, and the instance stays unavailable.

  3. Wait for the recreated pod to become ready on the new image:

    bash

Once the pod is ready, PerconaPGCluster.status.state returns to ready and your data is available on the new PostgreSQL major version.