liveBook · Manning

Oplog minimum retention period

As explained in MongoDB 8.0 in Action, Third Edition

The oplog minimum retention period is a MongoDB setting specifying the minimum age-based duration for retaining oplog entries.

The oplog minimum retention period sets an age threshold for oplog entries. A secondary performing logical initial sync needs older entries to remain available while it copies data and applies ongoing changes. If those entries disappear first, the secondary can fall off the oplog. section 9.1.3

Configure the threshold for the deployment you operate:

  • For mongod, set storage.oplogMinRetentionHours in its configuration file or pass --oplogMinRetentionHours at startup. Without a minimum, MongoDB trims the oldest entries to stay within the oplog size limit. With one set, an entry is deleted only when the size limit has been reached and its age exceeds the specified hours. section 9.1.3
  • For an Atlas cluster with storage autoscaling enabled, adjust the minimum oplog retention window in the Atlas UI; its default is 24 hours. Atlas also describes a maximum oplog size, so consider the configured retention window alongside storage limits. section 10.2.4
Listing 9.5 Output of the db.getReplicationInfo() command
db.getReplicationInfo()
{
  configuredLogSizeMB: 4096,
  logSizeMB: 4096,
  usedMB: 4074.63,
  timeDiff: 635133,
  timeDiffHours: 176.43,
  tFirst: 'Wed Mar 20 2024 10:44:15 GMT+0000 (Coordinated Universal Time)',
  tLast: 'Wed Mar 27 2024 19:09:48 GMT+0000 (Coordinated Universal Time)',
  now: 'Wed Mar 27 2024 19:09:49 GMT+0000 (Coordinated Universal Time)'
}

Use db.getReplicationInfo() to inspect the observed oplog window. The sample reports 176.43 hours between its oldest and newest entries; that observed span is not itself the configured minimum. section 9.1.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Defines the deletion conditions and identifies configuration controls, but does not walk through changing a live deployment.
Examples
Shows a db.getReplicationInfo() output with a 176.43-hour oplog window and an Atlas default of 24 hours.
What it assumes
Assumes replica-set and oplog context while explaining why initial sync needs retained entries.
What you can do after
Operate/configure it through mongod settings or the Atlas UI, and inspect the observed window with db.getReplicationInfo().
How it connects
Connects oplog size and oplog window to secondary initial sync and Atlas storage autoscaling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.