Switching the LEADER node¶
In some maintenance cases, it may be useful to switch the PostgreSQL cluster LEADER node in order to perform operations on it.
Before you can change the LEADER node, please identify the current LEADER node of the PostgreSQL cluster and then connect to it as root.
Once connected as root to the LEADER node, run a command similar to the following to trigger an immediate switchover:
| Value | Variable | Definition |
|---|---|---|
PSQL_NODE |
Name of the node that will become LEADER. |
1 | |
Failure
If the command fails, check that the settings for patronictl have been applied on each node: the Patroni port 8008 must be open in the local firewall, and patronictl must trust the certificate of the Patroni API (otherwise the command displays certificate verify failed).
Example
For the following PostgreSQL cluster:
1 2 3 4 5 6 7 | |
The goal is to make the PSQL_1 node the LEADER.
You therefore first connect as root to the PSQL_3 node, which is the current LEADER.
Once connected, the following command immediately switches the LEADER to the PSQL_1 node:
1 | |
The change of topology is then visible and can be checked:
1 2 3 4 5 6 7 | |