On this page本页内容
replSetResizeOplog
¶New in version 3.6.版本3.6中的新功能。
Use the replSetResizeOplog
administrative command to change the size of a replica set member’s oplog. [1]
New in version 4.4:replSetResizeOplog
also supports specifying the minimum number of hours to preserve an oplog entry.
replSetResizeOplog
enables you to resize the oplog or its minimum retention period dynamically without restarting the mongod
process.
You must run this command against the admin
database.
The command has the following form:
replSetResizeOplog
takes the following fields:
replSetResizeOplog |
int | Set to 1 . |
size |
double | The maximum size of the oplog in megabytes.
|
minRetentionHours | double | Optional. The minimum number of hours to preserve an oplog entry, where decimal values represent the fractions of an hour. For example, a value of The value must be greater than or equal to A
To check the currently configured minimum oplog retention period, see the
|
You can only use replSetResizeOplog
on mongod
instances running with the Wired Tiger storage engine.
See the Change the Size of the Oplog tutorial for a procedure on using replSetResizeOplog
command to resize the oplog.
Starting in MongoDB 4.0, MongoDB forbids dropping the local.oplog.rs
collection. For more information on this restriction, see Oplog Collection Behavior.
replSetResizeOplog
overrides the maximum oplog size or minimum oplog retention period set at startup by replication.oplogSizeMB
/ --oplogSizeMB
and storage.oplogMinRetentionHours
/
--oplogMinRetentionHours
respectively. To persist the changes made by replSetResizeOplog
through a server restart, update the referenced configuration file settings or command line options passed to the mongod
.
Important
Reducing the maximum oplog size results in truncation of the oldest oplog entries until the oplog reaches the new configured size.
Similarly, reducing the minimum oplog retention period (new in 4.4) results in truncation of oplog entries older that the specified period if the oplog has exceeded the maximum configured size.
Oplog truncation due to reduced oplog size or retention period can result in unexpected behavior from clients still reading those oplog entries, including:
mongodump
with --oplog
against the member may not capture entries prior to truncation.A mongod
has the following behavior when configured with a minimum oplog retention period (New in 4.4):
mongod
may continue to hold that disk space even if the oplog returns to its maximum size or is configured for a smaller maximum size. See Reducing Oplog Size Does Not Immediately Return Disk Space.mongod
compares the system wall clock to an oplog entries creation wall clock time when enforcing oplog entry retention. Clock drift between cluster components may result in unexpected oplog retention behavior. See Clock Synchronization for more information on clock synchronization across cluster members.replSetResizeOplog
Does Not Replicate To Other Members¶Changing the oplog size or minimum oplog retention period (new in 4.4)
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 or minimum retention period for all members.
Reducing the oplog size does not immediately reclaim that disk space. This includes oplog size reduction due to truncation of oplog events older than of the minimum oplog retention period (New in 4.4).
To immediately free unused disk space after reducing the oplog size, run compact
against the oplog.rs
collection in the local
database during a maintenance period. 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.
Changed in version 4.2.2.
replSetResizeOplog
takes an exclusive (W) lock on the oplog
and blocks other operations on the collection until it finishes.replSetResizeOplog
takes a global exclusive (W) lock and blocks all other operations until it finishes.For more information on locking in MongoDB, see FAQ: Concurrency.
Use the db.collection.stats()
mongo
shell method to display the current maximum oplog size, maxSize
, in megabytes. For example:例如:
The above command returns the oplog size of this member in megabytes:
The following command uses replSetResizeOplog
to change the oplog size of this member to 16384 megabytes:
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 . |
mongo
shell to the mongod
replica set member.db.serverStatus()
command to verify the current minimum oplog retention value as oplogTruncation.oplogMinRetentionHours
:
The command returns the currently configured minimum oplog retention period for the mongod
. For example:例如:
If the mongod
has no minimum oplog retention period, the operation returns an empty result.
replSetResizeOplog
command to modify the configured minimum oplog retention period. For example, the following sets the minimum oplog retention period to 2
hours: