Home > mongodb > MongoDB: reduce file size

MongoDB: reduce file size

I have a small Digital Ocean VPS with MongoDB with 20 GB storage. The database dump is 1.7 GB, but the directory /var/lib/mongodb occupies about 7 GB disk space. If it goes on like that, I will run out of free space.

MongoDB 3 uses the WiredTiger storage engine, but before that the mmapv1 engine was the default. The mmapv1 has two options to reduce file size but WiredTiger doesn’t support these options :(

So I switched back to mmapv1. Here is my /etc/mongod.conf file that enables file size reduction:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
  dbPath: /var/lib/mongodb
    enabled: true
  engine: mmapv1
    preallocDataFiles: false
    smallFiles: true
#  wiredTiger:

# where to write logging data.
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
  port: 27017

Notice preallocDataFiles and smallFiles. Keep in mind that they may have negative impact on the performance. In my case I was just collecting a lot of data and not running out of free space was more important.

My new /var/lib/mongodb is 4 GB now, not 7 GB.

To figure out if Mongo uses WiredTiger or mmapv1, execute this in the mongo shell:

> db.serverStatus().storageEngine
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: