<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="group-replication-change-primary">
      </a>
      20.5.1.1 Changing the Primary
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045133606832">
  </a>
  <a class="indexterm" name="idm46045133605344">
  </a>
  <a class="indexterm" name="idm46045133604240">
  </a>
  <a class="indexterm" name="idm46045133602752">
  </a>
  <p>
   This section explains how to change which member of a
        single-primary group is the primary, using the
   <a class="link" href="group-replication-functions-for-new-primary.html#function_group-replication-set-as-primary">
    <code class="literal">
     group_replication_set_as_primary()
    </code>
   </a>
   function, which can be can be run on any member of the group.
        When this is done, the current primary becomes a read-only
        secondary, and the specified group member becomes the read/write
        primary; this replaces the usual primary election process (see
   <a class="xref" href="group-replication-single-primary-mode.html" title="20.1.3.1 Single-Primary Mode">
    Section 20.1.3.1, “Single-Primary Mode”
   </a>
   ).
  </p>
  <p>
   If a standard source-to-replica replication channel is running
        on the existing primary member in addition to the Group
        Replication channels, you must stop that replication channel
        before you can change the primary member. You can identify the
        current primary using the
   <code class="literal">
    MEMBER_ROLE
   </code>
   column
        in the Performance Schema
   <a class="link" href="performance-schema-replication-group-members-table.html" title="29.12.11.16 The replication_group_members Table">
    <code class="literal">
     replication_group_members
    </code>
   </a>
   table.
  </p>
  <p>
   If all members are not running the same MySQL Server version,
        you can specify a new primary member that is running the lowest
        MySQL Server version in the group only. This safeguard is
        applied to ensure the group maintains compatibility with new
        functions.
  </p>
  <p>
   Any uncommitted transactions that the group is waiting on must
        be committed, rolled back, or terminated before the operation
        can complete. You can specify a timeout from 0 seconds
        (immediately) up to 3600 seconds (60 minutes) for transactions
        that are running when you use the function. There is no default
        setting for the timeout, so if you do not set it, there is no
        upper limit to the wait time, and new transactions can start
        during that time.
  </p>
  <p>
   When the timeout expires, for any transactions that did not yet
        reach their commit phase, the client session is disconnected so
        that the transaction does not proceed. Transactions that reached
        their commit phase are allowed to complete. When you set a
        timeout, it also prevents new transactions starting on the
        primary from that point on. Explicitly defined transactions
        (with a
   <code class="literal">
    START TRANSACTION
   </code>
   or
   <code class="literal">
    BEGIN
   </code>
   statement) are subject to the timeout,
        disconnection, and incoming transaction blocking even if they do
        not modify any data. To allow inspection of the primary while
        the function is operating, single statements that do not modify
        data, as listed in
   <a class="xref" href="group-replication-configuring-consistency-guarantees.html#group-replication-nonblocking" title="Permitted Queries Under Consistency Rules">
    Permitted Queries Under Consistency Rules
   </a>
   , are permitted
        to proceed.
  </p>
  <p>
   Pass in the
   <a class="link" href="replication-options.html#sysvar_server_uuid">
    <code class="literal">
     server_uuid
    </code>
   </a>
   of the
        member which you want to become the new primary of the group by
        issuing the following statement:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa97614673"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> group_replication_set_as_primary<span class="token punctuation">(</span><em class="replaceable">member_uuid</em><span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   You can add a timeout as shown here:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa470391"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token keyword">SELECT</span> group_replication_set_as_primary<span class="token punctuation">(</span>‘<span class="token number">00371d66</span><span class="token operator">-</span><span class="token number">3c45</span><span class="token operator">-</span><span class="token number">11ea</span><span class="token operator">-</span><span class="token number">804b</span><span class="token operator">-</span><span class="token number">080027337932</span>’<span class="token punctuation">,</span> <span class="token number">300</span><span class="token punctuation">)</span></code></pre>
  </div>
  <p>
   To check the status of the timeout, use the
   <code class="literal">
    PROCESSLIST_INFO
   </code>
   column in the Performance
        Schema
   <a class="link" href="performance-schema-threads-table.html" title="29.12.22.8 The threads Table">
    <code class="literal">
     threads
    </code>
   </a>
   table, like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa99791230"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token keyword">NAME</span><span class="token punctuation">,</span> PROCESSLIST_INFO <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>threads 
<span class="token prompt">    -&gt;</span> <span class="token keyword">WHERE</span> <span class="token keyword">NAME</span><span class="token operator">=</span><span class="token string">"thread/group_rpl/THD_transaction_monitor"</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
            NAME<span class="token punctuation">:</span> thread/group_rpl/THD_transaction_monitor
PROCESSLIST_INFO<span class="token punctuation">:</span> Group replication transaction monitor<span class="token punctuation">:</span> Stopped client connections</span></code></pre>
  </div>
  <p>
   The status shows when the transaction monitoring thread has been
        created, when new transactions have been stopped, when the
        client connections with uncommitted transactions have been
        disconnected, and finally, when the process is complete and new
        transactions are allowed again.
  </p>
  <p>
   While the action runs, you can check its progress by issuing the
        statement shown here:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa73960582"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql"><span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> event_name<span class="token punctuation">,</span> work_completed<span class="token punctuation">,</span> work_estimated 
<span class="token prompt">    -&gt;</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>events_stages_current 
<span class="token prompt">    -&gt;</span> <span class="token keyword">WHERE</span> event_name <span class="token operator">LIKE</span> <span class="token string">"%stage/group_rpl%"</span>\G
<span class="token output"><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span> 1. row <span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span><span class="token punctuation">*</span>
    EVENT_NAME<span class="token punctuation">:</span> stage/group_rpl/Primary Election<span class="token punctuation">:</span> Waiting for members to turn on super_read_only
WORK_COMPLETED<span class="token punctuation">:</span> 3
WORK_ESTIMATED<span class="token punctuation">:</span> 5</span></code></pre>
  </div>
 </div>
 <br/>
</div>
