Find file
Fetching contributors…
Cannot retrieve contributors at this time
176 lines (128 sloc) 5.49 KB
Force a Member to Become Primary
.. default-domain:: mongodb
.. contents:: On this page
:backlinks: none
:depth: 1
:class: singlecol
You can force a :term:`replica set` member to become :term:`primary`
by giving it a higher
:rsconf:`members[n].priority` value than any other
member in the set.
Optionally, you also can force a member never to become primary by
setting its :rsconf:`members[n].priority` value to
``0``, which means the member can never seek :ref:`election
<replica-set-elections>` as primary. For more information, see
For more information on priorities, see
A majority of the configured members of a replica set *must* be
available for a set to reconfigure a set or elect a primary. See
:doc:`/core/replica-set-elections` for more information.
.. _replica-set-force-member-to-be-primary-via-priority-setting:
Force a Member to be Primary by Setting its Priority High
This procedure assumes your current :term:`primary` is
```` and that you'd like to instead make ```` primary.
The procedure also assumes you have a three-member :term:`replica set` with the
configuration below. For more information on configurations, see :ref:`Replica Set
Configuration Use <replica-set-reconfiguration-usage>`.
This procedure assumes this configuration:
.. code-block:: javascript
"_id" : "rs",
"version" : 7,
"members" : [
"_id" : 0,
"host" : ""
"_id" : 1,
"host" : ""
"_id" : 2,
"host" : ""
1. In a :program:`mongo` shell connected to the primary, use the
following sequence of operations to make ```` the primary:
.. code-block:: javascript
cfg = rs.conf()
cfg.members[0].priority = 0.5
cfg.members[1].priority = 0.5
cfg.members[2].priority = 1
The last statement calls :method:`rs.reconfig()` with the modified
configuration document to configure ```` to have a higher
:rsconf:`members[n].priority` value than the other
:program:`mongod` instances.
The following sequence of events occur:
- ```` and ```` sync with
```` (typically within 10 seconds).
- ```` sees that it no longer has highest priority and,
in most cases, steps down. ```` *does not* step down
if ````'s sync is far behind. In that case,
```` waits until ```` is within 10
seconds of its optime and then steps down. This minimizes the
amount of time with no primary following failover.
- The step down forces on election in which ````
becomes primary based on its :data:`priority
<replSetGetConfig.members[n].priority>` setting.
#. Optionally, if ```` is more than 10 seconds behind
````'s optime, and if you don't need to have a primary
designated within 10 seconds, you can force ```` to
step down by running:
.. code-block:: javascript
db.adminCommand({replSetStepDown: 86400, force: 1})
This prevents ```` from being primary for 86,400
seconds (24 hours), even if there is no other member that can become primary.
When ```` catches up with ```` it will
become primary.
If you later want to make ````
primary again while it waits for ```` to catch up,
issue the following command to make ```` seek election
.. code-block:: javascript
The :method:`rs.freeze()` provides a wrapper around the
:dbcommand:`replSetFreeze` database command.
.. _replica-set-force-member-to-be-primary-via-dbcommands:
Force a Member to be Primary Using Database Commands
.. versionchanged:: 1.8
Consider a :term:`replica set` with the following members:
- ```` - the current :term:`primary`.
- ```` - a :term:`secondary`.
- ```` - a secondary .
To force a member to become primary use the following procedure:
1. In a :program:`mongo` shell, run :method:`rs.status()` to ensure your replica
set is running as expected.
#. In a :program:`mongo` shell connected to the :program:`mongod`
instance running on ````, freeze
```` so that it does not attempt to become primary
for 120 seconds.
.. code-block:: javascript
#. In a :program:`mongo` shell connected the :program:`mongod` running
on ````, step down this instance that the
:program:`mongod` is not eligible to become primary for 120
.. code-block:: javascript
```` becomes primary.
.. note:: During the transition, there is a short window where
the set does not have a primary.
For more information, consider the :method:`rs.freeze()` and
:method:`rs.stepDown()` methods that wrap the
:dbcommand:`replSetFreeze` and :dbcommand:`replSetStepDown` commands.