Major version upgrade¶
Major version upgrade allows you to jump from one database major version to another (for example, upgrade from PostgreSQL 17.x to PostgreSQL 18.x).
This feature is generally available starting with the Operator version 2.9.0.
Considerations¶
- A major upgrade introduces a downtime because the whole cluster is shut down during the upgrade. This flow is planned to be improved in future releases.
- During the upgrade, the Operator duplicates the data on each PVC and doesn’t remove the old version data automatically. Make sure your PVC has enough free space to store data.
- If the target image ships a different
glibcbuild, the sorting rules of some locales can change. Before the upgrade, check whether the change affects the locales your databases use. See the glibc collation limitation. The upgrade runspg_upgrade --link, which keeps every index as it is. The examplePerconaPGUpgradeuses UBI 9 images. If your cluster runs on-ubi8or-ubi10images, use the upgrade and PostgreSQL images with the same suffix. Otherwise, the upgrade also changes the operating system.
Before you start¶
Check operating system and glibc¶
Check the operating system used by the PostgreSQL container:
kubectl exec -n <namespace> <postgres-pod> -c database -- \
cat /etc/os-release
Check the glibc package build. The output includes the release number after the version, so it shows a change that the version alone hides:
kubectl exec -n <namespace> <postgres-pod> -c database -- \
rpm -q glibc
Sample output
glibc-2.34-275.el9_8.x86_64
If the cluster with the target image doesn’t exist yet, start a temporary Pod from the image and run the same command:
kubectl run glibc-check -n <namespace> --rm -i --restart=Never \
--image=<postgres-image> --command -- \
rpm -q glibc
Run the commands for the current image and for the target image, then compare the full output. If the output is the same, the collation rules are the same. If any part differs, including the release number, assess whether the change affects the locales your databases use.
Also check that every locale your databases use exists in the target image:
kubectl run locale-check -n <namespace> --rm -i --restart=Never \
--image=<postgres-image> --command -- \
locale -a
A locale that is missing from the list can’t be used on that image.
Assess the collation risk¶
A glibc change usually updates the sorting rules of only a few locales. Your data is at risk only if your databases use one of those locales. Run this assessment before you change the image, so you know whether you need to plan downtime for a repair.
-
If the
glibcbuild is the same in the current and the target image, and the ICU libraries match, stop here. The collation rules don’t change. -
Connect to PostgreSQL and list the default locale and locale provider of each database:
SELECT datname, datlocprovider, datcollate, datcollversion FROM pg_database WHERE datallowconn;Sample output
datname | datlocprovider | datcollate | datcollversion -----------+----------------+-------------+---------------- postgres | c | en_US.UTF-8 | 2.34 template1 | c | en_US.UTF-8 | 2.34 cluster1 | c | en_US.UTF-8 | 2.34The
datlocprovidercolumn shows the locale provider:cis libc (glibc),iis ICU, andbis the PostgreSQL built-in provider, available starting with PostgreSQL 17. The built-in provider doesn’t depend onglibcor ICU.PostgreSQL 14 has only the libc provider and no
datlocprovidercolumn. On PostgreSQL 14, runSELECT datname, datcollate FROM pg_database WHERE datallowconn;instead. -
In every database, list the collations that columns, indexes, constraints, generated columns, views and partition keys use. Any of them can set a collation that differs from the database default:
SELECT c.collname AS collation, c.collprovider, c.collcollate AS locale, count(*) AS objects FROM pg_depend d JOIN pg_collation c ON d.refclassid = 'pg_collation'::regclass AND d.refobjid = c.oid WHERE c.collname NOT IN ('C', 'POSIX', 'default') GROUP BY 1, 2, 3 UNION ALL SELECT 'default', 'd', datcollate, NULL FROM pg_database WHERE datname = current_database() ORDER BY 1;Sample output
collation | collprovider | locale | objects ------------+--------------+-------------+--------- C.utf8 | c | C.utf8 | 1 default | d | en_US.UTF-8 | sv_SE.utf8 | c | sv_SE.utf8 | 2If every locale on the list is
CorPOSIX, or the database uses the built-in provider, this database isn’t affected. -
For each
glibclocale on your list, find out whether its sorting rules changed between the two images.The Operator creates clusters with the
en_US.UTF-8locale. In the PostgreSQL images of Operator 3.1.0,en_US.UTF-8sorts the same on the UBI 8, UBI 9 and UBI 10 tags. A cluster that uses onlyen_US.UTF-8doesn’t need a repair when it moves between these images.C.UTF-8is different: it sorts differently on UBI 8 than on UBI 9 and UBI 10. The difference affects only strings with unassigned Unicode code points, but PostgreSQL doesn’t warn about it.For other locales, and for images of later Operator releases, compare the sort order yourself.
-
Export the distinct values of the text columns that use the locale to one file on your workstation. Only values in indexes, partition keys and constraints can break, so export only those columns. In
psql, run:\copy (SELECT <column> FROM <table> UNION SELECT <column> FROM <other_table>) TO 'values.txt'List every such column with that locale in the query. Include values with accented letters, punctuation and non-Latin characters if your data has them.
-
Sort the same file in a temporary Pod of the current image and of the target image. The command prints a checksum of the sorted output, or a message if the image doesn’t have the locale:
kubectl run sort-check -n <namespace> --rm -i --restart=Never \ --image=<postgres-image> --command -- \ sh -c 'if LC_ALL=<locale> locale 2>&1 >/dev/null | grep -q .; then echo "Locale <locale> is missing in this image"; else LC_ALL=<locale> sort | md5sum; fi' \ < values.txt -
Compare the checksum lines of the two runs. Different checksums mean the rules changed for your data.
kubectlalso prints apod "sort-check" deletedline, which you can ignore.
Use one file for both images. Don’t export the data again from each server: a server can return rows in the order of its existing index, which is the old order. If the image doesn’t have the locale,
sortsilently uses byte order, so both checksums would match even if the rules changed. The command checks this for you.Matching checksums prove only that the rules didn’t change for the values in your file. For ICU collations, compare the ICU versions of both images.
-
-
Decide:
- No locale on your list changed: you don’t need to repair anything.
- A locale on your list changed, or you can’t confirm that it didn’t: plan a repair. Repair data after a collation change tells you whether you need the full procedure or a targeted repair, and how to rehearse it. Stop writes before you change the image: from the moment a Pod starts on the new image, the old indexes let duplicate keys in.
If you need a repair, stop application traffic before you start the upgrade. The Operator starts the cluster as soon as the upgrade finishes, so applications can connect before you repair the affected objects.
Update PMM¶
- Update PMM Server before upgrading PMM Client.
- PMM2 has reached its end-of-life stage and is no longer supported in the Operator. See PMM upgrade documentation for how to migrate from version 2 to version 3.
Upgrade steps¶
To start the upgrade, you need to create a special PerconaPGUpgrade resource. This resource refers to the special Operator upgrade image and contains the information about the existing and target major versions. Find the example PerconaPGUpgrade configuration file in deploy/upgrade.yaml:
apiVersion: pgv2.percona.com/v2
kind: PerconaPGUpgrade
metadata:
name: cluster1-17-to-18
spec:
postgresClusterName: cluster1
image: docker.io/percona/percona-distribution-postgresql-upgrade:19.0-18.7-17.12-16.16-15.20-3
fromPostgresVersion: 17
toPostgresVersion: 18
toPostgresImage: docker.io/percona/percona-distribution-postgresql:18.7.1-2
toPgBouncerImage: docker.io/percona/percona-pgbouncer:1.26.1-2
toPgBackRestImage: docker.io/percona/percona-pgbackrest:2.60.1-2
As you can see, the manifest includes image names for the database cluster components (PostgreSQL, pgBouncer, and pgBackRest). You can find them in the list of certified images for the current Operator release. For older versions, please refer to the old releases documentation archive .
Apply this manifest to start the upgrade:
kubectl apply -f deploy/upgrade.yaml -n <namespace>
During the upgrade flow, the Operator:
- Pauses the cluster, making it unavailable for the duration of the upgrade,
- Annotates the cluster with a special
pgv2.percona.com/allow-upgrade:<PerconaPGUpgrade.Name>annotation, - Creates jobs to migrate the data,
- Starts up the cluster after the upgrade finishes.
Post-upgrade steps¶
-
The
pgauditextension is not upgraded automatically. If you use this extension, you must drop and recreate it in each database where it is installed. Connect to PostgreSQL with the privileges of the superuser and run the following commands:DROP EXTENSION pgaudit; CREATE EXTENSION pgaudit;Repeat for every database where the
pgauditextension is installed. -
A successful major upgrade invalidates existing logical replicas. After the cluster is
ready, reseed each logical replica. -
If the collation risk assessment showed that a locale you use changed, or you couldn’t confirm that it didn’t, repair the affected objects before applications connect.
Repair collation-affected objects¶
If the collation risk assessment showed that a locale you use changed, or you couldn’t confirm that it didn’t, follow Repair data after a collation change as soon as the cluster is ready. Keep the applications stopped until the repair is done.
Cleanup¶
-
You can remove old version data at your discretion by executing into containers and running the following commands (example for PostgreSQL 17):
rm -rf /pgdata/pg17 rm -rf /pgdata/pg17_wal -
You can also delete the
PerconaPGUpgraderesource (this will clean up the jobs and Pods created during the upgrade):kubectl delete perconapgupgrade cluster1-17-to-18
Troubleshooting upgrade issues¶
If the upgrade fails for some reason, the cluster will stay in paused mode. Resume the cluster manually to check what went wrong with upgrade (it will start with the old version). You can check the PerconaPGUpgrade resource with kubectl get perconapgupgrade -o yaml command, and check the logs of the upgraded Pods to debug the issue.
Failed first restore after the upgrade¶
After a major upgrade, PostgreSQL starts a new WAL timeline. PostgreSQL treats the upgraded cluster as a new logical generation, so it increments the timeline ID and begins writing WAL from that new point.
In clusters with very low write traffic, the upgraded primary may generate very few WAL segments after the upgrade.
When you make a first restore after the upgrade, the restored replicas need to replay WAL from the primary to catch up. To do that, PostgreSQL uses the pg_rewind tool. pg_rewind searches a common WAL ancestor — a point in history where both the primary and the replica share the same WAL record. If there are few WAL records, there may not be a common WAL ancestor and the replica may fail to rejoin the primary. When this happens, you see the could not find common ancestor of the source and target cluster's timelines error in pg_rewind.
To address this issue, you must manually reinitialize the failed replica. Before doing so, check if this replica has any transactions that are not replicated anywhere else. Then remove its data directory and let the instance perform a full copy from the primary.
Alternatively, you can automate replica reinitialization with Patroni. Update the cluster configuration by setting the spec.patroni.removeDataDirectoryOnDivergedTimelines in the Custom Resource before the upgrade. When timeline divergence is detected, the Operator instructs Patroni
to automatically remove the replica’s data and resync it from the primary.
Warning
The removeDataDirectoryOnDivergedTimelines option can lead to data loss.
When the Operator resyncs the replica automatically, some transactions may
be lost. The risk is usually small but not zero. Use this option only if you
understand and accept this trade-off.
Created: March 30, 2026