DBAtlas · Database operations atlas

Resync a member from scratch

MongoDBReplica Set

Command

// On the SECONDARY to be resynced (NEVER on the PRIMARY):
db.getSiblingDB("admin").shutdownServer()
// At the OS level: empty the dbPath contents (or move them elsewhere as a backup)
// and restart mongod with the same configuration; the member starts an initial sync automatically.
// Monitor progress (stateStr: STARTUP2 -> SECONDARY):
rs.status()

What it does

MongoDB has no separate resync command; stopping the secondary, emptying its data directory and restarting it starts a new initial sync from the primary (or a sync source).

When to use it

When a member falls so far behind that it drops outside the oplog window (RECOVERING / too stale) or its data becomes inconsistent.

Caution

All local data on the member is deleted and re-pulled; do this only on a secondary and make sure the majority stays up. Sync time and network/disk load are high; for very large data sets, seeding from a file system snapshot of a healthy member is faster.

Open in DBAtlas →

Related