Skip to content

DOCS-13922 describes procedure for renaming replica sets #5090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/administration/replica-set-maintenance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ replica sets.
:doc:`/tutorial/configure-replica-set-secondary-sync-target`
Specify the member that a secondary member synchronizes from.

:doc:`/tutorial/rename-unsharded-replica-set`
Rename an unsharded replica set.


.. toctree::
:titlesonly:
Expand All @@ -65,3 +68,4 @@ replica sets.
/tutorial/manage-chained-replication
/tutorial/change-hostnames-in-a-replica-set
/tutorial/configure-replica-set-secondary-sync-target
/tutorial/rename-unsharded-replica-set
12 changes: 7 additions & 5 deletions source/faq/replica-sets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ times.
Can I rename a replica set?
---------------------------

No.
Yes, unsharded replica sets can be renamed. This procedure requires
downtime.

You can use the backup and restore procedure described in the
:doc:`/tutorial/restore-replica-set-from-backup` tutorial to create a
new replica set with the desired name. Downtime may be necessary in
order to ensure parity between the original replica set and the new one.
To learn how to rename your replica set, see
:doc:`/tutorial/rename-unsharded-replica-set`.

Before renaming a replica set, perform a full
:doc:`backup of your MongoDB deployment </core/backups>`.
64 changes: 64 additions & 0 deletions source/includes/steps-rename-unsharded-replica-set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
title: Shut down replica set members.
level: 4
ref: shutdown-replica-set
content: |
Follow the procedure in :ref:`Stop a Replica Set <stop-replica-set>`
to confirm that replica set members are
:ref:`shut down <terminate-mongod-processes>`.

.. warning::

This step requires downtime as all replica members will need to be
shut down.

---
title: Rename the replica set.
level: 4
ref: rename-the-replica-set
content: |
Perform the following steps for each replica set member:

a. Update the replica set name.

- If using a :ref:`configuration file <conf-file>`, set
:setting:`replication.replSetName <replication.replSetName>`
to the new name.

- If using the :binary:`~bin.mongod` startup command with
the :option:`--replSet <mongod --replSet>` option, note down the
new replica set name for use in step f.

#. Start the replica set member on a different port without the
:option:`--replSet <mongod --replSet>` option.

#. Connect to the replica set member.

#. Update the replica set name in the :ref:`local database
<replica-set-local-database>` with the following commands:

.. code-block:: javascript

/* Set `newId` to the new replica set name */
var newId = '<new replica set name>'

var doc = db.getSiblingDB("local").system.replset.findOne()
var oldId = doc._id
doc._id = newId
db.getSiblingDB("local").system.replset.save(doc)
db.getSiblingDB("local").system.replset.remove({_id: oldId})

#. :ref:`Shut down <terminate-mongod-processes>` the replica set
member.

#. Start the replica set member on its original port.

- If using a configuration file, ensure that
:setting:`replication.replSetName <replication.replSetName>` is
set to the new replica set name.

- If using the :binary:`~bin.mongod` startup command with
the :option:`--replSet <mongod --replSet>` option, pass the new
name of the replica set to the
:option:`--replSet <mongod --replSet>` option.

...
3 changes: 1 addition & 2 deletions source/reference/replica-configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ Replica Set Configuration Fields

*Type*: string

The name of the replica set. Once set, you cannot change the
name of a replica set.
The name of the replica set.

:rsconf:`_id` *must* be identical to the
:setting:`replication.replSetName` or the value of `--replSet`
Expand Down
1 change: 1 addition & 0 deletions source/tutorial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Replica Sets
- :doc:`/tutorial/reconfigure-replica-set-with-unavailable-members`
- :doc:`/tutorial/recover-data-following-unexpected-shutdown`
- :doc:`/tutorial/troubleshoot-replica-sets`
- :doc:`/tutorial/rename-unsharded-replica-set`

Sharding
~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions source/tutorial/manage-mongodb-processes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ Starting in MongoDB 4.0.8 (and 3.6.15), if a replica set primary receives a

Never use ``kill -9`` (i.e. ``SIGKILL``) to terminate a mongod instance.

.. _stop-replica-set:

Stop a Replica Set
------------------

Expand Down
31 changes: 31 additions & 0 deletions source/tutorial/rename-unsharded-replica-set.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
====================
Rename a Replica Set
====================

.. default-domain:: mongodb

.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol

To rename a replica set, you must shut down all members of the replica
set, then configure each member's ``local`` database with the new
replica set name.

This procedure requires downtime.

Prerequisites
-------------

- Ensure your replica set is not sharded. The renaming procedure
is for unsharded replica sets only.

- Before renaming a replica set, perform a full
:doc:`backup of your MongoDB deployment </core/backups>`.

Procedure
---------

.. include:: /includes/steps/rename-unsharded-replica-set.rst