- Reference >
- Database Commands >
- Replication Commands >
- replSetResizeOplog
replSetResizeOplog¶
On this page
Definition¶
-
replSetResizeOplog¶ New in version 3.6.
Use the
replSetResizeOplogadministrative command to change the size of a replica set member’s oplog. [1]replSetResizeOplogenables you to resize the oplog dynamically without restarting themongodprocess.You must run this command against the
admindatabase.The command has the following form:
Note
replSetResizeOplogtakes 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.
In MongoDB versions 3.4 and earlier, the oplog was resized by dropping
and recreating the local.oplog.rs collection. In MongoDB versions
3.6 and later, use the replSetResizeOplog command to resize
the oplog as shown in the Change the Size of the Oplog tutorial.
Starting in MongoDB 4.0, MongoDB forbids dropping the local.oplog.rs
collection. For more information on this restriction, see
Oplog Collection Behavior.
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.
Resource Locking¶
Changed in version 4.2.2.
- For MongoDB 4.2.2 and later,
replSetResizeOplogtakes an exclusive (W) lock on theoplogand blocks other operations on the collection until it finishes. - For MongoDB 4.2.1 and earlier,
replSetResizeOplogtakes a global exclusive (W) lock and blocks all other operations until it finishes.
For more information on locking in MongoDB, see FAQ: Concurrency.
Example¶
Use the stats command to display the current oplog size,
maxSize. For example:
The above command will return the oplog size of this member:
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.
To verify the new oplog size, rerun the stats command:
The above command returns:
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.
| [1] | Starting in MongoDB 4.0, the oplog can grow past its configured size
limit to avoid deleting the majority commit point. |