Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Postgres Upgrades #201

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion control-plane/roles/postgres-backup-restore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ This role uses variables from [control-plane-defaults](/control-plane). So, make
You can look up all the default values of this role [here](defaults/main/main.yaml).

| Name | Mandatory | Description |
| ------------------------------------------------------- | --------- | ------------------------------------------------------------------------ |
|---------------------------------------------------------|-----------|--------------------------------------------------------------------------|
| postgres_image_name | yes | Image version of the postgres |
| postgres_image_tag | yes | Image tag of the postgres |
| postgres_old_image_tag | | Image tag of the postgres database before the upgrade |
| postgres_registry_auth_enabled | | Enables registry authentication |
| postgres_registry_auth | | The dockerconfigjson content used for registry authentication |
| postgres_image_pull_policy | | Image pull policy (defaults to IfNotPresent) |
Expand Down Expand Up @@ -43,3 +44,32 @@ You can look up all the default values of this role [here](defaults/main/main.ya
| postgres_effective_cache_size | | Allows setting effective cache size |
| postgres_backup_restore_sidecar_object_prefix | | The prefix to store the object in the cloud provider bucket |
| postgres_backup_restore_sidecar_object_max_keep | | The number of objects to keep at the cloud provider bucket |

## Major upgrades

Postgres does require special treatment if a major version upgrade is planned. `pg_upgrade` needs to be called with the old and new binaries, also the old data directory and a already initialized data directory which was initialized with the new binary, e.g. `initdb <new directory>`.

To make this process as smooth as possible, backup-restore-sidecar will detect if the version of the database files and the version of the postgres binary. If the binary is newer than the database files it will start the upgrade process. Strict validation to ensure all prerequisites are met is done before actually starting the upgrade process.

To trigger such an update you simply raise the version of the postgres container and specify additionally the version of the previous postgres container.

Configuration before the upgrade:

```yaml
...
postgres_image_tag: 12-alpine
...
```

Configuration to trigger the upgrade:

```yaml
...
postgres_image_tag: 15-alpine
postgres_old_image_tag: 12-alpine
...

```

Deploy again With this new configuration and the upgrade process will start, after that the database will run with the new postgres version in place.
You can remove the `postgres_old_image_tag` if you want, but this is not strictly required.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spec:
- name: bin-provision
subPath: tini
mountPath: /usr/local/bin/tini
{% if postgres_old_image_tag %}
- name: bin-provision
mountPath: /usr/local/bin/pg-old
subPath: pg-old
{% endif %}
- name: backup-restore-sidecar
image: {{ postgres_image_name }}:{{ postgres_image_tag }}
imagePullPolicy: {{ postgres_image_pull_policy }}
Expand Down Expand Up @@ -145,6 +150,11 @@ spec:
- name: bin-provision
subPath: tini
mountPath: /usr/local/bin/tini
{% if postgres_old_image_tag %}
- name: bin-provision
mountPath: /usr/local/bin/pg-old
subPath: pg-old
{% endif %}
{% if postgres_backup_restore_sidecar_provider == "gcp" %}
- name: gcp-credentials
mountPath: /gcp/credentials
Expand All @@ -162,6 +172,19 @@ spec:
volumeMounts:
- name: bin-provision
mountPath: /bin-provision
{% if postgres_old_image_tag %}
- command:
- cp
- -a
- /usr/local/bin
- /bin-provision/pg-old
image: {{ postgres_image_name }}:{{ postgres_old_image_tag }}
imagePullPolicy: {{ postgres_image_pull_policy }}
name: postgres-old
volumeMounts:
- mountPath: /bin-provision
name: bin-provision
{% endif %}
volumes:
- name: {{ postgres_name }}
persistentVolumeClaim:
Expand Down