DBAtlas · Database operations atlas

Resize the oplog online (replSetResizeOplog)

MongoDBReplica Set

Command

// Current oplog size (MB):
db.getSiblingDB("local").oplog.rs.stats().maxSize / 1024 / 1024
// Resize the oplog to 50 GB (in MB; run on each member separately, secondaries first):
db.adminCommand({ replSetResizeOplog: 1, size: 51200 })
// Minimum retention period (hours), independent of size:
db.adminCommand({ replSetResizeOplog: 1, minRetentionHours: 48 })
// Verify the result:
rs.printReplicationInfo()

What it does

Grows or shrinks the oplog of a running member without a restart; minRetentionHours keeps oplog entries for a minimum period even if the size limit is exceeded.

When to use it

When the oplog window does not cover the maintenance or initial sync duration, or bulk write jobs shrink the window.

Caution

The command affects only the member it runs on and is not replicated; apply it on every member. The window must also be sufficient on members that act as sync sources. Shrinking does not return disk space to the OS immediately; compact on oplog.rs is needed for that. With minRetentionHours the oplog can grow beyond size depending on write volume; plan disk accordingly.

Open in DBAtlas →

Related