Change Replica Set to WiredTiger

Starting in version 3.2, WiredTiger is the default storage engine for MongoDB.

This tutorial gives an overview of changing the storage engine of a member of a replica set to WiredTiger.

Considerations

Replica sets can have members with different storage engines. As such, you can update members to use the WiredTiger storage engine in a rolling fashion.

MongoDB 3.6 and PSA 3-member Architecture

Starting in MongoDB 3.6, "majority" read concern, available for WiredTiger, is enabled by default. However, for MongoDB 3.6.1-3.6.x, if you have a three-member replica set with a primary-secondary-arbiter (PSA) architecture, you can disable "majority" read concern. Disabling "majority" for a three member PSA architecture avoids possible cache-pressure build up.

The procedure below disables "majority" read concern for MongoDB 3.6.1-3.6.x PSA architecture by including --enableMajorityReadConcern false. If you are running a MongoDB 3.6.0 PSA architecture, first upgrade to the latest 3.6 version in order to disable this read concern.

Note

Disabling "majority" read concern disables support for Change Streams.

For more information on PSA architecture and read concern "majority", see Disable Read Concern Majority.

MongoDB 3.0 or Greater

You must be using MongoDB version 3.0 or greater in order to use the WiredTiger storage engine. If using an earlier MongoDB version, you must upgrade your MongoDB version before proceeding to change your storage engine. To upgrade your MongoDB version, refer to the appropriate version of the manual.

Default Bind to Localhost

Starting with MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. From MongoDB versions 2.6 to 3.4, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages would bind to localhost by default. To learn more about this change, see Localhost Binding Compatibility Changes.

XFS and WiredTiger

With the WiredTiger storage engine, using XFS for data bearing nodes is recommended on Linux. For more information, see Kernel and File Systems.

Procedure

To update a member to WiredTiger, the procedure removes a member’s data, starts mongod with WiredTiger, and performs an initial sync.

Tip

  • To update all members of the replica set to use WiredTiger, update the members in a rolling manner. That is, update, one by one, all secondary members first. Then, once all the secondary members have been updated, step down the primary, and update that stepped-down member.
  • If you are running a MongoDB 3.6.0 three-member PSA architecture and wish to disable "majority" read concern, upgrade first to the latest 3.6 version.

A. Update secondary members.

1

Shut down the secondary member.

In the mongo shell, shut down the secondary mongod instance.

use admin
db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member’s current data directory or create a new directory entirely.

mongod with WiredTiger will not start with data files created with a different storage engine.

3

Start mongod with WiredTiger.

Start mongod, specifying wiredTiger as the --storageEngine and the prepared data directory for WiredTiger as the --dbpath. Specify additional options, such as --bind_ip, as appropriate for this replica set member.

Warning

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses>

Important

If you are running a three-member PSA architecture and MongoDB version 3.6.1-3.6.x, include --enableMajorityReadConcern false to disable read concern majority. See MongoDB 3.6 and PSA 3-member Architecture.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses> --enableMajorityReadConcern false

Since no data exists in the --dbpath, the mongod will perform an initial sync. The length of the initial sync process depends on the size of the database and network connection between members of the replica set.

You can also specify the options in a configuration file. To specify the storage engine, use the storage.engine setting.

To update another secondary, repeat the previous steps.

B. Step down the primary.

Important

If updating all members of the replica set to use WiredTiger, ensure that all secondary members have been updated first before updating the primary.

To update the primary, step down the primary.

rs.stepDown()

C. Update the stepped down primary.

When the primary has stepped down and become a secondary, update the secondary to use WiredTiger as before:

1

Shut down the secondary member.

In the mongo shell, shut down the secondary mongod instance.

use admin
db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member’s current data directory or create a new directory entirely.

mongod with WiredTiger will not start with data files created with a different storage engine.

3

Start mongod with WiredTiger.

Start mongod, specifying wiredTiger as the --storageEngine and the prepared data directory for WiredTiger as the --dbpath. Specify additional options, such as --bind_ip, as appropriate for this replica set member.

Warning

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see Security Checklist. At minimum, consider enabling authentication and hardening network infrastructure.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses>

Important

If you are running a three-member PSA architecture and MongoDB version 3.6.1-3.6.x, include --enableMajorityReadConcern false to disable read concern majority. See MongoDB 3.6 and PSA 3-member Architecture.

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<ipaddresses> --enableMajorityReadConcern false

Since no data exists in the --dbpath, the mongod will perform an