pgd raft set-leader
===================

Synopsis
--------

The ``pgd raft set-leader`` command manually triggers a leadership
transfer within a Raft group. It instructs the current leader to step
down and facilitates the election of the specified target node as the
new Raft leader.

Users and roles
^^^^^^^^^^^^^^^

Requires the ``bdr_superuser`` role. See :ref:`User roles <User roles>`  .

Syntax
------

.. code:: plaintext

   pgd raft set-leader [OPTIONS] <LEADER>

Arguments
---------

.. csv-table::
  :header: Argument,Description
  :widths: 10,30
  :align: left
  :class: longtable

  `<LEADER>`,The name of the node to become the new Raft leader.

Options
-------

The following options are available for the ``pgd raft set-leader``
command:

.. csv-table::
  :header: Short,Long,Description
  :widths: 12,15,25
  :align: left
  :class: longtable

  "",--group,"The name of the group in which to change the leader. If omitted, the global group is used."
  "",--wait-for-completion,"If set, the CLI will block and monitor the cluster state until the target node successfully assumes leadership or the operation times out."

See `Global Options <https://www.enterprisedb.com/docs/pgd/latest/reference/cli/command_ref/#global-options>`_  for common global options.

Examples
--------

Change the leader of the global group
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: shell

   pgd raft set-leader kaboom
   __OUTPUT__
   Command submitted successfully

Attempt to set a node that is already the leader
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: shell

   pgd raft set-leader kaftan --group dc1_subgroup
   __OUTPUT__
   Node kaftan is already the raft leader

Change the leader and wait for completion
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Using the ``--wait-for-completion`` flag sets a 60-second statement
timeout. The CLI will attempt to verify the new leader using the
existing connection, or retry with a new connection if a proxy (like
Connection Manager) reroutes the traffic.

.. code:: shell

   pgd raft set-leader kaolin --group dc1_subgroup --wait-for-completion
   __OUTPUT__
   Command executed successfully
