Skip to content

DOCS-2489 clarify that removeShard is run on admin db #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions source/reference/command/removeShard.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,71 @@ removeShard

.. dbcommand:: removeShard

Starts the process of removing a shard from a :term:`cluster
<sharded cluster>`. This
is a multi-stage process. Begin by issuing the following command:
Removes a shard from a :term:`sharded cluster`. When you run
:dbcommand:`removeShard`, MongoDB first moves the shard's chunks to
other shards in the cluster. Then MongoDB removes the shard.

To run the command you must have administrative access. Either run
:dbcommand:`removeShard` from the admin database or run it with the
:method:`sh._adminCommand` command.

The command takes the following form:

.. code-block:: javascript

{ removeShard : "[shardName]" }
use admin
db.runCommand( { removeShard : "<shardName>" } )

The balancer will then migrate chunks from the shard specified by
``[shardName]``. This process happens slowly to avoid placing
undue load on the overall cluster.
Behavior
--------

The command returns immediately, with the following message:
When you run :dbcommand:`removeShard`, the command returns immediately,
with the following message:

.. code-block:: javascript
.. code-block:: javascript

{ msg : "draining started successfully" , state: "started" , shard: "shardName" , ok : 1 }
{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "bristol01",
"ok" : 1
}

If you run the command again, you'll see the following progress
output:
The balancer migrates chunks from shard ``bristol01``.
This process happens slowly to avoid placing undue load on the overall
cluster.

.. code-block:: javascript
If you run the command again, you'll see the following progress output:

{ msg: "draining ongoing" , state: "ongoing" , remaining: { chunks: 23 , dbs: 1 }, ok: 1 }
.. code-block:: javascript

The ``remaining`` :term:`document` specifies how many chunks and
databases remain on the shard. Use :method:`db.printShardingStatus()`
to list the databases that you must move from the shard.
{
"msg" : "draining ongoing",
"state" : "ongoing",
"remaining" : {
"chunks" : 23,
"dbs" : 1
},
"ok" : 1
}

Each database in a sharded cluster has a primary shard. If the
shard you want to remove is also the primary of one of the cluster's
databases, then you must manually move the database to a new
shard. This can be only after the shard is empty. See the
:dbcommand:`movePrimary` command for details.
The ``remaining`` :term:`document` specifies how many chunks and databases
remain on the shard. Use :method:`db.printShardingStatus()` to list the
databases that you must move from the shard.

After removing all chunks and databases from the shard, you
may issue the command again, to return:
Each database in a sharded cluster has a primary shard. If the shard you
want to remove is also the primary of one of the cluster's databases, then
you must manually move the database to a new shard. This can be done only
after the shard is empty. See the :dbcommand:`movePrimary` command for details.

.. code-block:: javascript
After removing all chunks and databases from the shard, if you issue the
command again it returns:

.. code-block:: javascript

{ msg: "remove shard completed successfully", state: "completed", host: "shardName", ok : 1 }
{
"msg" : "removeshard completed successfully",
"state" : "completed",
"shard" : "bristol01",
"ok" : 1
}
39 changes: 32 additions & 7 deletions source/tutorial/remove-shards-from-cluster.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,26 @@ The ``shards._id`` field lists the name of each shard.
Remove Chunks from the Shard
----------------------------

Run the :dbcommand:`removeShard` command. This begins "draining" chunks
From the ``admin`` database, run the :dbcommand:`removeShard` command.
This begins "draining" chunks
from the shard you are removing to other shards in the cluster. For
example, for a shard named ``mongodb0``, run:

.. code-block:: javascript

use admin
db.runCommand( { removeShard: "mongodb0" } )

This operation returns immediately, with the following response:

.. code-block:: javascript

{ msg : "draining started successfully" , state: "started" , shard :"mongodb0" , ok : 1 }
{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "mongodb0",
"ok" : 1
}

Depending on your network capacity and the amount of data, this
operation can take from a few minutes to several days to complete.
Expand All @@ -83,24 +90,36 @@ Check the Status of the Migration
---------------------------------

To check the progress of the migration at any stage in the process, run
:dbcommand:`removeShard`. For example, for a shard named ``mongodb0``, run:
:dbcommand:`removeShard` from the ``admin`` database again. For example,
for a shard named ``mongodb0``, run:

.. code-block:: javascript

use admin
db.runCommand( { removeShard: "mongodb0" } )

The command returns output similar to the following:

.. code-block:: javascript

{ msg: "draining ongoing" , state: "ongoing" , remaining: { chunks: NumberLong(42), dbs : NumberLong(1) }, ok: 1 }
{
"msg" : "draining ongoing",
"state" : "ongoing",
"remaining" : {
"chunks" : 42,
"dbs" : 1
},
"ok" : 1
}

In the output, the ``remaining`` document displays the remaining number
of chunks that MongoDB must migrate to other shards and the number of
MongoDB databases that have "primary" status on this shard.

Continue checking the status of the `removeShard` command until the
number of chunks remaining is ``0``. Then proceed to the next step.
number of chunks remaining is ``0``. Always run the command on the
``admin`` database. If you are on a database other than ``admin``, you can
use :method:`sh._adminCommand` to run the command on ``admin``.

.. _remove-shard-move-unsharded-databases:

Expand Down Expand Up @@ -165,13 +184,19 @@ To clean up all metadata information and finalize the removal, run

.. code-block:: javascript

use admin
db.runCommand( { removeShard: "mongodb0" } )

A success message appears at completion:

.. code-block:: javascript

{ msg: "remove shard completed successfully" , state: "completed", host: "mongodb0", ok : 1 }
{
"msg" : "removeshard completed successfully",
"state" : "completed",
"shard" : "mongodb0",
"ok" : 1
}

Once the value of the ``stage`` field is "completed", you may safely
Once the value of the ``state`` field is "completed", you may safely
stop the processes comprising the ``mongodb0`` shard.