This topic describes how to update CPU, memory, and storage configuration of an existing Postgres instance.

To update an existing Postgres instance for high availability or backup, see Configuring High Availability in VMware Postgres Operator, and Backing Up and Restoring VMware Postgres Operator.

Prerequisites

The steps in this topic require:

  • the kubectl command line tool to access the Kubernetes cluster.
  • appropriate access permissions to the Kubernetes cluster and namespace where the Postgres instances reside.
  • access permissions to the running Postgres instances to be updated.
  • access permissions to the Kubernetes storageclass.

Modifying Memory and CPU

You can update the memory and CPU requests and limits of a Postgres object by editing the instance manifest. Before changing any values, ensure that the Kubernetes cluster does not have any limiting resource quotas. For more details on the resource quotas refer to the Kubernetes Resource Quotas documentation.

  1. Edit the existing instance manifest or save it to a new file using:

    kubectl get postgres <POSTGRES-INSTANCE> -o yaml > postgres.yaml
    

    where POSTGRES-INSTANCE is the name of the Postgres object.

  2. Edit the file, and set new values in the resources field. For example, change the monitor CPU limits and requests:

    apiVersion: sql.tanzu.vmware.com/v1
    kind: Postgres
    metadata:
      name: postgres-sample
    spec:
      ... # Omitting unrelated fields in the manifest
    
      resources:
        data:
          limits:
            cpu: 2
            memory: 3G
          requests:
            cpu: 1
            memory: 2G
        monitor:
          limits:
            cpu: 500m
            memory: 800Mi
          requests:
            cpu: 500m
            memory: 800Mi
        metrics:
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 100m
            memory: 100Mi
    

    See the Kubernetes Resource Management documentation for more information.

    For the default values refer to the Resources Reference, and for minimum requirements review Minimum resource requirements.

  3. Execute the kubectl apply command, specifying the manifest file you edited. For example:

    kubectl apply -f ./postgres.yaml --wait=false
    
    postgres.sql.tanzu.vmware.com "postgres-sample" configured
    

    If the manifest file contains any incorrectly formatted values or unrecognized field names, an error message is displayed identifying the issue. Edit the manifest to correct the error, and re-run the command.

  4. Wait for the pods restart, and ensure they reach a Running state. If there aren't any nodes that can meet the resource requests, Kubernetes may not be able to schedule the pods on a node.

    You can inspect the pod configuration to verify the indiviual container resources. Note that the CPU and memory requests and limits will be split amongst some containers on a pod.

  5. (Optional) Observe the pod(s) resource usage.

    If you enabled the Metrics Server on the Kubernetes cluster, use kubectl top to show the resource usage:

    kubectl top pods -l postgres-instance=<POSTGRES-INSTANCE>
    

    where POSTGRES-INSTANCE is the name of the Postgres object.

    NAME                        CPU(cores)   MEMORY(bytes)
    postgres-sample-0           324m         68Mi
    postgres-sample-1           261m         120Mi
    postgres-sample-monitor-0   381m         68Mi
    

    Check the Kubernetes Resource Metrics documentation for more information.

Expanding Storage Volume Size

To expand a Postgres instance storage volume, verify that the storage volume is expandable, and then update the instance yaml file.

If the Kubernetes storage manager allocates space in fixed increments, the actual size of the expanded volumes may be greater than the storage value specified in the instance manifest.

Note: Kubernetes does not support shrinking a volume size.

Verify or enable volume expansion

To expand the PV volumes, review the storage class object, and check if the allowVolumeExpansion field is set to true. If the attribute does not exist, you may add it to the storage class, and then expand the storage volumes. The following steps describe this process.

  1. Show the current PVs:

    kubectl get pv
    
    NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                                       STORAGECLASS   REASON   AGE
    pvc-00d130f6-1fb6-49e0-b145-c58e152f76ab   5Gi        RWO            Delete           Bound    default/postgres-sample-pgdata-postgres-sample-0            standard                14s
    pvc-33371405-6853-49f7-b704-f49ae8771b5b   1Gi        RWO            Delete           Bound    default/postgres-sample-monitor-postgres-sample-monitor-0   standard                34s
    
  2. Check if the storage class (in this example standard) supports volume expansion:

    kubectl get storageclass standard
    
    NAME                 PROVISIONER                RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
    standard (default)   k8s.io/minikube-hostpath   Delete          Immediate           false                  20h
    

    In this case ALLOWVOLUMEEXPANSION is set to false.

  3. Check that you have permissions to modify the storage class:

    kubectl auth can-i update storageclass
    
    yes
    
  4. Amend the storage class configuration after saving it to a local yaml file:

    kubectl get storageclass standard -o yaml > storagesize.yaml
    
  5. Edit the saved file and change the allowVolumeExpansion attribute to true, or add the attribute if it is not already present.

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
       name: standard
    provisioner: kubernetes.io/aws-ebs # AWS specific
    reclaimPolicy: Retain
    allowVolumeExpansion: true
    mountOptions:
      - debug
    volumeBindingMode: Immediate
    

    For more information about expanding volumes, see the Kubernetes Allow Volume Expansion documentation.

  6. Apply the change.

    kubectl apply -f storagesize.yaml
    
  7. Verify the change.

    kubectl get storageclass standard --output=jsonpath='{.allowVolumeExpansion}'
    
    true
    

    See the Kubernetes Documentation for more information about storage classes and persistent volumes.

Increase volume size

  1. Edit the manifest file that was used to deploy the instance. Set the value for the storageSize and/or monitorStorageSize attribute to the desired size:

    apiVersion: sql.tanzu.vmware.com/v1
    kind: Postgres
    metadata:
      name: postgres-sample
    spec:
      storageSize: 2G
      monitorStorageSize: 3G
    
  2. Apply the edited manifest to the Postgres instance.

    kubectl apply -f postgres.yaml
    
    postgres.sql.tanzu.vmware.com/postgres-sample configured
    

    If the manifest file contains any incorrectly formatted values or unrecognized field names, an error message identifies the issue. Edit the manifest, correct the error, and re-run the command.

  3. Verify that the persistent volume size has increased:

    watch kubectl get pv
    
    NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                                       STORAGECLASS   REASON   AGE
    pvc-00d130f6-1fb6-49e0-b145-c58e152f76ab   2Gi        RWO            Delete           Bound    default/postgres-sample-pgdata-postgres-sample-0            standard                14s
    

Troubleshoot

If the storage class does not have the allowVolumeExpansion attribute set totrue, the persistent volumes will not be expanded. No message is immediately displayed, but errors are written to the Postgres operator logs. View the logs with commands like the following:

kubectl logs -l app=postgres-operator -n <NAMESPACE>

where NAMESPACE is the namespace where the Postgres operator is running.

INFO controllers.PersistentVolumeClaims Reconciler    Error updating PVC resources: persistentvolumeclaims "postgres-sample-pgbackrest-postgres-sample-0" is forbidden: only dynamically provisioned pvc can be resized and the storageclass that provisions the pvc must support resize
ERROR    controllers.PostgresInstance    found error reconciling backup persistent volume claim    {"error": "persistentvolumeclaim\"postgres-sample-pgbackrest-postgres-sample-0\" is forbidden: only dynamically provisioned pvc can be resized and the storage class that provisions the pvc must support resize"}

If the persistent volumes could not be resized, edit the StorageSize attribute in the manifest to match the actual size.

check-circle-line exclamation-circle-line close-line
Scroll to top icon