Resizing a PersistentVolumeClaim for Postgres by volume expansion

Resize a PersistentVolumeClaim (PVC) for Postgres that supports volume expansion, on native Kubernetes.

Before you begin

Determine whether your storage class supports volume expansion. See Recovering when disks are filled by the management database.

About this task

You can expand a PVC if your storage provisioner supports volume expansion. This procedure is for use on native Kubernetes.

Note: This procedure is for use only with Postgres.

Procedure

  1. Determine the primary Postgres pod.
    kubectl get pods --selector role=master | grep -v bootstrapselector=role=master
  2. Gracefully shutdown Postgres pods.
    1. Exec into the Postgres primary pod.
      kubectl 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.
    kubectl get pod <postgres-pod> -o json | jq '.spec.volumes[] | select ( has ("persistentVolumeClaim"))'
  4. Scale down the Postgres deployment.
    kubectl 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:

    kubectl scale deploy <deployment-name> --replicas=0
  5. Edit the PVC you want to increase.
    kubectl 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.
    kubectl 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:

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