When updating PostgreSQL to a major version, it is necessary to update the version of the running pod to a later version of PostgreSQL. It is also necessary to recreate the storage to update the data stored in the PostgreSQL data files.
Updating a PostgreSQL container consists of five steps:
- Database backup.
- Installation of PostgreSQL 15 in a Kubernetes cluster.
- Recreation of storage.
- Starting PostgreSQL.
- Database recovery.
Step 1. Database backup
Before carrying out any actions related to the update, create a backup of the PostgreSQL data and configuration. Read more about how to do this in Backup and recover databases.
начало внимание
If there are third-party databases on the PostgreSQL server, backups of these databases should also be created.
конец внимание
Backup of the PostgreSQL database without using the elma365-backupper utility
kubectl port-forward -n <<namespace>> pods/postgres-0 5477:5432
pg_dump -h localhost -p 5477 -U postgres -W elma365 -Fc > path/to/elma365.bak |
Step 2. Installation of PostgreSQL 15 in a Kubernetes cluster
- Stop the container:
postgres
:
kubectl scale -n <<namespace>> statefulset -l app.kubernetes.io/instance=<<namespace>>,app.kubernetes.io/name=postgresql --replicas 0
- Save the
statefulsets
configuration of thepostgres
pod to the filepostgresql.yaml
:
kubectl get statefulsets -n <<namespace>> -lapp.kubernetes.io/instance=<<namespace>>,app.kubernetes.io/name=postgresql -o yaml > path/to/postgresql.yaml
- Open the
postgresql.yaml
file by using the command:
sudo nano path/to/postgresql.yaml
In this file, replace the version image
with version docker.io/bitnami/postgresql:15.4.0
.
- Apply the changes for pod
postgres
:
kubectl apply -f path/to/postgresql.yaml
Step 3. Recreation of storage
Delete storage postgresql
:
kubectl delete pvc -n <<namespace>> -l app.kubernetes.io/instance=<<namespace>>,app.kubernetes.io/name=postgresql --wait=false
Step 4. Starting PostgreSQL
Start the container postgres
:
kubectl scale -n <<namespace>> statefulset -l app.kubernetes.io/instance=<<namespace>>,app.kubernetes.io/name=postgresql --replicas 1
Step 5. Database recovery
Read more about how to do this in Backup and recover databases.
Recovery of the PostgreSQL database without using the elma365-backupper utility
kubectl port-forward -n <<namespace>> pods/postgres-0 5477:5432
pg_restore -h localhost -p 5477 -U postgres -W -Fc -d elma365 < elma365.bak |