Home > mongodb > MongoDB: upgrade to the WiredTiger storage engine

MongoDB: upgrade to the WiredTiger storage engine

Problem
I started to use the MongoDB 2.x series and since then I’ve upgraded to MongoDB 3.2. MongoDB 3.0 introduced pluggable storage engines. In 3.0 the default was MMAPv1 but in 3.2 the default became the WiredTiger storage engine that has some advantages: document level concurrency, compression on data and indexes, etc. So naively, I checked my configuration:

$ mongo
MongoDB shell version: 3.2.0
connecting to: test
> db.serverStatus().storageEngine
{ "name" : "mmapv1", "supportsCommittedReads" : false }

What???

Solution
Well, since I had some MMAPv1 databases when I upgraded MongoDB, it continued to use the old storage engine, so it’s understandable why I didn’t have WiredTiger. When I got over the shock, I decided to upgrade to the new engine. Here are the steps (under Manjaro):

Make a full backup of your databases:

$ mongodump --out <exportDirectory>

Stop the mongod process:

$ systemctl stop mongodb

Try to start the mongo shell with the command “mongo”. If it fails, then the server is correctly stopped.

Rename your database folder and create a new one. The “#” prompt means a root prompt.

# cd /var/lib
# mv mongodb mongodb.mmapv1
# mkdir mongodb
# chown mongodb mongodb
# chgrp daemon mongodb

Make a copy of your log file:

# cd /var/log/mongodb
# mv mongod.log mongod.log.mmapv1

Edit the config file /etc/mongodb.conf . I still had the old format (the new format uses YAML), but if it works then I don’t replace it yet. Add the following line to its end:

storageEngine=wiredTiger

Now restart the server:

$ systemctl start mongodb

And check if it uses the new engine:

$ mongo
MongoDB shell version: 3.2.0
connecting to: test
> db.serverStatus().storageEngine
{ "name" : "wiredTiger", "supportsCommittedReads" : true }

Great! Now restore the databases that we backed up in the first step.

$ mongorestore <exportDirectory>

It will take a while. Let’s do a final check. Print the stats of a collection (sample):

$ mongo
MongoDB shell version: 3.2.0
connecting to: test
> show dbs
mydb
> use mydb
switched to db mydb
> show collections
mycoll
> db.mycoll.stats()
{
        "ns" : "crunchbase.companies",
        "count" : 18801,
        "size" : 72236994,
        "avgObjSize" : 3842,
        "storageSize" : 36052992,
        "capped" : false,
        "wiredTiger" : {
                "metadata" : {
                        "formatVersion" : 1
                },
        ...

It’s in WiredTiger format. Awesome.

If you want, you can delete the folder /var/lib/mongodb.mmapv1 with the old databases. But first make sure that everything works as before the migration.

Links

Advertisements
  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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: