Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB file size too big

I just want to understand why MongoDB uses that much disk space or even better would be to possibly reduce it.

The following is just an example. I have a storageSize of 1,35GB (includes dataSize + preallocated space), the index size is about 0,5GB, sums up to roughly 2GB. I know that mongodb allocates 2GB files, so you could loose some space there, but how is it possible to use 6GB of file size? Padding is set to 1, actually it's just once written data, never any deletes or updates. Is there any possibility to reduce the file size?

In my case, MongoDB uses 6 times more space than my traditional SQL solution. I really want to use MongoDB, but I need to find a way to reduce diskspace. Thank you!

> db.stats(1024*1024)
{
    "db" : "data",
    "collections" : 4345,
    "objects" : 9328910,
    "avgObjSize" : 67.95158105287756,
    "dataSize" : 604,
    "storageSize" : 1350,
    "numExtents" : 6480,
    "indexes" : 8686,
    "indexSize" : 511,
    "fileSize" : 6078,
    "nsSizeMB" : 16,
    "ok" : 1
}

note: "data" is the only database in use in this stats

like image 881
Mario Bertschler Avatar asked Mar 23 '26 01:03

Mario Bertschler


1 Answers

Is there any possibility to reduce the file size?

Well, partly yes. If you have a small/[many small] database/s you might want to use the smallfiles flag when starting you databaseprocess/es.
By doing so you will reduce the preallocated files from maximum 2 gigabytes to a maximum of 512 megabytes and the journal files from 1 gigabyte to 128 megabytes. Important to note, if you use this flag with a large database, the server need to create many files, which may affect performance.

If you have deleted enough data from you database you can run the db.repairDatabase() command to free unused disk space. Just remember that running this command will create a global block in you database.

like image 133
Mattias Avatar answered Mar 24 '26 18:03

Mattias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!