Deleting a Postgres Instance from Kubernetes

This section describes how to delete Postgres pods and other resources that are created when you deploy a Postgres instance to Kubernetes. When deleting the resources, everything related to that instance is deleted, including the persistent volume claims (PVCs) and the access secrets. Any application bound to the deleted instance will have to rebind with new credentials.

Warning Do not delete the Postgres operator when there are existing Postgres instances. If the Postgres operator is deleted, you will get an error if you try to reinstall it. See Cannot Reinstall Operator after Deleting for a workaround to this problem.

Deleting Postgres Pods and Resources

Follow these steps to delete a Postgres instance from Kubernetes.

  1. Change to the Tanzu SQL with Postgres workspace directory with the Kubernetes manifest you used to deploy the Postgres instance.

    $ cd ./postgres-v<postgres-version>+<vmware-version>
  2. Execute the kubectl delete command, specifying the manifest you used to deploy the instance. For example:

    $ kubectl delete -f ./pg-instance-example.yaml --wait=false "my-postgres" deleted

    Note: The optional wait=false flag returns immediately without waiting for the deletion to complete.

    kubectl stops the Postgres instance and deletes the Kubernetes resources for the deployment.

  3. If for any reason stopping the Postgres instance fails, use kubectl to display the postgres-operator log.

    $ kubectl logs -l app=postgres-operator

    The Postgres operator should remain for future deployments:

    $ kubectl get all
    NAME                                     READY   STATUS    RESTARTS   AGE
    pod/postgres-operator-546ffd888b-dc6zk   1/1     Running   0          26h
    NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
    service/kubernetes   ClusterIP    <none>        443/TCP   18d
    NAME                                READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/postgres-operator   1/1     1            1           26h
    NAME                                           DESIRED   CURRENT   READY   AGE
    replicaset.apps/postgres-operator-546ffd888b   1         1         1       26h

Deleting the Postgres Operator

If you want to remove the Postgres operator, follow the instructions in Uninstalling Tanzu SQL with Postgres for Kubernetes.