replSetResizeOplog

On this page

Definition

replSetResizeOplog

New in version 3.6.

Use the replSetResizeOplog administrative command to change the size of a replica set member’s oplog. replSetResizeOplog enables you to resize the oplog dynamically without restarting the mongod process.

You must run this command against the admin database.

The command has the following form:

{ replSetResizeOplog: <boolean>, size: <num MB> }

Note

replSetResizeOplog takes the size parameter in megabytes while the oplog size is stored in bytes:

  • The minimum size you can specify is 990 megabytes.
  • The maximum size you can specify is 1 petabytes.

Behavior

You can only use replSetResizeOplog on mongod instances running with the Wired Tiger storage engine.

Changing the oplog size of a given replica set member with replSetResizeOplog does not change the oplog size of any other member in the replica set. You must run replSetResizeOplog on each replica set member in your cluster to change the oplog size for all members.

Reducing the oplog size does not reclaim that disk space automatically. You must run compact against the oplog.rs collection in the local database. compact blocks all operations on the database it runs against. Running compact against oplog.rs therefore prevents oplog synchronization. For a procedure on resizing the oplog and compacting oplog.rs, see Change the Size of the Oplog.

Example

Use the stats command to display the current oplog size, maxSize. For example:

use local
db.oplog.rs.stats().maxSize

The above command will return the oplog size of this member:

"maxSize": NumberLong("9790804377")

maxSize is currently 9790804377 bytes, or 9337 megabytes.

The following command changes the oplog size of this member to 17179869184 bytes, or 16384 megabytes.

To change the size, run the replSetResizeOplog, passing the desired size in megabytes as a parameter.

db.adminCommand({replSetResizeOplog:1, size: 16384})

To verify the new oplog size, rerun the stats command:

use local
db.oplog.rs.stats().maxSize

The above command returns:

"maxSize": NumberLong("17179869184")

Warning

Reducing the size of the oplog in a node removes data from it. This may cause replica members syncing with that node to become stale. To resync those members, see Resync a Member of a Replica Set.