FULL AI ANALYSIS

MongoDB index build on primary causes secondaries to fall behind as oplog wraps

Generated Oct 3, 2026, 12:35:03 AM

Analysis summary

A large index build on the primary generated a substantial volume of replication operations that exceeded the duration of the configured oplog window on secondaries. When the oplog no longer contains the earliest needed operations, a secondary cannot catch up and requires resynchronization. In MongoDB 4.4, some index builds are replicated as operations that secondaries must apply; resource starvation (CPU, I/O) on secondaries worsens the situation. The root issues are insufficient oplog retention for the size/duration of the operation and resource saturation on secondaries.

Possible causes

Oplog size too small relative to volume of operations and index build duration.

95%

Index build type/flags cause a heavy stream of replicated writes (rather than an in-place build on secondaries).

90%

Index build performed on primary when it would have been safer to build on a secondary that can be resynced or stepped down.

80%

Secondaries under-provisioned (CPU/disk) and cannot apply operations fast enough.

75%

Suggested fixes

1

Diagnostic step 1

If index build is still running and cluster is degraded, stop accepting writes from the application if possible to let secondaries catch up. This is reversible and limits data churn.

2

Diagnostic step 2

Add temporary capacity: bring up an additional secondary (with a larger oplog) to act as a catch-up node or to run the index build there. This avoids impacting existing secondaries.

3

Diagnostic step 3

Consider building the index on a secondary by taking it offline (stop mongod), starting mongod in standalone mode against the data copy, create the index there, then reintroduce it to the set as a secondary so it will replicate less. This requires careful orchestration and backup.

4

Diagnostic step 4

Preemptively increase oplog size on a node before heavy operations (requires planning — create a new larger oplog member and replace an existing one if you cannot resize in-place). Monitor oplog window with rs.printReplicationInfo().

5

Diagnostic step 5

For future maintenance, schedule index builds during a full application quiesce window or perform rolling index builds using newer MongoDB features or by building on secondaries then stepping them up if supported. Escalate to DBA or hosting provider if you cannot provision additional disk or cannot safely resync members.