Switch over a PostgreSQL cluster
You can initiate a switchover for a PostgreSQL Replication Cluster by executing the kbcli or kubectl command. Then KubeBlocks modifies the instance roles.
Before you start
Make sure the cluster is running normally.
Check whether the following role probe parameters exist to verify whether the role probe is enabled.
kubectl get cd postgresql -o yaml
>
probes:
roleProbe:
failureThreshold: 2
periodSeconds: 1
timeoutSeconds: 1
Initiate the switchover
You can switch over a secondary of a PostgreSQL Replication Cluster to the primary role, and the former primary instance to a secondary.
Switchover with no primary instance specified
kbcli cluster promote pg-cluster
Switchover with a specified new primary instance
kbcli cluster promote pg-cluster --instance='pg-cluster-postgresql-2'
If there are multiple components, you can use
--components
to specify a component.kbcli cluster promote pg-cluster --instance='pg-cluster-postgresql-2' --components='postgresql'
Verify the switchover
Check the instance status to verify whether the switchover is performed successfully.
kbcli cluster list-instances
Handle an exception
If an error occurs, refer to Handle an exception to troubleshoot the operation.