Introduction
Configuration
PostgreSQL Connection Pool
High Availability
You can initiate a switchover for a PostgreSQL Replication Cluster by executing the kbcli or kubectl command. Then KubeBlocks modifies the instance roles.
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
You can switch over a secondary of a PostgreSQL Replication Cluster to the primary role, and the former primary instance to a secondary.
The value of instanceName
decides whether a new primary instance is specified for the switchover.
Switchover with no specified primary instance
kubectl apply -f -<<EOF
apiVersion: apps.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: mycluster-switchover
namespace: demo
spec:
clusterName: mycluster
type: Switchover
switchover:
- componentName: postgresql
instanceName: '*'
>>
Switchover with a specified new primary instance
kubectl apply -f -<<EOF
apiVersion: apps.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: mycluster-switchover
namespace: demo
spec:
clusterName: mycluster
type: Switchover
switchover:
- componentName: postgresql
instanceName: 'mycluster-postgresql-2'
>>
Switchover with no primary instance specified
kbcli cluster promote mycluster -n demo
Switchover with a specified new primary instance
kbcli cluster promote mycluster -n demo --instance='mycluster-postgresql-2'
If there are multiple components, you can use --components
to specify a component.
kbcli cluster promote mycluster -n demo --instance='mycluster-postgresql-2' --components='postgresql'
Check the instance status to verify whether the switchover is performed successfully.
kubectl get cluster mycluster -n demo
kubectl -n demo get po -L kubeblocks.io/role
kbcli cluster list-instances -n demo
If an error occurs, refer to Handle an exception to troubleshoot the operation.