How to "defragment" the MongoDB index efficiently in production?

I was looking at MongoDB. Good.

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

If i call

db.repairDatabase() 

indexes are then crushed to zero. Similarly, if I do not delete all the data, but call repairDatabase (), the indexes are a little compressed (perhaps because unused extensions are truncated?). I get an index of size from "totalIndexSize" from db.collection.stats ().

However, this takes a lot of time (I read that it can be hours in a large database). I do not understand how accessible the database is for reading or writing while it is running. I guess this is not so affordable.

Since I want to run as few mongod instances as possible, I want to learn more about how to manage indexes after deletion. Can someone point me to something or give any advice?

+4
source share
2 answers

To summarize David related question :

  • There is no way other than db.repairDatabase ().
  • If you need to minimize downtime, configure the master / slave and the "repairDatabase" slave, then switch the slave and master.
+1
source

I think Reducing the file size of a MongoDB database answers your question.

0
source

Source: https://habr.com/ru/post/1308506/


All Articles