AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

deleteShard(データベースコマンド)

removeShard

シャーディングされたクラスターからシャードを削除します。removeShard を実行すると、 MongoDB はバランサーを使用してシャードのチャンクをクラスター内の他のシャードに移動し、シャードを空にします。

注意

removeShard が完了するには、バランサーを有効にする必要があります。バランサーが無効になっている場合、すべてのデータをシャードからすでに移動している場合でも、 コマンドはドレイン状態のままになり、終了しません。

シャードにシャーディングされていないコレクションがある場合は、シャーディングされていないコレクションをすべてシャードからドレイニングする必要があります。MongoDB 8.0 以降では、sh.moveCollection() を使用してシャーディングされていないコレクションを移動できます。シャードを空にする手順の詳細については、 シャードクラスタからシャードを削除する を参照してください。

シャードが空になると、 MongoDB はクラスターからシャードを削除します。

注意

削除された シャードstorage.dbPath をシャーディングされたクラスターに再度追加する場合は、再追加する前に、シャードのすべてのノードの をクリアして、シャードの ファイルを削除する必要があります。

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

注意

このコマンドはMongoDB Atlasではサポートされていません。Atlas クラスターからシャードを追加または削除するには、「Atlasシャードクラスタの変更」を参照してください。

このコマンドの構文は、次のとおりです。

db.adminCommand(
{
removeShard : <shardToRemove>
}
)

シャードの削除中は、 クラスター データをバックアップできません。

You can have more than one removeShard operation in progress.

authorizationを有効にしている場合は、 clusterManagerロールまたはremoveShardアクションを含む任意のロールが必要です。

シャーディングされたシャーディングされたクラスターの各データベースにはプライマリシャードがあります。 削除するシャードがクラスターのデータベースの 1 つのプライマリでもある場合は、シャードからすべてのデータを移行した後、データベースを新しいシャードに手動で移動する必要があります。 詳細については、 movePrimaryコマンドとシャーディングされたシャードクラスタからシャードを削除するを参照してください。

チャンクの分布が不均一なクラスター内のシャードを削除すると、バランサーはまずドレイン シャードからチャンクを削除し、次に残りの不均一なチャンクの分布のバランスをとります。

mongos converts the write concern of the removeShard command to "majority".

シャードを削除すると、開いている変更ストリームのカーソルが閉じてしまい、閉じた変更ストリームのカーソルが完全に再開できなくなることがあります。

クラスターが DDL操作( reshardCollectionなどのコレクションを変更する操作)を実行しているときにremoveShardを実行すると、 removeShardは同時 DDL操作が完了した後にのみ実行されます。

From mongosh, the removeShard operation resembles the following:

db.adminCommand( { removeShard : "bristol01" } )

Replace bristol01 with the name of the shard to remove. When you run removeShard, the command returns with a message that resembles the following:

{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "bristol01",
"note" : "you need to call moveCollection for collectionsToMove and afterwards movePrimary for the dbsToMove",
"dbsToMove" : [
"fizz",
"buzz"
],
"collectionsToMove" : [
"fizz.coll1",
"buzz.coll1"
],
"ok" : 1,
"operationTime" : Timestamp(1575398919, 2),
"$clusterTime" : {
"clusterTime" : Timestamp(1575398919, 2),
"signature" : {
"hash" : BinData(0,"Oi68poWCFCA7b9kyhIcg+TzaGiA="),
"keyId" : Long("6766255701040824328")
}
}
}

The balancer begins migrating ("draining") chunks from the shard named bristol01 to other shards in the cluster. These migrations happen slowly to avoid placing undue load on the cluster.

If you run the command again, removeShard returns the current status of the process. For example, if the operation is in an ongoing state, the command returns an output that resembles the following:

