> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# oplog Sizing

The [mongosync](https://www.mongodb.com/docs/mongosync/current/reference/mongosync-binary.md#std-label-c2c-mongosync) program uses [change streams](https://www.mongodb.com/docs/manual/changeStreams.md#std-label-changeStreams) to synchronize data between source and destination clusters. `mongosync` does not access the [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog) directly, but when a change stream returns events from the past, the events must be within the `oplog` time range.

`mongosync` applies operations in the `oplog` on the source cluster to the data on the destination cluster after the [collection copy](https://www.mongodb.com/docs/mongosync/current/about-mongosync.md#std-label-c2c-collection-copy) phase.  When operations that `mongosync` has not applied roll off the `oplog` on the source cluster, the sync fails and `mongosync` exits.

**Note:**

`mongosync` does not replicate [`applyOps`](https://www.mongodb.com/docs/manual/reference/command/applyOps.md#mongodb-dbcommand-dbcmd.applyOps) operations made on the source cluster during sync to the destination cluster.

If you anticipate syncing a large data set, or if you plan to pause synchronization for an extended period of time, you might exceed the [oplog window](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog-window). Use the [`oplogSizeMB`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-replication.oplogSizeMB) setting to increase the size of the `oplog` on the source cluster.

## Considerations

The destination cluster must have enough disk storage to accommodate the logical data size being migrated and the destination oplog entries from the initial sync. For example, to migrate 10 GB of data, the destination cluster must have at least 10 GB available for the data and another 10 GB for the insert oplog entries from the initial sync.

To use [embedded verification](https://www.mongodb.com/docs/mongosync/current/reference/verification/embedded.md#std-label-c2c-embedded-verifier), you must have a larger oplog on the destination. If you enable the embedded verifier and reduce the size of the destination oplog, the embedded verifier might not be able to keep up, causing `mongosync` to error.

If you need to reduce the overhead of the destination oplog entries and the embedded verifier is disabled, you can:

- Use the [`oplogSizeMB`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-replication.oplogSizeMB) setting to lower the destination cluster's oplog size.

- Use to [`oplogMinRetentionHours`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-storage.oplogMinRetentionHours) setting to lower or remove the destination cluster's minimum oplog retention period.

## Monitor oplog Size Needed for Initial Sync

1. Determine oplog window.

   To get the difference in seconds between the first and last entry in the `oplog` run [`db.getReplicationInfo()`](https://www.mongodb.com/docs/manual/reference/method/db.getReplicationInfo.md#mongodb-method-db.getReplicationInfo). If you are replicating a sharded cluster, run the command on each shard.

   ```javascript
   db.getReplicationInfo().timeDiff

   ```

   The value returned is the minimum `oplog` window of the cluster. If there are multiple shards, the smallest number is the minimum `oplog` window.

2. Determine `mongosync` replication lag.

   To get the `lag.overallLagSeconds` value, run the [/progress](https://www.mongodb.com/docs/mongosync/current/reference/api/progress.md#std-label-c2c-api-progress) command. The lag time is the time in seconds between the last event applied by `mongosync` and time of the current latest event on the source cluster.

   It is a measure of how far behind the source cluster `mongosync` is.

3. Validate oplog size.

   If the lag time approaches the minimum `oplog` window, make one of the following changes:

   - Increase the `oplog` window. Use [`replSetResizeOplog`](https://www.mongodb.com/docs/manual/reference/command/replSetResizeOplog.md#mongodb-dbcommand-dbcmd.replSetResizeOplog) to set `minRetentionHours` greater than the current `oplog` window.

     **Note:**

     [`replSetResizeOplog`](https://www.mongodb.com/docs/manual/reference/command/replSetResizeOplog.md#mongodb-dbcommand-dbcmd.replSetResizeOplog) is unsupported in Atlas. To resize the oplog in Atlas, see [Set Minimum Oplog Window.](https://www.mongodb.com/docs/atlas/cluster-additional-settings.md#std-label-set-oplog-min-window)

   - Scale up the `mongosync` instance. Add CPU or memory to scale up the `mongosync` node so that it has a higher copy rate.

**Note:**

The [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog) window and rate of change for replication lag may vary during synchronization. Repeat these steps during a migration to monitor the progress.
