Is it possible to split an existent ReplicaSet?

Is it possible to remove a node from a replica set and start a new replica set from it ?

I haven’t seen any topics, article, docs or posts about this, but I believe it would only to change the replica set configuration on the isolated node by removing the other nodes. :thinking:

Hello @Lucas,

Is it possible to remove a node from a replica set and start a new replica set from it ?

Yes you can.

Assume you have a replica-set with three nodes: “localhost:27011”, “localhost:27012” and “localhost:27013”. And, the node with port 27011 is the primary and you want to remove the node on port 27012.

Now, remove the replica-set node:

  • Connect to the secondary member to be removed from the shell, and stop the instance.

    use admin
    db.shutdownServer()

  • Connect to the primary and remove the member from the replica-set:

    rs.remove(“localhost:27012”)
    rs.status() // or rs.isMaster(), and verify both before and after the remove.

  • Delete the data directory of the removed member (“localhost:27012”).

Now you have “localhost:27012” to create a new standalone member or a new replica-set from it.

Also see: Remove Members from Replica Set

2 Likes

Awesome @Prasad_Saya !

Thank you very much for the quick reply :wink:

But can I not remove the data from the removed node and still make it a stand alone or new replica set?

The main goal I’m looking for is to remove one node and making it as a point in time copy of the existent replica set

Hi @Lucas,

Then take a look at the Delayed Replica Set Members.

Hi @Lucas ,

Once you remove it from a replica set you can treat this as a recovery operation to create a new replicaset. Start at step 2.

https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/#restore-a-replica-set-from-mongodb-backups

1 Like

I’m aware of delayed replica set members @Prasad_Saya , but in my case I want to end up with two replica sets and not just a delayed instance.

To get a better picture of what I’m planning to do:

  1. I currently have a Replica Set (let’s call it RS-0) with 3 members (2 data, 1 arbiter);
  2. I’ll add a new data member as secundary and wait for it to sync up;
  3. Then, remove a secundary member from RS-0;
  4. And finally, with the removed member and all it’s existent data, I want to start a new Replica Set (e.g. RS-1);

By doing this I expect to endup with 2 Replica Sets, RS-0 and RS-1, which RS-1 started with a copy from RS-0. In a git analogy, RS-0 is my master branch and I want to create a branch RS-1 from it :upside_down_face:

I’m just not sure about step 4, if it is possible.

Yes, it is possible.

In my last post see this following step:

Connect to the primary and remove the member from the replica-set:

rs.remove(“localhost:27012”)
rs.status() // or rs.isMaster(), and verify both before and after the remove.

From this point you can do the following steps:

Use the configuration for the member “localhost:27012” with the same dbPath, etc., but without the replication option. For example, newConfig.cfg:

storage:
  dbPath: C:\mongo\data\replset\rs3\db
net:
  bindIp: localhost
  port: 27012
systemLog:
  destination: file
  path: C:\mongo\data\replset\rs3\mongod.log
  logAppend: true
# replication:
#  replSetName: myrset

If you specifying the parameters at command-line, start the mongod without the --replSet parameter, but pointing to the same data directory (the --dbpath parameter).

1. Restart the member as a standalone:

> mongod -f newConfig.cfg

Connect to it from mongo shell, and:

use local
show collections
oplog.rs

These collections in local database are related to replication.

2. Drop this local database and shutdown the server:

use local
db.dropDatabase()

use admin
db.shutdownServer()

3. Restart the server:

Now, specify the --replSet parameter, but with a new replica set name. Or in the configuration file newConfig.cfg specify the options with new replica set name. For example:

replication:
  replSetName: RS-1

> mongod -f newConfig.cfg

Connect to it from mongo shell.

3.1. Initiate the new replica-set.

rs.initiate()

This member becomes the primary of the newly created replica-set. Verify:

rs.isMaster()

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.