从头重新同步成员
MongoDB副本集命令
// 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()作用
MongoDB 没有单独的 resync 命令;停止 secondary、清空其数据目录并重启,即可从 primary(或同步源)开始新的初始同步。
适用场景
成员落后过多以至超出 oplog 窗口(RECOVERING / too stale)或其数据不一致时。
注意
该成员上的所有本地数据都会被删除并重新拉取;只在 secondary 上执行,并确保多数派保持在线。同步时间以及网络/磁盘负载都很高;对于超大数据集,从健康成员的文件系统快照做种更快。