Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer

As Adam mentioned, "no", the files will not eventually compact on their own.

Just a note about the repair process, but remember that it takes twice the amount of disk space to run. In your case, your database is 14GB so you must also have an additional 14GB of free space on disk to successfully run repair.

At only 14GB you most likely won't have a problem. I thought I'd point that out for any future googlers who might be having issues with getting repair to run.

share|improve this answer
    
It's a maximum of 2x the data size, but usually not actually that much - especially if there has been a lot of deletions - not a bad guideline to use though –  Adam C Aug 27 '12 at 11:18
    
Both answer is correct. I can only select one. Thanks guys –  Jim Thio Aug 31 '12 at 2:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.