MongoDB Smallfiles – How to Switch and Optimize Storage

mongodb

I've reached a point where mongo fails to start because there's no enough free disk space. The log suggests using the --smallfiles option to start the mongod service.

So, I have two options, either make the hard drive bigger (it's an Amazon free instance) or doing what the mongodb log suggested.

Would data get corrupted if I enable --smallfiles for an existing mongo instance? I wouldn't want to lose any data.

Best Answer

Straight to the point? The smallfiles option doesn't help. It doesn't automagically shrink existing files. All this option does is changing the behavior of how data files are preallocated.

Usually, the first datafile allocated has a size of 64MB. The next has 128MB. This doubling goes on until 2GB are reached. After that, every new datafile is allocated with 2GB.

The smallfiles option simply sets the initial size to 16MB, and the doubling starts from there.

You need either to increase disk space or start to shard.