How to "defragment" MongoDB index effectively in production?

Posted by dfrankow on Stack Overflow See other posts from Stack Overflow or by dfrankow
Published on 2010-04-30T21:10:32Z Indexed on 2010/04/30 21:17 UTC
Read the original article Hit count: 289

Filed under:
|
|

I've been looking at MongoDB. Feels good.

I added some indexes to a collection, uploaded a bunch of data, then removed all the data, and I noticed the indexes did not change size, similar to the behavior reported here.

If I call

db.repairDatabase()

the indexes are then squashed to near-zero. Similarly if I don't remove all the data, but call repairDatabase(), the indexes are squashed somewhat (perhaps because unused extends are truncated?). I am getting index size from "totalIndexSize" of db.collection.stats().

However, that takes a long time (I've read it could be hours on a large database). It's unclear to me how available the database is for reads or writes while it is running. I am guessing not so available.

Since I want to run as few instances of mongod as possible, I want to understand more about how indexes are managed after deletes. Can anyone point me to anything or give any advice?

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about admin