Change the Oplog Size of Self-Managed Replica Set Members (original) (raw)
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 theprimary.
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>
To view the current size of the oplog, switch to the local
database and run db.collection.stats() against theoplog.rs
collection. stats() displays the oplog size as maxSize.
use local
db.oplog.rs.stats().maxSize
The maxSize
field displays the collection size in bytes.
Resize the oplog with the replSetResizeOplog command. Thesize
is a double and must be greater than 990
megabytes. To explicitly cast the oplog size
in mongosh, use theDouble()
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)})
Reducing the size of the oplog does not automatically reclaim the disk space allocated to the original oplog size. You must runcompact against the oplog.rs
collection in thelocal
database to reclaim disk space. There are no benefits to running compact
on the oplog.rs
collection after increasing the oplog size.
Important
A replica set member cannot replicate oplog entries when acompact
operation is ongoing on oplog.rs
because it prevents oplog synchronization. You must schedule compact
operations on the oplog during a maintenance window. Oplog replication cannot occur during that time window.
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 theoplog.rs
collection:
use local
db.runCommand({ "compact" : "oplog.rs" } )
For clusters enforcing authentication, authenticate as a user with the compact privilege action on the local
database and the oplog.rs
collection. For complete documentation on compact authentication requirements, see compact Required Privileges.