Skip to main content
Version: release-0.8

Restart PostgreSQL cluster

You can restart all pods of the cluster. When an exception occurs in a database, you can try to restart it.

note

Restarting a PostgreSQL cluster triggers a concurrent restart and the leader may change after the cluster restarts.

Steps

  1. Restart a cluster.

    You can use kbcli or create an OpsRequest to restart a cluster.

    Option 1. (Recommended) Use kbcli

    Configure the values of components and ttlSecondsAfterSucceed and run the command below to restart a specified cluster.

    kbcli cluster restart NAME --components="postgresql" \
    --ttlSecondsAfterSucceed=30
    • components describes the component name that needs to be restarted.
    • ttlSecondsAfterSucceed describes the time to live of an OpsRequest job after the restarting succeeds.

    Option 2. Create an OpsRequest

    Run the command below to apply the restarting to a cluster.

    kubectl apply -f - <<EOF
    apiVersion: apps.kubeblocks.io/v1alpha1
    kind: OpsRequest
    metadata:
    name: ops-restart
    spec:
    clusterRef: pg-cluster
    type: Restart
    restart:
    - componentName: postgresql
    EOF
  2. Validate the restarting.

    Run the command below to check the cluster status to check the restarting status.

    kbcli cluster list <name>

    Example

    kbcli cluster list pg-cluster
    >
    NAME NAMESPACE CLUSTER-DEFINITION VERSION TERMINATION-POLICY STATUS CREATED-TIME
    pg-cluster default postgresql-cluster postgresql-14.7.0 Delete Running Mar 03,2023 18:28 UTC+0800
    • STATUS=Restarting: it means the cluster restart is in progress.
    • STATUS=Running: it means the cluster has been restarted.