定义
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: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
输出示例
The Sharding Version section displays information on the config database:
--- Sharding Status --- sharding version: { "_id" : <num>, "minCompatibleVersion" : <num>, "currentVersion" : <num>, "clusterId" : <ObjectId> }
The Shards section lists information on the shard(s). For each shard, the section displays the name, host, and the associated tags, if any.
shards: { "_id" : <shard name1>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> } { "_id" : <shard name2>, "host" : <string>, "tags" : [ <string> ... ], "state" : <num> } ...
The Active mongos Instances section displays, by default, information on the version and count of mongos instances that have been active within the last 60 seconds:
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>
The Balancer section lists information about the state of the balancer. This provides insight into current balancer operation and can be useful when troubleshooting an unbalanced sharded cluster.
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
The Databases section lists information on the database(s). It displays the database name and the primary shard for each database.
databases: { "_id" : <dbname1>, "primary" : <string>, "partitioned" : <boolean>, "version": <document> } { "_id" : <dbname2>, "primary" : <string>, "partitioned" : <boolean>, "version": <document> } ...
The Sharded Collection section provides information on the sharding details for sharded collection(s). For each sharded collection, the section displays the shard key, the number of chunks per shard(s), the distribution of chunks across shards [1], and the tag information, if any, for shard key range(s).
<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-mongosesIf
verboseisfalse,sh.status.active-mongoseslists the version and count of the activemongosinstances. Activemongosinstances aremongosinstances that have been pinged within the last 60 seconds.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-hoursdisplays the number of migrations in the last 24 hours, and the error messages from failed migrations . If there have been no recent migrations,migration-results-for-the-last-24-hoursdisplaysNo 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.partitioned从 MongoDB 6.0 和特性兼容性版本 (FcV) 6.0 开始,
partitioned标志仅保持与先前版本的向后兼容性。默认情况下,无论partitioned值如何,所有数据库都启用分片。
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-detailsThe
chunk-detailslists the details of the chunks [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) The sharded collection section, by default, displays the chunk information if the total number of chunks is less than 20. To display the information when you have 20 or more chunks, call the sh.status() methods with the verbose parameter set to true, i.e. sh.status(true). |