How much free space does compact command need in MongoDB 2.0?

263 views
Skip to first unread message

toki

unread,
Dec 14, 2011, 4:45:06 AM12/14/11
to mongod...@googlegroups.com
I've using MongoDB 2.0 storing my daily statistic data.
The statistic collection updates very often and the data inside have many fragments.

I don't have 2x free space on the same host, so I decided to just run compact command on the statistic collection.

1st time:
Collection size: about 25GB
Free space left: about 4GB
Result: Failed. MongoDB alive but keep saying out of disk space in server log file, and only hundreds of GB free space left after compact runs.

2nd time:
Collection size: about 25GB
Free space left: about 8GB
Result: Failed. This time MongoDB server crashed. 1.7GB free space left after compact runs.

So, could anyone tell me, how many free space should I reserve for compacting a 25GB data collection in MongoDB 2.0?

Sergei Tulentsev

unread,
Dec 14, 2011, 9:26:09 AM12/14/11
to mongod...@googlegroups.com
From what I understand, `compact` command uses the same mechanism as repairDatabase(). It copies defragmented data to temp collection and, if successful, drops the original one and renames the temp.
So, there's no magical in-place compaction and you need 2x space (in the worst case).

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/fXlN0AxhnfsJ.
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.



--
Best regards,
Sergei Tulentsev

Spencer T Brody

unread,
Dec 14, 2011, 5:48:59 PM12/14/11
to mongod...@googlegroups.com
Yep, that's correct.  In most cases the compact command uses less space than repairDatabase(), but in the worst case it too can use 2x space.  You should also be aware, however, that compact defragments data within the mongod data files, giving the mongod process more data to work with, but does not release that space back to the OS. Therefore, running compact will give mongo more room to store new documents, but the datasize on disk may actually *increase*.  The next version of mongodb will be better about using less disk space for compact().

toki

unread,
Dec 18, 2011, 9:16:14 PM12/18/11
to mongod...@googlegroups.com
Seems following lines are beautiful dream. :-P

Unlike repairDatabase, the compact command does not require double disk space to do its work. It does require a small amount of additional space while working. Additionally, compact is faster.

I just got it done without using compact or repair database. But that's not a good way.
I dumped the collection, killed all data files and restored my data back and got a cleaned and compacted collection.

Spencer T Brody

unread,
Dec 19, 2011, 11:32:46 AM12/19/11
to mongod...@googlegroups.com
I updated the documentation to make the disk usage clearer.  Thank you for pointing that out!

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/-ScbGzbY0-0J.
Reply all
Reply to author
Forward
0 new messages