進行中のインデックス構築を監視・中止する
MongoDBメンテナンスコマンド
// Index builds in progress and their completion percentage:
db.getSiblingDB("admin").aggregate([
{ $currentOp: { allUsers: true } },
{ $match: { $or: [{ "command.createIndexes": { $exists: true } }, { desc: /^IndexBuildsCoordinator/ }] } },
{ $project: { opid: 1, desc: 1, ns: 1, secs_running: 1, msg: 1, progress: 1, "command.indexes.name": 1 } }
])
// Abort the build (on the primary; in a replica set it stops on all members):
db.musteri.dropIndex("idx_email")概要
実行中のインデックス構築を、スキャン済みドキュメント数と進捗率 (progress.done / progress.total) とともに一覧表示する。必要に応じて dropIndex で構築を中止する。
使用する場面
大きなコレクションで開始した createIndex がいつ終わるかを見積もる場合、またはピーク時に負荷を生じている構築を停止する場合。
注意
インデックス構築の中止には killOp ではなく dropIndex/dropIndexes を使用する。レプリカセットではプライマリで実行し、中止がすべてのメンバーに伝播するようにする。構築中、コレクションに対する一部の DDL 操作は待機する。構築の最後に短時間の排他ロックが取得され、非常に書き込みが多い状況ではその瞬間にレイテンシが生じることがある。