Chapter 16. Sharding Administration
A sharded cluster is the most difficult type of deployment to administer. This chapter gives advice on performing administrative tasks on all parts of a cluster, including:
Inspecting what the cluster’s state is: who its members are, where data is held, and what connections are open
How to add, remove, and change members of a cluster
Administering data movement and manually moving data
Seeing the Current State
There are several helpers available to find out what data is where, what the shards are, and what the cluster is doing.
Getting a Summary with sh.status
sh.status()
gives you an
overview of your shards, databases, and sharded collections. If you have
a small number of chunks, it will print a breakdown of which chunks are
where as well. Otherwise it will simply give the collection’s shard key
and how many chunks each shard has:
>
sh
.
status
()
---
Sharding
Status
---
sharding
version
:
{
"_id"
:
1
,
"version"
:
3
}
shards
:
{
"_id"
:
"shard0000"
,
"host"
:
"localhost:30000"
,
"tags"
:
[
"USPS"
,
"Apple"
]
}
{
"_id"
:
"shard0001"
,
"host"
:
"localhost:30001"
}
{
"_id"
:
"shard0002"
,
"host"
:
"localhost:30002"
,
"tags"
:
[
"Apple"
]
}
databases
:
{
"_id"
:
"admin"
,
"partitioned"
:
false
,
"primary"
:
"config"
}
{
"_id"
:
"test"
,
"partitioned"
:
true
,
"primary"
:
"shard0001"
}
test
.
foo
shard
key
:
{
"x"
:
1
,
"y"
:
1
}
chunks
:
shard0000
4
shard0002
4
shard0001
4
{
"x"
:
{
$minKey
:
1
},
"y"
:
{
$minKey
:
1
}
}
-->>
{
"x"
:
0
,
"y"
:
10000
}
on
:
shard0000
{
"x"
Get MongoDB: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.