Docs Menu
Docs Home
MongoDB Manual
/ /

Change the Size of the Oplog

On this page

  • A. Connect to the replica set member
  • B. (Optional) Verify the current size of the oplog
  • C. Change the oplog size of the replica set member
  • D. (Optional) Compact to reclaim disk space


You cannot drop the collection. For more information on this restriction, see Oplog Collection Behavior.

This procedure changes the size of the oplog [1] on each member of a replica set using the replSetResizeOplog command, starting with the secondary members before proceeding to the primary.

Perform these steps on each secondary replica set member first. Once you have changed the oplog size for all secondary members, perform these steps on the primary.

Connect to the replica set member using mongosh:

mongosh --host <hostname>:<port>


If the replica set enforces authentication, you must authenticate as a user with privileges to modify the local database, such as the clusterManager or clusterAdmin role.

To view the current size of the oplog, switch to the local database and run db.collection.stats() against the collection. stats() displays the oplog size as maxSize.

use local

The maxSize field displays the collection size in bytes.

Resize the oplog with the replSetResizeOplog command. The size is a double and must be greater than 990 megabytes. To explicitly cast the oplog size in mongosh, use the Double() constructor.

The following operation changes the oplog size of the replica set member to 16 gigabytes, or 16000 megabytes.

db.adminCommand({replSetResizeOplog: 1, size: Double(16000)})
[1] The oplog can grow past its configured size limit to avoid deleting the majority commit point.

Reducing the size of the oplog does not automatically reclaim the disk space allocated to the original oplog size. You must run compact against the collection in the local database to reclaim disk space. There are no benefits to running compact on the collection after increasing the oplog size.


A replica set member can replicate oplog entries while the compact operation is ongoing. As a result, it is no longer necessary to limit compaction operations on the oplog to maintenance windows, as oplog replication can continue as normal during compaction.

Do not run compact against the primary replica set member. Connect a mongo shell directly to the primary (not the replica set) and run rs.stepDown(). If successful, the primary steps down. From the mongo shell, run the compact command on the now-secondary member.

The following operation runs the compact command against the collection:

use local
db.runCommand({ "compact" : "" } )

For clusters enforcing authentication, authenticate as a user with the compact privilege action on the local database and the collection. For complete documentation on compact authentication requirements, see compact Required Privileges.


Replica Set Maintenance Tutorials


Perform Maintenance on Replica Set Members