Initial sync brings a new or empty MongoDB replica-set member toward the set’s current data state by copying existing data and applying subsequent operations. While it runs, the member is in STARTUP2 and cannot vote; it has not yet become a functioning secondary. section 9.1.1
Check the member and the operations it needs to catch up:
- In mongosh, run db.adminCommand("replSetGetStatus") or rs.status() and inspect the member’s state. STARTUP2 means initial sync is running. section 9.1.1
- Check the oplog window with db.getReplicationInfo(). It must be long enough to retain operations generated during logical initial sync until the member can apply them; otherwise, needed entries may be removed. section 9.1.3
- If retention needs adjustment, consider oplog size and minimum retention time. An existing member’s oplog can be resized with replSetResizeOplog without restarting mongod. section 9.1.3
MongoDB 6.0 and later offers logical initial sync and, in MongoDB Enterprise, file-based initial sync designed for data sets of 1 TB or more. After a failure such as losing access to needed oplog entries or a transient network problem, sync can resume within a default 24-hour window for logical sync or 10-minute window for file-based sync. mongod parameters can change those windows. section 9.1.3
Table 9.1 Possible state of each member of a replica set
| Number |
Name |
Description |
| 0 |
|
Initial state. Parses config document. |
| 1 |
|
Accepts writes. Eligible to vote. |
| 2 |
|
Replicates data. Eligible to vote. |
| 3 |
|
In self-checks, rollback, or resync. No reads. Votes. |
| 4 |
|
Running initial sync. Can’t vote. |
| 5 |
|
State not known by others. |
| 6 |
|
Only votes. Doesn’t replicate data. |
| 7 |
|
Unreachable by others. |
| 8 |
|
Performing a rollback. No reads. Votes. |
| 9 |
|
Was part of a set, now removed. |
Compare STARTUP2 with SECONDARY, RECOVERING, and other member states when interpreting replica-set status. section 9.1.1
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 the reported oplog time span to assess whether operations are retained long enough for a syncing member. section 9.1.3
