Sharding an existing database

658 views
Skip to first unread message

wmwong

unread,
Jan 7, 2010, 12:59:03 PM1/7/10
to mongodb-user
I was playing around with sharding using the MongoDB documents and got
it to work successfully. However, all the examples seem to start with
a brand new database.

What I'm wondering is if it is possible to shard an existing database
that was previously using mongod. Is it possible to shard this old
database and use mongos? If so, how do I go about doing this?

Thanks!

Eliot Horowitz

unread,
Jan 7, 2010, 3:35:05 PM1/7/10
to mongod...@googlegroups.com
It's actually pretty easy
What I would do if 5 min of downtime is ok (if not you should see how
to do it without)
1) restart mongod on port 27018
2) start config server
3) start mongod
4) add only your previous mongod as a shard
5) do at least a show collections for each db on the mongod through
mongod

That should be it

> --
> 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
> .
>
>

wmwong

unread,
Jan 7, 2010, 4:22:08 PM1/7/10
to mongodb-user
Thanks for the reply. I'm a little bit confused with the instructions.

1) restart mongod on port 27018 <-- am I doing this using --shardsvr?
2) start config server
3) start mongod <-- I don't need to start mongos?


4) add only your previous mongod as a shard
5) do at least a show collections for each db on the mongod through

mongod <-- I don't quite understand the "through mongod". Is this the
mongo console?

Thanks! At least I know that it is possible.

On Jan 7, 12:35 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> It's actually pretty easy
> What I would do if 5 min of downtime is ok (if not you should see how  
> to do it without)
> 1) restart mongod on port 27018
> 2) start config server
> 3) start mongod
> 4) add only your previous mongod as a shard
> 5) do at least a show collections for each db on the mongod through  
> mongod
>
> That should be it
>

wmwong

unread,
Jan 7, 2010, 4:43:11 PM1/7/10
to mongodb-user
Actually, I think I've figured it out. I tried running steps 1-5 with
the modifications I mentioned in my previous post and it seems to have
worked. I then added another shard server and after inserting some
records, MongoDB automatically moved chunks over to the second shard.

Thanks for your help!

Chuck Remes

unread,
Jan 7, 2010, 8:09:38 PM1/7/10
to mongod...@googlegroups.com

On Jan 7, 2010, at 3:43 PM, wmwong wrote:

> Actually, I think I've figured it out. I tried running steps 1-5 with
> the modifications I mentioned in my previous post and it seems to have
> worked. I then added another shard server and after inserting some
> records, MongoDB automatically moved chunks over to the second shard.
>
> Thanks for your help!

I'm not sure I understand the last part you wrote there. Do you mean that mongodb started to migrate/rebalance your original data from the original single database over multiple shards?

If that is the case, I will *definitely* have to check this out!

cr

Eliot Horowitz

unread,
Jan 7, 2010, 8:22:42 PM1/7/10
to mongod...@googlegroups.com
This won't happen automatically when it launches right now.
But as writes occur old data will start migrating to other shards.

Chuck Remes

unread,
Jan 7, 2010, 9:17:07 PM1/7/10
to mongod...@googlegroups.com
That's good enough for me.

cr

Reply all
Reply to author
Forward
0 new messages