説明
db.killOp(opid)操作 ID で指定された操作を終了します。操作とそれに対応する ID を見つけるには、
$currentOpまたはdb.currentOp()を参照してください。The
db.killOp()method has the following parameter:Parameterタイプ説明op数値
操作 ID。
警告
Terminate running operations with extreme caution. Only use
db.killOp()to terminate operations initiated by clients and do not terminate internal database operations.
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
重要
MongoDB Atlas limits the use of this method to the MongoDB user who ran the operation. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
シャーディングされたクラスター
読み取り操作の強制終了
The db.killOp() method can be run on a mongos and can kill queries (read operations) that are running on more than one shard in a cluster.
たとえば、シャーディングされたクラスターでクエリ操作を強制終了するには、次のようにします。
クライアントがクエリを発行したのと同じ
mongosで、次のlocalOps: trueで集計パイプライン$currentOpを実行し、強制終了するクエリ操作の opid を見つけます。use admin db.aggregate( [ { $currentOp : { allUsers: true, localOps: true } }, { $match : <filter condition> } // Optional. Specify the condition to find the op. // e.g. { op: "getmore", "command.collection": "someCollection" } ] ) 重要
この集計操作は、クライアントがクエリを発行したのと同じ
mongosで発行する必要があります。Once you find the query operation to kill, issue
db.killOp()with the opid on themongos:db.killOp(<opid of the query to kill>)
Tip
$currentOp内のlocalOpsパラメータ。
または、操作を実行中のシャード ノードから読み取り操作を見つけて強制終了することもできます。MongoDB は、強制終了操作を他のシャードと mongos インスタンスに伝達します。
操作が実行中のシャードの 1 つで、強制終了するクエリ操作の opid を見つけます。
use admin db.aggregate( [ { $currentOp : { allUsers: true } }, { $match : <filter condition> } // Optional. Specify the condition to find the op. // e.g. { op: "getmore", "command.collection": "someCollection" } ] ) Once you find the query operation to kill, issue
db.killOp()with the opid on the shard member:db.killOp(<opid of the query to kill>) MongoDB は、強制終了操作を他のシャードと
mongosインスタンスに伝達します。
書き込み操作の強制終了
- セッション内
MongoDB ドライバーは、確認されていない書き込みを除くすべての操作をサーバー セッションに関連付けます。
書き込み操作がセッションに関連付けられている場合、
mongosのkillSessionsコマンドを使用して、シャード全体の書き込み操作を強制終了できます。mongosで集計パイプライン$currentOpを実行して、lsid(論理セッション ID)を見つけます。use admin db.aggregate( [ { $currentOp : { allUsers: true, localOps: true } }, { $match : <filter condition> } // Optional. Specify the condition to find the op. // e.g. { "op" : "update", "ns": "mydb.someCollection" } ] ) 返された
lsid情報を使用して、mongosでkillSessionsコマンドを発行し、シャードに対する操作を強制終了します。db.adminCommand( { killSessions: [ { "id" : UUID("80e48c5a-f7fb-4541-8ac0-9e3a1ed224a4"), "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=") } ] } )
- セッションなし
書き込み操作がセッションに関連付けられていない場合は、書き込みに関連するすべてのシャードで操作を見つけて強制終了する必要があります。
mongosから、集計パイプライン$currentOpを実行して、シャード上のクエリ操作の opid を見つけます。use admin db.aggregate( [ { $currentOp : { allUsers: true } }, { $match : <filter condition> } // Optional. Specify the condition to find the op. ] ) mongosで実行すると、$currentOpは opids を"<shardName>:<opid on that shard>"の形式で返します。例:{ "shard" : "shardB", .. "opid" : "shardB:79214", ... }, { "shard" : "shardA", .. "opid" : "shardA:100913", ... }, Using the opid information, issue
db.killOp()on themongosto kill the operation on the shards.db.killOp("shardB:79014"); db.killOp("shardA:100813");
アクセス制御
authorization で実行されているシステムでは、ユーザー自身のものでない操作を強制終了するには、ユーザーに killop 特権アクションを含むアクセス権が必要です。
mongod インスタンスでは、ユーザーは killop 特権アクションがなくても自分の操作を強制終了できます。
Tip