Declarative hibernation v1

EDB Postgres for Kubernetes is designed to keep PostgreSQL clusters up, running and available anytime.

There are some kinds of workloads that require the database to be up only when the workload is active. Batch-driven solutions are one such case.

In batch-driven solutions, the database needs to be up only when the batch process is running.

The declarative hibernation feature enables saving CPU power by removing the database Pods, while keeping the database PVCs.


Declarative hibernation is different from the existing implementation of imperative hibernation via the cnp plugin. Imperative hibernation shuts down all Postgres instances in the High Availability cluster, and keeps a static copy of the PVCs of the primary that contain PGDATA and WALs. The plugin enables to exit the hibernation phase, by resuming the primary and then recreating all the replicas - if they exist.


To hibernate a cluster, set the annotation:

$ kubectl annotate cluster <cluster-name> --overwrite

A hibernated cluster won't have any running Pods, while the PVCs are retained so that the cluster can be rehydrated at a later time. Replica PVCs will be kept in addition to the primary's PVC.

The hibernation procedure will delete the primary Pod and then the replica Pods, avoiding switchover, to ensure the replicas are kept in sync.

The hibernation status can be monitored by looking for the condition:

$ kubectl get cluster <cluster-name> -o "jsonpath={.status.conditions[?(.type==\"\")]}" 

        "message":"Cluster has been hibernated",

The hibernation status can also be read with the status sub-command of the cnp plugin for kubectl:

$ kubectl cnp status <cluster-name>
Cluster Summary
Name:              cluster-example
Namespace:         default
PostgreSQL Image:
Primary instance:  cluster-example-2
Status:            Cluster in healthy state 
Instances:         3
Ready instances:   0

Status   Hibernated
Message  Cluster has been hibernated
Time     2023-03-05 16:43:35 +0000 UTC


To rehydrate a cluster, either set the annotation to off:

$ kubectl annotate cluster <cluster-name> --overwrite

Or, just unset it altogether:

$ kubectl annotate cluster <cluster-name>

The Pods will be recreated and the cluster will resume operation.