定义
sh.status()在
mongos实例上运行时,打印分片配置的格式化报告以及有关分片集群中现有数据段的信息。如果数据段总数大于或等于 20,则默认行为将禁止显示详细的数据段信息。The
sh.status()method has the following parameter:Parameter类型说明verbose布尔
可选。确定详细级别。
如果
true,则该方法将显示:即使您有 20 个或更多数据段,也可以查看跨分片数据段分布的完整详情以及每个分片上的数据段个数。
活动 mongos 实例的详情。
如果
false,则该方法将显示:仅当数据段少于 20 个时,才会显示跨分片数据段分布的完整详情。如果有 20 个或更多数据段,该方法会返回
too many chunks to print ...消息,仅显示每个分片上的数据段个数。
默认的详细值为
false。输出还包括
shardedDataDistribution部分,其中提供了每个分片集合的数据分布指标。此数据与$shardedDataDistribution聚合阶段的输出相同。
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
M0 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
输出示例
--- Sharding Status --- sharding version: { "_id" : <num>, "minCompatibleVersion" : <num>, "currentVersion" : <num>, "clusterId" : <ObjectId> }
分片部分列出了有关分片的信息。对于每个分片,该部分显示名称、主机和关联的标记(如果有)。
shards: { "_id" : <shard name1>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> } { "_id" : <shard name2>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> } ...
mongos默认下,“活动mongos 实例”部分显示过去60 秒内处于活动状态的 实例的版本和数量信息:
active mongoses: <version> : <num>
If the method is run with the verbose parameter to true, the Active mongos Instances section displays additional information:
active mongoses: { "_id" : "<hostname:port>", "advisoryHostFQDNs" : [ "<name>" ], "mongoVersion" : <string>, "ping" : <ISODate>, "up" : <long>, "waiting" : <boolean> }
自动分割显示有关是否启用自动分割的信息:
autosplit: Currently enabled: <yes|no>
负载均衡器部分列出有关负载均衡器状态的信息。这可以深入了解当前负载均衡器的操作,在对不均衡的分片集群进行故障排除时非常有用。
balancer: Currently enabled: yes Currently running: yes Collections with active migrations: config.system.sessions started at Fri May 15 2020 17:38:12 GMT-0400 (EDT) Failed balancer rounds in last 5 attempts: 0 Migration Results for the last 24 hours: 416 : Success 1 : Failed with error 'aborted', from shardA to shardB
数据库部分列出了有关数据库的信息。它显示数据库名称和每个数据库的主分片。
databases: { "_id" : <dbname1>, "primary" : <string>, "version": <document> } { "_id" : <dbname2>, "primary" : <string>, "version": <document> } ...
分片集合部分提供有关分片的集合的分片详细信息。对于每个分片的集合,该部分显示分片键、每个分片的数据段数量、跨分片的数据段分布 []1 以及分片键范围的标签信息(如果有)。
<dbname>.<collection> shard key: { <shard key> : <1 or hashed> } unique: <boolean> balancing: <boolean> allowMigrations: <boolean> chunks: <shard name1> <number of chunks> <shard name2> <number of chunks> ... { <shard key>: <min range1> } -->> { <shard key> : <max range1> } on : <shard name> <last modified timestamp> { <shard key>: <min range2> } -->> { <shard key> : <max range2> } on : <shard name> <last modified timestamp> ... tag: <tag1> { <shard key> : <min range1> } -->> { <shard key> : <max range1> } ...
The Sharded Data Distribution section displays data distribution information for each sharded collection:
shardedDataDistribution: [ { "ns" : "<database>.<collection>", "shards" : [ { "shardName" : "<shard name>", "numOrphanedDocs" : <num>, "numOwnedDocuments" : <num>, "ownedSizeBytes" : <num>, "orphanedSizeBytes" : <num> } ] } ]
输出字段
分片版本
sh.status.sharding-version._idThe
_idis an identifier for the version details.
sh.status.sharding-version.minCompatibleVersionThe
minCompatibleVersionis the minimum compatible version of the config server.在比 6.2 更早的 MongoDB 版本中,该字段包含在
config.version集合中,但在mongosh2.0.0 及更高版本中,该字段不会在sh.status()输出中返回。从 MongoDB 6.2 开始,此字段已被删除,并且不会在任何mongosh版本或其他客户端应用程序中返回。如要获取版本信息,请参阅特征兼容性版本(fcv)。
sh.status.sharding-version.currentVersionThe
currentVersionis the current version of the config server.在比 6.2 更早的 MongoDB 版本中,该字段包含在
config.version集合中,但在mongosh2.0.0 及更高版本中,该字段不会在sh.status()输出中返回。从 MongoDB 6.2 开始,此字段已被删除,并且不会在任何mongosh版本或其他客户端应用程序中返回。如要获取版本信息,请参阅特征兼容性版本(fcv)。
sh.status.sharding-version.clusterIdThe
clusterIdis the identification for the sharded cluster.
活动 mongos 实例
sh.status.active-mongoses如果
verbose为false,sh.status.active-mongoses会列出活动mongos实例的版本和数量。活动mongos实例是指在过去mongos60秒内 ping 通的 个实例。If
verboseistrue,sh.status.active-mongosesreturns a document for each activemongosinstance containing the following fields:字段数据类型说明_id字符串
运行
mongos的主机名和端口。_id的格式为<hostname>:<port>。advisoryHostFQDNs字符串数组
mongos的完全限定域名(FQDN)的数组。createdDate
当
mongos启动时。5.2版本新增。
mongoVersion字符串
正在运行
mongos的 MongoDB 版本。pingDate
upNumberLong
截至上次 ping 时
mongos已启动的秒数。waiting布尔
此字段始终为
true,并且仅为向后兼容而包含。active mongoses: { "_id" : "<hostname:port>", "advisoryHostFQDNs" : [ "<name>" ], "created" : <ISODate>, "mongoVersion" : <string>, "ping" : <ISODate>, "up" : <long>, "waiting" : <boolean> } ...
Autosplit
sh.status.autosplitsh.status.autosplit指示当前是否启用自动分割。
注意
从 MongoDB 6.0.3 开始,不再执行自动数据块分割。这是因为均衡策略的改进。自动分割命令仍然存在,但不执行操作。
在 MongoDB 6.1 以前的版本中:
balancerStart命令以及mongoShell 助手方法sh.startBalancer()和sh.setBalancerState(true)还会启用分片集群自动分割。要在启用负载均衡器时禁用自动分割,可以使用
sh.disableAutoSplit()。balancerStop命令以及mongoShell 助手方法sh.stopBalancer()和sh.setBalancerState(false)还会禁用分片集群自动分割。要在禁用负载均衡器时启用自动分割,可以使用
sh.enableAutoSplit()。
mongo 方法 sh.enableBalancing(namespace) 和 sh.disableBalancing(namespace) 对自动分割没有影响。
自动合并
sh.status.automerge指示是否启用自动合并功能。
注意
只有明确启用或禁用自动合并功能时,才会显示
automerge部分。默认情况下,自动合并是启用的。
分片
sh.status.shards._idThe
_iddisplays the name of the shard.
sh.status.shards.hostThe
hostdisplays the host location of the shard.
sh.status.shards.tagsThe
tagsdisplays all the tags for the shard. The field only displays if the shard has tags.
sh.status.shards.stateThe
statedisplays:0如果该分片不具备分片感知性。1如果该分片具备分片感知性。
平衡器
注意
从 MongoDB 6.0.3 开始,不再执行自动数据块分割。这是因为均衡策略的改进。自动分割命令仍然存在,但不执行操作。
在 MongoDB 6.1 以前的版本中:
balancerStart命令以及mongoShell 助手方法sh.startBalancer()和sh.setBalancerState(true)还会启用分片集群自动分割。要在启用负载均衡器时禁用自动分割,可以使用
sh.disableAutoSplit()。balancerStop命令以及mongoShell 助手方法sh.stopBalancer()和sh.setBalancerState(false)还会禁用分片集群自动分割。要在禁用负载均衡器时启用自动分割,可以使用
sh.enableAutoSplit()。
mongo 方法 sh.enableBalancing(namespace) 和 sh.disableBalancing(namespace) 对自动分割没有影响。
sh.status.balancer.currently-enabledcurrently-enabledindicates if the balancer is currently enabled on the sharded cluster.
sh.status.balancer.currently-runningcurrently-runningindicates whether the balancer is currently running, and therefore currently balancing the cluster.
sh.status.balancer.collections-with-active-migrationscollections-with-active-migrationslists the names of any collections with active migrations, and specifies when the migration began. If there are no active migrations, this field will not appear in thesh.status()output.
sh.status.balancer.failed-balancer-rounds-in-last-5-attemptsfailed-balancer-rounds-in-last-5-attemptsdisplays the number of balancer rounds that failed, from among the last five attempted rounds. A balancer round will fail when a chunk migration fails.
sh.status.balancer.last-reported-errorlast-reported-errorlists the most recent balancer error message. If there have been no errors, this field will not appear in thesh.status()output.
sh.status.balancer.time-of-reported-errortime-of-reported-error提供最近所报告错误的日期和时间。
sh.status.balancer.migration-results-for-the-last-24-hoursmigration-results-for-the-last-24-hours显示过去24 小时内的迁移次数,以及失败迁移的错误消息。如果最近没有迁移,migration-results-for-the-last-24-hours将显示No recent migrations。migration-results-for-the-last-24-hoursincludes all migrations, including those not initiated by the balancer.
Databases
sh.status.databases._idThe
_iddisplays the name of the database.
sh.status.databases.primaryThe
primarydisplays the primary shard for the database.
sh.status.databases.versionThe
versiondisplays the version information for the database:{ "uuid" : UUID("cc250b66-8638-49f7-a2e8-c6f1220b9d7a"), "lastMod" : 1 } 其中:
uuid是数据库标识符。lastMod是数据库版本。
分片集合
sh.status.databases.<collection>.shard-keyThe
shard-keydisplays the shard key specification document.
sh.status.databases.<collection>.uniqueThe
uniquedisplays whether MongoDB enforces uniqueness on the shard key values (i.e. whether the underlying shard key index is unique).
sh.status.databases.<collection>.balancing显示负载均衡器是否可以对集合进行负载均衡。 如果负载均衡器已启用并且此状态返回
true,则负载均衡器会在负载均衡操作中包含此集合。 如果状态返回false,则表示负载均衡器器未平衡此集合中的数据。
sh.status.databases.<collection>.allowMigrations显示是否允许对集合进行迁移。当
true时,集合允许迁移。当false时,集合不允许迁移,从而阻止此集合的数据块迁移。使用sh.enableMigrations()和sh.disableMigrations()控制此设置。
sh.status.databases.<collection>.chunksThe
chunkslists all the shards and the number of chunks that reside on each shard.
sh.status.databases.<collection>.chunk-detailschunk-details列出数据段 []1 的详细信息:定义该数据段的分片键值的范围,
该数据段所在的分片,以及
该数据段的最后修改时间戳。
sh.status.databases.<collection>.tagThe
taglists the details of the tags associated with a range of shard key values.
分片数据分布
sh.status.shardedDataDistribution一个文档数组,为集群中的每个分片集合提供数据分布指标。该数据与
$shardedDataDistribution聚合阶段的输出相同。
| [1] | (1 ,2 )默认下,如果数据段总数小于 20,分片的集合部分会显示数据块信息。要在有20 个或更多数据段时显示信息,请调用sh.status() verbosetrue方法,并将 参数设立为 ,即sh.status(true) 。 |