Replica Set Oplog

    Theoplog(operations log) is a specialthat keeps a rolling record of all operations that modify the data stored in your databases. MongoDB applies database operations on theprimaryand then records the operations on the primary’s oplog. Themembers then copy and apply these operations in an asynchronous process. All replica set members contain a copy of the oplog, in thecollection, which allows them to maintain the current state of the database.

    To facilitate replication, all replica set members send heartbeats (pings) to all other members. Any member can import oplog entries from any other member.

    Each operation in the oplog is. That is, oplog operations produce the same results whether applied once or multiple times to the target dataset.

    When you start a replica set member for the first time, MongoDB creates an oplog of a default size.

    For Unix and Windows systems

    For 64-bit macOS systems

    The default oplog size is 192 MB of either physical memory or free disk space depending on the storage engine:

    Storage Engine Default Oplog Size
    In-Memory Storage Engine 192 MB of physical memory
    192 MB of free disk space
    MMAPv1 Storage Engine 192 MB of free disk space

    In most cases, the default oplog size is sufficient. For example, if an oplog is 5% of free disk space and fills up in 24 hours of operations, then secondaries can stop copying entries from the oplog for up to 24 hours without becoming too stale to continue replicating. However, most replica sets have much lower operation volumes, and their oplogs can hold much higher numbers of operations.

    Beforecreates an oplog, you can specify its size with theoption. However, after you have started a replica set member for the first time, you can only change the size of the oplog using theprocedure.

    If you can predict your replica set’s workload to resemble one of the following patterns, then you might want to create an oplog that is larger than the default. Conversely, if your application predominantly performs reads with a minimal amount of write operations, a smaller oplog may be sufficient.

    The oplog must translate multi-updates into individual operations in order to maintainidempotency. This can use a great deal of oplog space without a corresponding increase in data size or disk use.

    If you delete roughly the same amount of data as you insert, the database will not grow significantly in disk use, but the size of the operation log can be quite large.

    If a significant portion of the workload is updates that do not increase the size of the documents, the database records a large number of operations but does not change the quantity of data on disk.

    To view oplog status, including the size and the time range of operations, issue themethod. For more information on oplog status, seeCheck the Size of the Oplog.

    Under various exceptional situations, updates to aoplog might lag behind the desired performance time. Usefrom a secondary member and theoutput to assess the current state of replication and determine if there is any unintended replication delay.