liveBook · Manning

Rs.printSecondaryReplicationInfo()

As explained in MongoDB 8.0 in Action, Third Edition

rs.printSecondaryReplicationInfo() is a mongosh helper, also available as db.printSecondaryReplicationInfo(), that reports replication lag for secondary replica-set members.

`rs.printSecondaryReplicationInfo()` is a mongosh helper for checking how far secondary replica-set members lag behind the primary. The equivalent `db.printSecondaryReplicationInfo()` output identifies each member, when it last synchronized, and its replication lag. section 9.1.3 section 21.2.3

Listing 9.6 Output of the db.printSecondaryReplicationInfo() command
db.printSecondaryReplicationInfo()
source: ac-5dhjxpf-shard-00-00.fpomkke.mongodb.net:27017
{
  syncedTo: 'Wed Mar 27 2024 18:21:52 GMT+0000
➥(Coordinated Universal Time)',
  replLag: '0 secs (0 hrs) behind the primary '
}
---
source: ac-5dhjxpf-shard-00-01.fpomkke.mongodb.net:27017
{
  syncedTo: 'Wed Mar 27 2024 18:21:53 GMT+0000
➥(Coordinated Universal Time)',
  replLag: '10 secs (0 hrs) behind the primary '
}

The sample `db.printSecondaryReplicationInfo()` output shows one member at 0 seconds of lag and another 10 seconds behind the primary. Compare each member’s `replLag` when checking whether secondaries are keeping up. section 9.1.3

Lag matters when an application reads from secondaries: a lagging member may serve outdated data. The helper prints human-readable output rather than JSON; use `rs.status()` instead for automated scripts. Check oplog capacity separately when investigating whether a secondary can catch up after a pause. section 9.1.3 section 21.2.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Shows member-level output and explains lag’s operational meaning, but does not develop an automated monitoring procedure.
Examples
Uses mongosh output with one member at 0 seconds of lag and another 10 seconds behind the primary.
What it assumes
Assumes access to mongosh and a replica set; explains the oplog’s synchronization role without walking through setup.
What you can do after
Diagnose/debug with it by identifying lagging secondaries and judging whether secondary reads risk being outdated.
How it connects
Links replication lag to replica sets, primary and secondary members, oplog synchronization, and stale reads.

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.