Administering PGD Proxy
=======================

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 will wait
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 will always try 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 :ref:`bdr.routing_leadership_transfer() <Routing functions>`  function.

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

edb_notranlate_0 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.

.. code:: sql

   SELECT bdr.routing_leadership_transfer(group1, node1);

Using PGD CLI
^^^^^^^^^^^^^

You can use the :ref:`Switchover <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:

.. code:: sh

   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.

.. code:: sh

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