Resizing a PVC for Postgres on OpenShift by using volume expansion

Resize a Persistent Volume Claim (PVC) for Postgres that supports volume expansion.

Before you begin

This task only applies to the PVC used by Postgres. To determine whether your storage class supports volume expansion, see Recovering on OpenShift and Cloud Pak for Integration when disks are filled by the management database.

About this task

You can expand a PVC if your storage provisioner supports volume expansion.

Procedure

  1. Determine the primary Postgres pod.
    oc get pods --selector role=master | grep -v bootstrapselector=role=master
  2. Gracefully shutdown Postgres pods.
    1. Exec into the Postgres primary pod.
      oc exec -it <postgres-pod> -- bash
    2. Pause Patroni process. Note: you can skip this step if using the one replica profile.
      patronictl pause
    3. Stop the Postgres process gracefully.
      pg_ctl stop -D /pgdata/<cluster-name>

      For example:

      • cluster-name is usually the name of the cluster. If primary pod name is m1-1b12bf81-postgres-58dfcc5f97-fsvvt, cluster-name is m1-1b12bf81-postgres.
      • There will be a folder named cluster-name located under /pgdata/.
      • In this example, the command is:
        pg_ctl stop -D /pgdata/m1-1b12bf81-postgres
  3. Determine the PVC linked to the primary Postgres pod, and obtain the claimName of the PVC.
    oc get pod <postgres-pod> -o json | jq '.spec.volumes[] | select ( has ("persistentVolumeClaim"))'
  4. Scale down the Postgres deployment.
    oc get deploy | grep postgres | grep -v bouncer | grep -v bootstrap | grep -v backrest | grep -v operator

    If you are using n3 profile then you find 3 deployments. Scale them down:

    oc scale deploy <deployment-name> --replicas=0
  5. Edit the PVC you want to increase.
    oc edit pvc <claimName>
  6. Update spec.resources.requests.storage field value with new size. For example:
    spec:
      resources:
        requests:
          storage: 20Gi
    
  7. Scale up the Postgres deployment.
    oc get deploy | grep postgres | grep -v bouncer | grep -v bootstrap | grep -v backrest | grep -v operator

    If you are using the n3 profile then you find 3 deployments. Scale them up:

    oc scale deploy <deployment-name> --replicas=1
  8. If you are using the n3 profile, resume the Patroni process. If using the n1 profile, skip this step.
    1. Identify the Postgres pods.
      oc get pods --selector role
    2. Exec into any Postgres pod.
      oc exec -it <postgres-pod> -- bash
    3. Resume Patroni.
      patronictl resume