how to stop or pause replication on a secondary

3,765 views
Skip to first unread message

DaneXA

unread,
Jul 12, 2011, 6:54:52 PM7/12/11
to mongodb-user
Hello,

What's the right way to temporarily stop replication on a secondary in
a replica set? We need to run some queries against the secondary, but
the write load is too high while replication is running. I'd like to
stop replication, run the queries, then resume replication.

So far I've tried 'rs.remove(secondarynode)', but then got errors
querying the secondary.

We're using MongoDB 1.8.1 on 64bit Ubuntu.

Thanks,
Dane

Bernie Hackett

unread,
Jul 12, 2011, 7:50:01 PM7/12/11
to mongodb-user
What driver are you using? What errors did you get?

The problem I see with what you are trying to do is that if the load
from replication is that high your secondary is going to fail far
behind in replication before you add it back to the replica set.

DaneXA

unread,
Jul 12, 2011, 8:00:37 PM7/12/11
to mongodb-user
Bernie Hackett <ber...@10gen.com> wrote:
> What driver are you using? What errors did you get?
>
> The problem I see with what you are trying to do is that if the load
> from replication is that high your secondary is going to fail far
> behind in replication before you add it back to the replica set.

Thanks Bernie,

I guess before we get into troubleshooting an error, I was hoping to
learn the proper way to do this. I'm using the mongo shell to perform
the operations.

Dane

Bernie Hackett

unread,
Jul 12, 2011, 8:42:18 PM7/12/11
to mongodb-user
From my testing it looks like you can do this:

1. rs.remove(<secondary you want to query>)
2. Restart the secondary without --replSet
3. Run your queries
4. Restart the secondary with --replSet
6. rs.add(<secondary you queried>)

DaneXA

unread,
Jul 12, 2011, 8:57:06 PM7/12/11
to mongodb-user
On Jul 12, 5:42 pm, Bernie Hackett <ber...@10gen.com> wrote:
> From my testing it looks like you can do this:
>
> 1. rs.remove(<secondary you want to query>)
> 2. Restart the secondary without --replSet
> 3. Run your queries
> 4. Restart the secondary with --replSet
> 6. rs.add(<secondary you queried>)

Thanks. I just tested, and I believe --fastsync is also required in
Step 4, in addtion to --replSet.

Step 4 generates the following errors if I don't include --
fastsync ...

[startReplSets] replSet error self not present in the repl set
configuration:
[startReplSets] { _id: "replicasetname", version: 18, members:
[ { _id: 2, host: "rs-west1.mydomain.com", priority: 0.0 }, { _id: 1,
host: "rs-east2.mydomain.com" } ] }
[startReplSets] replSet error loading configurations 13497 replSet
error self not present in the configuration
[startReplSets] replSet error replication will not start
[startReplSets] replSet error loading set config
[startReplSets] replSet error fatal, stopping replication
[startReplSets] replSet ~RSBase called
[startReplSets] replSet caught exception in startReplSets thread:
replSet error self not present in the configuration

Dane

Bernie Hackett

unread,
Jul 12, 2011, 9:01:13 PM7/12/11
to mongodb-user
You have to run rs.remove() and rs.add() from the primary of the
replica set. Sorry, I should have made that clear.

DaneXA

unread,
Jul 12, 2011, 9:05:01 PM7/12/11
to mongodb-user
On Jul 12, 6:01 pm, Bernie Hackett <ber...@10gen.com> wrote:
> You have to run rs.remove() and rs.add() from the primary of the
> replica set. Sorry, I should have made that clear.

Yep, that's what I did. Thanks for clarifying. Any chance I can
request this info be put in the MogoDB documentation?

Dane

Bernie Hackett

unread,
Jul 12, 2011, 9:32:39 PM7/12/11
to mongodb-user
I'll have to double check but I think most of this already exists in
the docs, just not your specific use case.

DaneXA

unread,
Jul 13, 2011, 3:38:48 PM7/13/11
to mongodb-user
On Jul 12, 6:32 pm, Bernie Hackett <ber...@10gen.com> wrote:
> I'll have to double check but I think most of this already exists in
> the docs, just not your specific use case.

Well, there's some incomplete info here:
(see "Adding a former member"): http://www.mongodb.org/display/DOCS/Adding+a+New+Set+Member).

If you can provide links to documentation that covers this use case,
I'd love to see it. I think this use case is pretty mainstream.
Consider how this is done in mysql (our *other* database):

Pausing replication in Mysql:
slave> STOP SLAVE;
slave> ; do something...
slave> START SLAVE;

Just for the record, and to help folks searching this list for the
answer, here's how to pause replication in MongoDB Replica Sets,
v1.8.1:

Pausing replication in MongoDB 1.8.1:
1. PRIMARY> rs.remove(secondary.host.name:port);
2. restart secondary without --replSet
3. run read queries against the secondary
4. restart secondary with --fastsync --replSet
5. PRIMARY> rs.add(secondary.host.name:port);

Dane

brad103

unread,
Aug 8, 2011, 10:25:45 PM8/8/11
to mongodb-user
Hi Dane

Thanks for the efforts here, we too want to take the secondary offline
for backing up purposes.

My question for you guys is, why add and remove the replica from the
config? If the secondary is inaccessible then it's not receiving
updates anyway. We just got repeated errors in testing when trying to
re-add to the rs, even when --fastsync was used (which I wasn't
comfortable using, given that our primary had explictly received
updates during the pause). As long as the 'primary-ness' of the
primary is guaranteed by configuration, the below seems to work fine:

Pausing replication in MongoDB 1.8.1:
1. restart secondary without --replSet
2. run read queries against the secondary
3. restart secondary with --fastsync --replSet

Am I missing something?

Cheers
Brad

Scott Hernandez

unread,
Aug 8, 2011, 10:35:02 PM8/8/11
to mongod...@googlegroups.com
On Mon, Aug 8, 2011 at 10:25 PM, brad103 <a.eup...@googlemail.com> wrote:
> Hi Dane
>
> Thanks for the efforts here, we too want to take the secondary offline
> for backing up purposes.
>
> My question for you guys is, why add and remove the replica from the
> config? If the secondary is inaccessible then it's not receiving
> updates anyway. We just got repeated errors in testing when trying to
> re-add to the rs, even when --fastsync was used (which I wasn't
> comfortable using, given that our primary had explictly received
> updates during the pause). As long as the 'primary-ness' of the
> primary is guaranteed by configuration, the below seems to work fine:
>
> Pausing replication in MongoDB 1.8.1:
> 1. restart secondary without --replSet
> 2. run read queries against the secondary
> 3. restart secondary with --fastsync --replSet
>
> Am I missing something?

No, it is that simple.

Don't use --fastsync though.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

brad103

unread,
Aug 8, 2011, 11:27:39 PM8/8/11
to mongodb-user
Oops, meant to take the --fastsync out.

Thanks for the confirmation

Brad

On Aug 9, 2:35 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages