Skip to content

Declarative support for PostgreSQL major in-place upgrades #4682

Description

@gbartolini

Currently, Major upgrades of PostgreSQL can be done in an imperative way, by relying on the native logical replication capabilities and the cnpg plugin. See: https://www.gabrielebartolini.it/articles/2024/03/cloudnativepg-recipe-5-how-to-migrate-your-postgresql-database-in-kubernetes-with-~0-downtime-from-anywhere/

However, we should provide a way to support major upgrades just by changing the major field like in the following example:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-example
spec:
  instances: 3
  imageCatalogRef:
    apiGroup: postgresql.cnpg.io
    kind: ImageCatalog
    name: postgresql
    major: 16
  storage:
    size: 1Gi

To:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-example
spec:
  instances: 3
  imageCatalogRef:
    apiGroup: postgresql.cnpg.io
    kind: ImageCatalog
    name: postgresql
    major: 17
  storage:
    size: 1Gi

Alternative approaches are valid too, for example through CRDs that evoke imperative names (like upgrades) and that are useful too as they prepare the underlying PVCs for the new major.

Activity

  1. converted this from a draft issue on May 25, 2024
  2. added this to the 1.26.0 milestone on May 25, 2024
  3. moved this to Todo in Roadmapon Aug 13, 2024
  4. maxpain commented on Oct 7, 2024

    @maxpain
    Contributor

    Any updates on this?
    I can't believe that CNPG doesn't have major pg upgrades.

  5. bo0tzz commented on Oct 7, 2024

    @bo0tzz

    It's on the roadmap for 1.26.0 Roadmap (view) - as is also noted by the events listed above your comment ;)

  6. changed the title [-]Declarative support for PostgreSQL major online upgrades[/-] [+]Declarative support for PostgreSQL major in-place upgrades[/+] on Dec 6, 2024
  7. added
    enhancement 🪄
    on Dec 6, 2024
  8. gbartolini commented on Jan 8, 2025

    @gbartolini
    ContributorAuthor

    Version 1.25 introduced support for logical subscriptions, which simplifies the process of performing major upgrades using logical replication. Additionally, we've added the ability to perform parallel dump and restore, providing more flexibility for handling large-scale database operations. These features already cover many everyday use cases—logical online upgrades were, in fact, our preferred approach for Postgres upgrades during our time at 2ndQuadrant.

    I've been reflecting on this feature and considering how the direction we're taking with operand container images and extensions might influence its evolution. Specifically, we're working towards separating PostgreSQL operand images from extensions starting with PostgreSQL 18, with a proposed patch by EDB for the extension_control_path in PostgreSQL (see RFC: Extension Packaging Lookup. It is hard to say without a prototype, but I remain concerned about the potential for extension upgrades to lead to unpredictable or unrecoverable scenarios.

    However, given the strong demand for this feature, one approach for an initial implementation could be an offline update. If the update fails, the system would revert to the previous PostgreSQL version, resulting in an inconsistent state and requiring manual intervention to change the cluster definition. If successful, the process would promote the primary, destroy the standbys, and recreate them in sequence. Thoughts?

    Given our current commitments, I believe we can start working on this feature for version 1.26. However, due to the uncertainties mentioned earlier, there is a possibility that its delivery might be delayed.

  9. pschichtel commented on Jan 8, 2025

    @pschichtel

    one approach for an initial implementation could be an offline update. If the update fails, the system would revert to the previous PostgreSQL version, resulting in an inconsistent state and requiring manual intervention to change the cluster definition.

    The main point of concern is extensions, right? How is the risk of failure/inconsistency different when performing offline updates?

  10. gbartolini commented on Jan 9, 2025

    @gbartolini
    ContributorAuthor

    one approach for an initial implementation could be an offline update. If the update fails, the system would revert to the previous PostgreSQL version, resulting in an inconsistent state and requiring manual intervention to change the cluster definition.

    The main point of concern is extensions, right? How is the risk of failure/inconsistency different when performing offline updates?

    You work on a new cluster. You have time to prepare it in advance and test it, especially with applications. That's always been the main advantage of migrations to a different cluster, at least in my experience. You will have time to test upgrades to a different extension version as well.

  11. pschichtel commented on Jan 9, 2025

    @pschichtel

    Ah ok that's what you mean, makes sense. The declarative in-place upgrade approach wouldn't prevent people from using the imperative approach to have more safety if preferred, right? Even clusters that don't use extensions could hit a bug in a newer PG version and (subtly) break, so cluster upgrades would need to go through the usual QA processes anyway

  12. mnencia commented on Jan 25, 2025

    @mnencia
    Member

    I’ve submitted a possible implementation for declarative support for PostgreSQL major in-place upgrades in #6664. I would greatly appreciate it if you could review and test my approach and provide feedback or suggestions for improvement.

  13. egkristi commented on Feb 13, 2025

    @egkristi

    Will in-place major upgrades be included in version 1.26, scheduled for February 20th?

    We are currently evaluating CNPG, and this feature is critical for our decision. With over a thousand databases to manage, performing major upgrades imperatively is far too time-consuming. Declarative support for in-place upgrades would be a game-changer for us.

    We’d greatly appreciate any updates on whether this will make it into the next release.

  14. gbartolini commented on Mar 10, 2025

    @gbartolini
    ContributorAuthor

    This feature will be in 1.26.0.

  15. moved this from Todo to In Progress in Roadmapon Mar 10, 2025
  16. moved this from In Progress to Done in Roadmapon Mar 28, 2025
  17. added a commit that references this issue on Mar 28, 2025
    7a0963d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement 🪄

    Projects

    • Status
      Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions