Configuring PostgreSQL instances

Use the Postgres Operator for Kubernetes to manage PostgreSQL cluster instances. To manage instances, edit the cluster custom resource (CR).

Note: Any changes that you make to the CR automatically trigger the operator to update the running PostgreSQL cluster.
Tip: In the following commands, my-postgres is an example cluster name. Replace my-postgres with your actual PostgreSQL cluster name.
Change the number of replicas
To scale PostgreSQL replicas, update the spec.instances value in the cluster CR.
For example, open the cluster CR for editing and modify the spec.instances field to increase the instances from 3 to 5:
oc edit clusters.pg.ibm.com my-postgres -n postgres-namespace
spec:
 instances: 5
After the update:
  • The operator creates additional PostgreSQL replica pods.
  • Any required services and persistent volume claims (PVCs) are automatically configured.
  • Scaling down removes pods but does not delete their PVCs by default unless configured.
Change resource settings
To increase CPU and memory allocated to PostgreSQL instances, update the resource requests and limits in the cluster CR.
For example, edit the cluster CR and update the spec.resources section with the required values:
oc edit clusters.pg.ibm.com my-postgres -n postgres-namespace
spec:
 resources:
   requests:
     memory: "4Gi"
     cpu: "2"
   limits:
     memory: "8Gi"
     cpu: "4"
After the update:
  • The operator restarts affected pods one at a time to reduce downtime.
  • Updated resources apply to all instances unless you override them for an instance.
Expand storage
The Postgres Operator supports storage expansion only. It does not support storage reduction. When you increase storage capacity, the operator updates the PVCs.
For example, edit the cluster CR and modify the storage capacity from 10Gi to 50Gi:
oc edit clusters.pg.ibm.com my-postgres -n postgres-namespace
spec:
 storage:
   size: 50Gi
Note:
  • You can increase storage only.
  • Expansion might require a pod restart, depending on the storage class.
  • Ensure that your storage class supports volume expansion.