Repository navigation
feat: declarative offline in-place major upgrades of PostgreSQL - #6664
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
|
/test |
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/12967425266 |
|
Just to be sure I understand this correctly: This is an offline migration as in: The cluster gets taken down completely, the primary upgraded in-place, started up again and new replicas are cloned from that, right? |
Yes exactly. However, it will be speedy, as no data will be copied around. |
There was a problem hiding this comment.
Just a heads up that this will perform noticeably better on systems/containers with coreutils 9.x or higher when using xfs/btrfs/zfs/bcachefs, where cp reflinks by default instead of copying.
|
Hi @mnencia, this looks like a wonderful PR! Are you still working on it? Or is there another reason it is still in draft? |
|
just FYI, not in any way a request or anything: In my homelab I'm using zalando's operator, which is based around patroni and their spilo images. While there are a bunch of things I don't like about that operator, it's in-place major upgrades work quite well. I tested that on the weekend and it seems it keeps the replicas around while upgrading the master, so read queries could still be answered. Might be worth looking at what they are doing. |
There was a problem hiding this comment.
In this code, we’re creating the instance manager reconciler just to call functions that download the secrets and make sure the WAL volume is set up correctly. The problem is, the first function doesn’t return any error, so we’re not really sure if the secrets were downloaded or not.
A similar issue pops up with the "initdb" call and the one that creates the metrics server. The "initdb" call should be encapsulated, and the metrics server creation shouldn't even be here in the first place.
Before merging this, we need to clean up the implementation to make it more maintainable and avoid repeating code, kind of like what we did with the subreconciler in the operator. This will take some time, and if we go down that path, we might not have enough time to hit the 1.26 release as planned.
Important: we need E2e tests too, and we should be careful on this one.
I’d love to hear what the other maintainers think. What’s your opinion?
There was a problem hiding this comment.
I suggest proceeding incrementally to ensure both functionality and maintainability. We should first validate the feature mechanics in their current form to confirm they work as expected. At the same time, we should complete the implementation of the patch's E2E tests to demonstrate how the feature operates, providing a reliable safety net before making structural changes. Once this validation is complete and the E2E tests are in place, we can refactor the code to improve its structure and maintainability while preserving functionality.
For the 1.26.0 release, if we don’t have enough time to complete the full work before 1.26.0rc1, we should prioritize merging the patch with the E2E tests in place, leaving the refactor for later. This will allow users to try it out and provide feedback. Based on that input, we can complete the refactoring and issue a new RC release.
There was a problem hiding this comment.
I agree, but only partially. I won't call that refactor - there's no tests in place, I call it clean up.
It is not the first time we postponed the clean up phase, and the duplicated code is still there needing a clean up.
One example is that RefreshSecrets call, another one is the NewExporter call.
In this patch we add new duplication for the initdb command.
If this patch reaches a release we give value and help people immediately - and that's our goal - but we won't be able to continue helping later.
There was a problem hiding this comment.
For the 1.26.0 release, if we don’t have enough time to complete the full work before 1.26.0rc1, we should prioritize merging the patch with the E2E tests in place, leaving the refactor for later. This will allow users to try it out and provide feedback. Based on that input, we can complete the refactoring and issue a new RC release.
This confirms that there will definitely be an RC2. Is this what you mean, @mnencia? Help me understand. Thanks.
There was a problem hiding this comment.
For the 1.26.0 release, if we don’t have enough time to complete the full work before 1.26.0rc1, we should prioritize merging the patch with the E2E tests in place, leaving the refactor for later. This will allow users to try it out and provide feedback. Based on that input, we can complete the refactoring and issue a new RC release.
This confirms that there will definitely be an RC2. Is this what you mean, @mnencia? Help me understand. Thanks.
Yes, in that scenario, an RC2 would be necessary. If we merge the patch with E2E tests in place but defer the refactor, we will need an additional RC release once the cleanup is complete to ensure a properly maintained and polished implementation.
|
/test tl=4 d=main |
Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Niccolò Fei <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
A job retry could fail because the wal directory created for the upgrade already exists. Clean it up before retrying. Signed-off-by: Francesco Canovai <[email protected]>
Some storage classes don't seem to follow expected directory permissions, so we explicitly set them before running pg_upgrade to avoid errors during initial checks. Signed-off-by: Francesco Canovai <[email protected]>
pg_upgrade until version 16 needs details about locales, or its incompatibility check will fail if there are differences. The failure happens on the default settings, given that the operator uses the C locale by default and pg_upgrade uses en_US.utf-8. Let's avoid adding support for upgrades to versions that are already old, and keep the patch simpler. Signed-off-by: Francesco Canovai <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Add e2e for major upgrades for postgresql and postgis images. Signed-off-by: Francesco Canovai <[email protected]>
Fix pg_upgrade failures on OpenShift where the user is some random high number. Signed-off-by: Francesco Canovai <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Inform the user about the need of an ANALYZE after the upgrade. Add a note about major upgrade e2e. Signed-off-by: Francesco Canovai <[email protected]>
Signed-off-by: Francesco Canovai <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
|
/test tl=4 d=main |
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/14117210423 |
This PR introduces the ability to upgrade PostgreSQL clusters to a higher major version, enabling a fully declarative approach for major version upgrades within CloudNativePG.
IMPORTANT: While the upgrade job area still requires refactoring, we’ve decided to merge this patch into the main branch and release version 1.26.0-rc1 to gather early community feedback at KubeCon Europe 2025 in London. The refactoring will likely require a second release candidate before the final 1.26.0 release.
With this update, users can specify a new image with a higher major version using any supported method. The operator tracks the previous image version in
.status.majorVersionUpgradeFromImage, which also serves as an indicator that a major version upgrade is in progress.The upgrade process starts by deleting all pods and jobs to ensure the data directory is inaccessible. A dedicated upgrade job is created for the primary instance, using an
initContainerto copy the old PostgreSQL installation and runningpg_upgrade --linkfor an efficient migration. Once the upgrade completes, all non-primary instances are removed, and new standbys are cloned to restore the desired number of instances.Closes #4682
Release Notes
Declarative Offline In-Place Major Upgrades of PostgreSQL: Introduced support for offline in-place major upgrades when a new operand container image with a higher PostgreSQL major version is applied to a cluster. All cluster pods are shut down during the upgrade to ensure data consistency. A new job is created to validate upgrade conditions, run
pg_upgrade, and set up new directories forPGDATA, WAL files, and tablespaces as needed. Once the upgrade is complete, replicas are re-created. Failed upgrades can be rolled back declaratively. (#6664)