PostgreSQL major versions are released every year, with each release delivering better performance and new features. With such rapid innovation, it is inevitable that there will be a need to upgrade from one version to another. Upgrade procedures are usually very complex and require thorough planning.
With the 2.4.0 release of Percona Operator for PostgreSQL, users can now upgrade to the new major version automatically. The feature is currently in technical preview.
To demonstrate it I will deploy the Operator and a cluster with PostgreSQL version 15. The goal would be to upgrade to PostgreSQL version 16.
Deploy the Operator:
|
1 |
kubectl apply -f deploy/bundle.yaml --server-side |
We use version 16 by default in our Custom Resources. To set the version, I set the following lines in the cr.yaml:
|
1 |
image: percona/percona-postgresql-operator:2.4.0-ppg15-postgres<br> postgresVersion: 15 |
Please note that right now, the major version upgrade only works for the images without the minor version tag. It will not work for images like percona/percona-postgresql-operator:2.4.0-ppg15.7-postgres.
Deploy the cluster:
|
1 |
kubectl apply -f deploy/cr.yaml |
In 2.4.0, we introduced the new Custom Resource PerconaPGUpgrade. It has a simple structure:
|
1 |
apiVersion: pgv2.percona.com/v2<br>kind: PerconaPGUpgrade<br>metadata:<br> name: cluster1-15-to-16<br>spec:<br> postgresClusterName: cluster1<br> image: percona/percona-postgresql-operator:2.4.0-upgrade<br> fromPostgresVersion: 15<br> toPostgresVersion: 16 |
Before running the upgrade, test the procedure on the non-production environment and take the full backup.
Apply the upgrade resource:
|
1 |
kubectl apply -f deploy/upgrade.yaml |
Below we explain what happens under the hood when you create the PerconaPGUpgrade resource.
Once PerconaPGUpgrade resource is created, the Operator does the following:
|
1 |
image: percona/percona-postgresql-operator:2.4.0-upgrade |
This is a special image that holds multiple PostgreSQL versions in it. You can find its Dockerfile here.
The Pods mount the data volumes (Persistent Volume Claims) of the instances and executes pg_upgrade. It copies the data without the need to perform dump/restore procedures and does its best to make sure the old and new clusters are binary-compatible. As the data is copied, make sure you have enough disk space.
You can track the upgrade status by checking the logs of the upgrade Pods. A Pod will be created for every instance.
|
1 |
kubectl logs cluster1-15-to-16-pgdata-qzzxh |
Once the data is copied, the cluster automatically starts up.
As mentioned above, the data is copied during the upgrade process, but it is also retained. Meaning that the data from the starting major version is kept on the disk. You can remove it at your discretion by executing into containers and running the following commands (example for PostgreSQL 15):
|
1 |
rm -rf /pgdata/pg15<br>rm -rf /pgdata/pg15_wal |
You can also delete the PerconaPGUpgrade resource; this will clean up the jobs and Pods created during the upgrade:
|
1 |
kubectl delete perconapgupgrade cluster1-15-to-16 |
If the upgrade fails for some reason, the cluster will stay in paused mode. You can unpause it manually, and it will start with the old version.
To debug the issue:
If you use any custom extensions, you need to make sure that you have them rebuilt for the new major version before the upgrade; otherwise, they will not work.
When the upgrade finishes the Operator automatically takes the full backup. Previous backups can be used to restore only to the older version. It is very important to ensure that you have a backup for the new version after the upgrade.
The introduction of the PerconaPGUpgrade resource in Percona Operator for PostgreSQL 2.4.0 simplifies the traditionally complex process of PostgreSQL major version upgrades. While still in technical preview, this feature promises to streamline the upgrade process for users, saving time and effort while reducing potential risks. Remember, as with any upgrade, testing in a non-production environment and creating full backups are essential precautions. We encourage you to try out this new functionality and share your feedback with the Percona community.