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

db upgrage: upgrade postgres 15 to postgres 16 #1415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vh05
Copy link
Contributor

@vh05 vh05 commented Aug 19, 2024

The Postgres upgrade from 15 to 16 or any later versions can be done by adding the env variable named POSTGRES_UPGRADE = copy in the pg db pod.

More about upgrade process is here: https://www.postgresql.org/docs/current/pgupgrade.html

In our case, we achieve the upgrade by setting this env var in noobaa-db-pg STS.

Once after upgrade is done, we have to remove the POSTGRES_UPGRADE env from the STS. Otherwise pg db pod fails to come up because the db pod check PG directory version against upgrade image version and exits if there is no upgrade required and POSTGRES_UPGRADE is still provided.

To remove this env, we store the upgrade status in noobaa-core CR after the PG upgrade and refer the same status during db reconcile. If the upgrade is already done, we remove this env from desired sts status.

This will help to upgrade the db smoothly

@dannyzaken
Copy link
Contributor

@vh05, can you please improve the PR description? What are the changes, technical details on the env used, etc.

@vh05
Copy link
Contributor Author

vh05 commented Oct 7, 2024

@vh05, can you please improve the PR description? What are the changes, technical details on the env used, etc.

sure

Comment on lines 292 to 294
if r.isPostgresDBUpgradeReqd() {
r.NooBaa.Status.BeforeUpgradeDbImage = r.NooBaa.Spec.DBImage
r.NooBaa.Spec.DBImage = &options.DBImage
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this belongs here. GetDesiredDBImage should be a general utility function, not a Reconciler method that modifies the object. It should also remain in system.go
Also, since this is the user input, you should generally not modify the values provided in the spec, such as r.NooBaa.Spec.DBImage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@@ -26,6 +26,8 @@ spec:
- name: db
image: NOOBAA_DB_IMAGE
env:
- name: POSTGRESQL_UPGRADE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only relevant for upgrades. when hardcoded here it will set the env for every new deployment as well.
The POSTGRES_UPGRADE env should be set only when necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is not needed anymore. The reconcile will detect upgrade status and flag will be set on the fly in memory

Copy link
Contributor

@dannyzaken dannyzaken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that instead of deciding on upgrade and applying changes inside SetDesiredNooBaaDB it will be more manageable, easy to follow, and less error-prone if you implement an UpgradeDB function that will be performed before the DB reconciliation. This method will ensure that everything is upgraded correctly, and will only return nil if the reconciliation is ready to proceed.

@vh05
Copy link
Contributor Author

vh05 commented Nov 12, 2024

I think that instead of deciding on upgrade and applying changes inside SetDesiredNooBaaDB it will be more manageable, easy to follow, and less error-prone if you implement an UpgradeDB function that will be performed before the DB reconciliation. This method will ensure that everything is upgraded correctly, and will only return nil if the reconciliation is ready to proceed.

Sure Danny. Let me check and do the changes

The Postgres upgrade from 15 to 16 or any later versions can be done by adding the env variable named POSTGRES_UPGRADE = copy in the pg db pod.

More about upgrade process is here: https://www.postgresql.org/docs/current/pgupgrade.html

In our case, we achieve the upgrade by setting this env var in noobaa-db-pg STS.

Once after upgrade is done, we have to remove the POSTGRES_UPGRADE env from the STS. Otherwise pg db pod fails to come up because the db pod check PG directory version against upgrade image version and exits if there is no upgrade required and POSTGRES_UPGRADE is still provided.

To remove this env, we store the upgrade status in noobaa-core CR after the PG upgrade and refer the same status during db reconcile. If the upgrade is already done, we remove this env from desired sts status.

This will help to upgrade the db smoothly

Signed-off-by: Vinayak Hariharmath <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants