MongoDB data remove - reclaim diskspace [duplicate]
Asked Answered
W

3

20

Possible Duplicate:
Auto compact the deleted space in mongodb?

My understanding is that on delete operations MongoDB won't free up the disk space but would reuse it as needed.

  1. Is that correct?
  2. If not, would I have run a repair command?
  3. Could the repair be run on a live mongo instance?
Wooer answered 1/4, 2011 at 20:38 Comment(0)
M
19
  1. Yes it is correct.
  2. No, better to give mongodb as much disk space as possible( if mongodb can allocate more space than less disk fragmentation you will have, in additional allocating space is expensive operation). But if you wish you can run db.repairDatabase() from mongodb shell to shrink database size.
  3. Yes you can run repairDatabase on live mongodb instance ( better to run it in none peak hours)
Mcquoid answered 1/4, 2011 at 21:6 Comment(1)
While you can run repair on a live system it will make it unusable since it locks the server while running; I would argue that effectively means you can't run it on a live instance if you plan to keep using that instance.Lucinalucinda
V
7

This is somewhat of a duplicate of this MongoDB question ...

Auto compact the deleted space in mongodb?

See that answer for details on how to ...

  • Reclame some space
  • Use serverside JS to run a recurring job to get back space (including a script you can run ...)
  • How you might want to look into Capped Collections for some use cases!

Also you can see this related blog posting: http://learnmongo.com/posts/compacting-mongodb-data-files/

Vitriolic answered 1/4, 2011 at 21:19 Comment(0)
F
3

I have another solution that might work better than doing db.repairDatabase() if you can't afford for the system to be locked, or don't have double the storage.

You must be using a replica set.

My thought is once you've removed all of the excess data that's gobbling your disk, stop a secondary replica, wipe its data directory, start it up and let it resynchronize with the master. Repeat with the other secondaries, one at a time.

On the master, do an rs.stepDown() to hand over MASTER to one of the synched secondaries, now stop this one, wipe it, and let it resync.

The process is time consuming, but it should only cost a few seconds of down time, when you do the rs.stepDown().

Fourwheeler answered 13/11, 2012 at 21:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.