HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Does MongoDB auto compacting

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
automongodbcompactingdoes

Problem

I copy a collection to another collection. Data is 14GB. I deleted the copied collection. Yet the size of the directory is still 14 GB.

I chose repair but it seems to take forever. Actually inserting the whole data took only 20 minutes and the repair is still running till now.

It's just compacting data.

What happen if I do not repair the database? Will files eventually be compacted?

Solution

When you delete data like this, the files are not automatically rewritten to reflect the new size of the data (which is potentially a massive operation). Instead, the free space in those files is marked as free and will be re-used when you insert new data.

As you have found, the only way to reclaim that space on disk at the moment is a repair - that is not "just compacting data". In fact a repair rewrites your data files from scratch, essentially creating a brand new copy of them on another part of the disk before removing the old ones. Depending on how large the current data set is, how much data is left, and how fast your disk is, this can take a long time.

If you removed all data in a database, a faster and more efficient method to remove the data is to simply drop the database, which would not have this issue.

Context

StackExchange Database Administrators Q#23059, answer score: 3

Revisions (0)

No revisions yet.