Perform Maintenance on Replica Set Members¶
Replica sets allow a MongoDB deployment to remain available during the majority of a maintenance window.
This document outlines the basic procedure for performing maintenance on each of the members of a replica set. Furthermore, this particular sequence strives to minimize the amount of time that the primary is unavailable and controlling the impact on the entire deployment.
For each member of a replica set, starting with a secondary member, perform the following sequence of events, ending with the primary:
- Restart the
mongodinstance as a standalone.
- Perform the task on the standalone instance.
- Restart the
mongodinstance as a member of the replica set.
Restart the secondary as a standalone on a different port.¶
At the operating system shell prompt, restart
as a standalone instance running on a different port and without
mongod --port 37017 --dbpath /srv/mongodb
mongod with the same user, even when
restarting a replica set member as a standalone instance.
mongod as a member of the replica set.¶
After performing all maintenance tasks, use the following procedure
to restart the
mongod as a member of the replica set
on its usual port.
mongo shell, shut down the standalone
server after completing the maintenance:
mongod instance as a member of
the replica set using its normal command-line arguments or
Perform maintenance on the primary last.¶
To perform maintenance on the primary after completing maintenance
tasks on all secondaries, use
rs.stepDown() in the
mongo shell to step down the primary and allow one of
the secondaries to be elected the new primary. Specify a 300 second
waiting period to prevent the member from being elected primary again
for five minutes:
After the primary steps down, the replica set will elect a new primary. See Replica Set Elections for more information about replica set elections.