Skip to content

Maintenance windows #14

Open
Open

Description

@gbartolini

An initial implementation of maintenance windows is to introduce their specification on a weekly basis. In the future we might provide more control, including specification of an actual day.

Maintenance windows are enabled only for the “unsupervised” primary update strategy, with “restart” method option. When a maintenance window is defined in a cluster, an update of the image is “postponed” to the first available maintenance window, which will trigger a rollout update.

A maintenance window has a minimal length of "w" hours (initially 6), in which activities cannot start any later than "w - s" hours, where "s" is expressed in hours (by default 3). So, for example, with w=6h and s=3, activities can only start in the first 3 hours of the maintenance window.

Maintenance windows can be specified as an array:

maintenanceWindows:
  - dow: 0, 6
    start_at: 02:00
    end_at: 08:00

Or:

maintenanceWindows:
  - dow: 0
    start_at: 02:00
    end_at: 08:00
  - dow: 6
    start_at: 03:00
    end_at: 09:30

Activity

  1. gbartolini commented on Feb 5, 2024

    @gbartolini
    ContributorAuthor

    This should be depending on #12

  2. added this to the 1.25.0 milestone on May 25, 2024
  3. modified the milestones: 1.25.0, 1.26.0 on Aug 13, 2024
  4. moved this to Todo in Roadmapon Aug 13, 2024
  5. modified the milestones: 1.26.0, 1.27.0 on Dec 6, 2024
  6. github-actions commented on Feb 5, 2025

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  7. github-actions commented on Feb 20, 2025

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

  8. moved this from Todo to Done in Roadmapon Feb 20, 2025
  9. removed this from the 1.27.0 milestone on Mar 21, 2025
  10. alexklibisz commented on Jun 16, 2025

    @alexklibisz
    Contributor

    My team and I would find this quite useful. It is pretty disruptive that upgrading the operator or upgrading an image in the cluster image catalog leads to a rolling restart of all cloudnative-pg clusters managed by the operator. Not impossible to handle, but we'd really rather avoid a restart-the-world scenario if possible. It would be nice to define a maintenance window such that these rolling restarts can only happen during specific times. Then we can default randomize these times across cloudnative-pg clusters, or let individual database owners specify particular maintenance windows.

  11. LaurentP-Pro commented on Nov 15, 2025

    @LaurentP-Pro

    Hello,

    We would also benefit from such a feature.

    We envision a large fleet of DB clusters in dedicated namespaces for each application and segregated by environment layer DEV / TEST / QA / PROD .
    I considered heavily the pros and cons of the ClusterImageCatalog and ImageCatalog approaches: while I'm all for simplicity, we cannot afford to affect all DB clusters at once for all apps when we update the ClusterImageCatalog, even with distinct prod and non-prod k8s clusters. Blast radius is too wide for our risk appetite.
    Therefore we define ImageCatalog resources in each application namespace, and we (the DB infra team) update its contents through automation (gitops). As of now, the clusters are immediately updated. That's about enforcement of patching controls as part of the platform contract we define with our customers (the app teams).

    Like @alexklibisz , we can handle this scenario by controlling in our automation the timing of the ImageCatalog in each namespace. But I feel it would be much nicer to have everything defined within the cluster manifest, or through another CRD similar to ScheduledBackups for example.

    And it would provide a consistent experience for the app teams: everything is defined through CNPG.

    @gbartolini : would you agree to reopen this issue ? Or shall I create a new feature request and reference this one ?

  12. moved this from Done to Todo in Roadmapon Dec 12, 2025
  13. added this to the Later milestone on Dec 12, 2025
  14. gaurangkudale commented on Dec 27, 2025

    @gaurangkudale
    Contributor

    @gbartolini, This makes sense especially with the introduction of ImageCatalog / ClusterImageCatalog, where new PostgreSQL images can become available at any time.
    For an initial implementation, it seems reasonable to:

    • Define maintenance windows at the Cluster CRD level, since they describe when a specific cluster is allowed to restart, not which images exist.
    • Apply maintenance windows only when primaryUpdateStrategy is unsupervised and the update method is restart.
    • When a new image is detected outside a maintenance window, postpone the rollout and trigger it during the first available maintenance window.
    • Keep supervised strategy behavior unchanged.

    This would provide predictable, enterprise-friendly upgrade timing while keeping the initial scope small and aligned with existing controller logic.

    Example Cluster CRD

    apiVersion: postgresql.cnpg.io/v1
    kind: Cluster
    metadata:
      name: cluster-example
    spec:
      instances: 3
    
      primaryUpdateStrategy: unsupervised # Default
    
      maintenanceWindows:
        - dow: 0, 6            # Sunday, Saturday
          start_at: "02:00"
          end_at: "06:00"
    
      imageCatalogRef:
        apiGroup: postgresql.cnpg.io
        kind: ImageCatalog
        name: postgresql
        major: 17
    
      storage:
        size: 1Gi
    

    High-Level Design

    1. The operator detects a new PostgreSQL image via ImageCatalog

    2. If inside maintenance windw:

      • operator will process with the selected PrimayUpdateMethod (i.e restart)
      • detect a new postgressql image via ImageCatalog
      • at first maintenance window rollout restart is triggered
      • postgres pods are update safely
    3. If outside any maintenance window:

      • The upgrade is marked as pending
      • No restart or rollout occurs
    4. At the first available maintenance window:

      • A rollout restart is triggered
      • PostgreSQL pods are updated safely
    5. After completion:

      • Pending state is cleared
  15. thomasboussekey commented on Apr 13, 2026

    @thomasboussekey
    Contributor

    Hello,

    Interesting feature!

    My 2 pence thought on this would be to change maintenance definition from multiple entries to a cron-defined timestamp:

    apiVersion: postgresql.cnpg.io/v1
    kind: Cluster
    metadata:
      name: cluster-example
    spec:
      instances: 3
    
      primaryUpdateStrategy: unsupervised # Default
    
      maintenanceWindows:
        - start_timestamp: "0 2 * * 0,6"            # Sunday, Saturday
          duration: "04:00"
    
      imageCatalogRef:
        apiGroup: postgresql.cnpg.io
        kind: ImageCatalog
        name: postgresql
        major: 17
    
      storage:
        size: 1Gi
  16. bo0tzz commented on Jun 30, 2026

    @bo0tzz

    Besides (only) time-based, I think it would be awesome to be able to gate a maintenanceWindow on other factors too - perhaps even an arbitrary CEL expression against other cluster resources. What I'm envisioning is for example to prevent any rollouts while a workload is busy running migrations.

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

    Type

    No type

    Projects

    • Status
      Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions