Online modification of oplog size by mongodb

Time:2021-4-14

From mongodb 3.6, you can use the command replsetresizeoplog to modify the oplog size of replica set members,Start with the secondary node, and then go to the primary node.The test environment of this paper is mongodb 4.2.

You can view the size of oplog through the command

handong1:PRIMARY> use local
switched to db local
handong1:PRIMARY> db.oplog.rs.stats().maxSize
NumberLong("5242880000")

The maxsize field displays the set size in bytes. You can see that the current node oplog size is 5242880000 / 1024 / 1024 = 5000MB.

Next, we modify the oplog size of each member of the replica set (master slave arbitration).
Modify firstsecondaryThe oplog size of the node.

handong1:SECONDARY> use local
switched to db local
handong1:SECONDARY> db.oplog.rs.stats().maxSize
NumberLong("10485760000")
handong1:SECONDARY> db.adminCommand({replSetResizeOplog: 1, size: 2000})
{
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1617786418, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1617786418, 1)
}
handong1:SECONDARY> db.oplog.rs.stats().maxSize
NumberLong(2097152000)

The secondary node oplog size is changed to 2000mb.

Then modify itprimaryThe oplog size of the node.

handong1:PRIMARY> use local
switched to db local
handong1:PRIMARY> 
handong1:PRIMARY> db.oplog.rs.stats().maxSize
NumberLong("5242880000")
handong1:PRIMARY> db.adminCommand({replSetResizeOplog: 1, size: 2000})
{
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1617786579, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    },
    "operationTime" : Timestamp(1617786579, 1)
}
handong1:PRIMARY> db.oplog.rs.stats().maxSize
NumberLong(2097152000)

You can see that the primary node oplog size has also been changed to 2000mb.