Administering PGD Proxy v5

Switching the write leader

Switching the write leader is a manual operation that you can perform to change the node that's the write leader. It can be useful when you want to perform maintenance on the current write leader node or when you want to change the write leader for any other reason. When changing write leader, there are two modes: strict and fast. In strict mode, the lag is checked before switching the write leader. It waits until the lag is less than route_writer_max_lag before starting the switchover. This is the default. In fast mode, the write leader is switched immediately. You can also set a timeout parameter to specify the time to wait for the switchover to complete.

Note

The switchover operation is not a guaranteed operation. If, due to a timeout or for other reasons, the switchover to the given target node fails, PGD may elect another node as write leader in its place. This other node can include the current write leader node. PGD always tries to elect a new write leader if the switchover operation fails.

Using SQL

You can perform a switchover operation that explicitly changes the node that's the write leader to another node.

Use the bdr.routing_leadership_transfer() function.

For example, to switch the write leader to node node1 in group group1, use the following SQL command:

SELECT bdr.routing_leadership_transfer('group1', 'node1','strict','10s');

This command switches the write leader using strict mode and waits for up to 10 seconds for the switchover to complete. Those are default settings, so you can omit them, as follows:

SELECT bdr.routing_leadership_transfer('group1', 'node1');

Using PGD CLI

You can use the switchover command to perform a switchover operation.

For example, to switch the write leader from node node1 to node node2 in group group1, use the following command:

pgd switchover --node-group group1 --node-name node1 --method strict --timeout 10s

This command switches the write leader using strict mode and waits for up to 10 seconds for the switchover to complete. Those are default settings, so you can omit them, as follows:

pgd switchover --node-group group1 --node-name node1