{
"msg" : "draining ongoing",
"state" : "ongoing",
"remaining" : {
"chunks" : NumberLong(2),
"dbs" : NumberLong(2),
"jumboChunks" : NumberLong(0),
"collectionsToMove": NumberLong(2)
},
"note" : "you need to call moveCollection for collectionsToMove and afterwards movePrimary for the dbsToMove",
"dbsToMove" : [
"fizz",
"buzz"
],
"collectionsToMove" : [
"fizz.coll1",
"buzz.coll1"
],
"ok" : 1,
"operationTime" : Timestamp(1575399086, 1655),
"$clusterTime" : {
"clusterTime" : Timestamp(1575399086, 1655),
"signature" : {
"hash" : BinData(0,"XBrTmjMMe82fUtVLRm13GBVtRE8="),
"keyId" : Long("6766255701040824328")
}
}
}

出力では、 remainingフィールドには次のフィールドが含まれます。

フィールド
説明

chunks

現在シャードに残っているチャンクの合計数。

dbs

プライマリ シャードがシャードであるデータベースの合計数。 これらのデータベースはdbsToMove出力フィールドで指定されます。

jumboChunks

chunksの合計数のうち、ジャンボである数値。

jumboChunks が 0 より大きい場合は、jumboChunks のみがシャード上に残るまで待ちます。ジャンボチャンクのみが残ったら、ドレインが完了する前にジャンボフラグを手動でクリアする必要があります。「 ジャンボフラグのクリア を参照してください。

jumboフラグがクリアされると、バランサーはこれらのチャンクを移行できます。 移行手順の詳細については、「範囲の移行手順 」を参照してください。

collectionsToMove

シャードから移動する必要がある、シャーディングされていないコレクションの総数。

When you run transitionToDedicatedConfigServer, the removeShard output may include the following fields. These fields appear only after the balancer has moved all chunks and databases off the config server:

フィールド
説明

pendingRangeDeletions

削除中のシャードに残っている保留中の範囲削除の数。

firstNonEmptyCollection

削除対象のシャード上の最初の空でないコレクション。

Continue checking the status of the removeShard command (that is, rerun the command) until the number of chunks remaining is 0.

{
"msg" : "draining ongoing",
"state" : "ongoing",
"remaining" : {
"chunks" : NumberLong(0), // All chunks have moved
"dbs" : NumberLong(2),
"jumboChunks" : NumberLong(0),
"collectionsToMove": NumberLong(2)
},
"note" : "you need to call moveCollection for collectionsToMove and afterwards movePrimary for the dbsToMove",
"dbsToMove" : [
"fizz",
"buzz"
],
"collectionsToMove" : [
"fizz.coll1",
"buzz.coll1"
],
"ok" : 1,
"operationTime" : Timestamp(1575400343, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1575400343, 1),
"signature" : {
"hash" : BinData(0,"9plu5B/hw4uWAgEmjjBP3syw1Zk="),
"keyId" : Long("6766255701040824328")
}
}
}

バランサーがシャードからすべてのチャンクをドレインした後、ドレインされたシャードからコレクションとデータベースを手動で移動する必要がある場合があります。

の出力にremoveShard フィールドのコレクションが含まれている場合は、collectionsToMove moveCollectionを使用してそれらのコレクションをドレインシャード以外のシャードに移動するか、コレクションを削除します(関連するデータファイルが削除されます)。

removeShard の出力に dbsToMoveフィールドのデータベースが含まれている場合は、それらのデータベースに movePrimary を使用するか、データベースを削除します(関連するデータファイルを削除します)。

注意

最高のパフォーマンスを得るには、データベースを移動する前にコレクションを移動してください。

After the balancer completes moving all chunks off the shard and you have handled the dbsToMove and collectionsToMove, removeShard can finish. Running removeShard again returns output that resembles the following:

{
"msg" : "removeshard completed successfully",
"state" : "completed",
"shard" : "bristol01",
"ok" : 1,
"operationTime" : Timestamp(1575400370, 2),
"$clusterTime" : {
"clusterTime" : Timestamp(1575400370, 2),
"signature" : {
"hash" : BinData(0,"JjSRciHECXDBXo0e5nJv9mdRG8M="),
"keyId" : Long("6766255701040824328")
}
}
}
このページを評価