Docs HomeMongoDB Manual

sh.status()

Definition定义

sh.status()

When run on a mongos instance, prints a formatted report of the sharding configuration and the information regarding existing chunks in a sharded cluster. 当在mongos实例上运行时,会打印一份格式化的分片配置报告和关于分片集群中现有块的信息。The default behavior suppresses the detailed chunk information if the total number of chunks is greater than or equal to 20.如果块的总数大于或等于20,则默认行为抑制详细的块信息。

The sh.status() method has the following parameter:sh.status()方法具有以下参数:

Parameter参数Type类型Description描述
verbosebooleanOptional.可选的。Determines the level of verbosity.确定详细程度。
If true, the method displays: 如果为true,则该方法显示:
  • Full details of the chunk distribution across shards even if you have 20 or more chunks, as well as the number of chunks on each shard.即使你有20个或20个以上的区块,区块在分片之间分布的完整细节,以及每个分片上的区块数量。
  • Details of active mongos instances.活动mongos实例的详细信息。
If false, the method displays: 如果为false,则该方法显示:
  • Full details of the chunk distribution across shards only if you have less than 20 chunks. 只有当你拥有少于20个区块时,区块在分片之间分布的完整细节。If you have 20 or more chunks, the method instead returns a too many chunks to print ... message, showing only the number of chunks on each shard.如果你有20个或更多的块,该方法会返回too many chunks to print ...消息,只显示每个分片上的块数。
  • Only the version and number of active mongos instances.活动mongos实例的版本和数量
The default verbose value is false. 默认的详细值为false
Tip

See also: 另请参阅:

db.printShardingStatus()

Output Examples输出示例

The Sharding Version section displays information on the config database:分片版本部分显示有关config数据库的信息:

--- 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:默认情况下,活动mongos实例部分显示过去60秒内处于活动状态的mongos实例的版本和数量信息:

active mongoses:
<version> : <num>

If the method is run with the verbose parameter to true, the Active mongos Instances section displays additional information:如果在verbose参数为true的情况下运行该方法,则活动mongos实例部分将显示其他信息:

active mongoses:
{ "_id" : "<hostname:port>", "advisoryHostFQDNs" : [ "<name>" ], "mongoVersion" : <string>, "ping" : <ISODate>, "up" : <long>, "waiting" : <boolean> }

The Autosplit displays information on whether autosplit is enabled:Autosplit显示有关是否启用自动拆分的信息:

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).对于每个分片集合,该部分显示分片键、每个分片的块数、分片之间的块分布[1]以及分片键范围的标记信息(如果有的话)。

<dbname>.<collection>
shard key: { <shard key> : <1 or hashed> }
unique: <boolean>
balancing: <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> }
...

Output Fields输出字段

Sharding Version分片版本

sh.status.sharding-version._id

The _id is an identifier for the version details._id是版本详细信息的标识符。

sh.status.sharding-version.minCompatibleVersion

The minCompatibleVersion is the minimum compatible version of the config server.minCompatibleVersion是配置服务器的最低兼容版本。

In MongoDB versions earlier than 6.2, this field is included in the config.version collection, but in mongosh 2.0.0 and later, the field is not returned in the sh.status() output. 在低于6.2的MongoDB版本中,此字段包含在config.version集合中,但在mongosh 2.0.0及更高版本中,该字段不会在sh.status()输出中返回。Starting in MongoDB 6.2, this field is removed and not returned in any mongosh version or other client application. 从MongoDB 6.2开始,该字段将被删除,并且不会在任何mongosh版本或其他客户端应用程序中返回。Instead, to obtain version information, see the feature compatibility version (fcv).相反,要获取版本信息,请参阅功能兼容性版本(fcv)

sh.status.sharding-version.currentVersion

The currentVersion is the current version of the config server.currentVersion是配置服务器的当前版本。

In MongoDB versions earlier than 6.2, this field is included in the config.version collection, but in mongosh 2.0.0 and later, the field is not returned in the sh.status() output. 在6.2之前的MongoDB版本中,该字段包含在config.version集合中,但在mongosh 2.0.0及更高版本中,sh.status()输出中不会返回该字段。Starting in MongoDB 6.2, this field is removed and not returned in any mongosh version or other client application. Instead, to obtain version information, see the feature compatibility version (fcv).从MongoDB 6.2开始,该字段将被删除,并且不会在任何mongosh版本或其他客户端应用程序中返回。相反,要获取版本信息,请参阅功能兼容性版本(fcv)

sh.status.sharding-version.clusterId

The clusterId is the identification for the sharded cluster.clusterId是分片集群的标识。

Active mongos Instances活动mongos实例

sh.status.active-mongoses

If verbose is false, sh.status.active-mongoses lists the version and count of the active mongos instances. 如果verbosefalsesh.status.active-mongoses将列出活动mongos实例的版本和计数。Active mongos instances are mongos instances that have been pinged within the last 60 seconds.活动的mongos实例是在过去60秒内被ping到的mongo实例。

If verbose is true, sh.status.active-mongoses returns a document for each active mongos instance containing the following fields:如果verbosetruesh.status.active-mongoses将为每个活动的mongos实例返回一个包含以下字段的文档:

Field字段Data TypeDescription描述
_idStringThe hostname and port where the mongos is running. The _id is formatted as <hostname>:<port>.mongos运行的主机名和端口。_id的格式为<hostname>:<port>
advisoryHostFQDNsArray of stringsArray of the mongos's fully qualified domain names (FQDNs).mongos的完全限定域名(FQDN)的数组。
createdDateWhen the mongos was started. mongos启动时。
New in version 5.2. 5.2版新增。
mongoVersionStringVersion of MongoDB that the mongos is running.mongos正在运行的MongoDB版本。
pingDatemongos instances send pings to the config server every 30 seconds. mongos实例每30秒向配置服务器发送一次ping。This field indicates the last ping time.此字段指示最后一次ping时间。
upNumberLongNumber of seconds the mongos has been up as of the last ping.截至上次ping,mongos已上升的秒数。
waitingBooleanAs of MongoDB 3.4, this field is always true and is only present for backward compatibility.从MongoDB 3.4开始,该字段始终为true,并且仅用于向后兼容性。
active mongoses:

{
"_id" : "<hostname:port>",
"advisoryHostFQDNs" : [ "<name>" ],
"created" : <ISODate>,
"mongoVersion" : <string>,
"ping" : <ISODate>,
"up" : <long>,
"waiting" : <boolean>
}
...

Autosplit自动拆分

sh.status.autosplit

sh.status.autosplit indicates whether autosplit is currently enabled.指示当前是否启用了自动拆分。

Note

Starting in MongoDB 6.1, automatic chunk splitting is not performed. 从MongoDB 6.1开始,不执行自动区块分割。This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. 这是因为平衡政策的改进。自动拆分命令仍然存在,但不执行操作。For details, see Balancing Policy Changes.有关详细信息,请参阅平衡策略更改

In MongoDB versions earlier than 6.1:在6.1之前的MongoDB版本中:

The mongo methods sh.enableBalancing(namespace) and sh.disableBalancing(namespace) have no affect on the auto-splitting.mongo方法sh.enableBalancing(namespace)sh.disableBalancing(namespace)对自动拆分没有影响。

Shards分片

sh.status.shards._id

The _id displays the name of the shard._id显示分片的名称。

sh.status.shards.host

The host displays the host location of the shard.host显示分片的主机位置。

sh.status.shards.tags

The tags displays all the tags for the shard. The field only displays if the shard has tags.tags将显示分片的所有标记。该字段仅在分片具有标记时显示。

sh.status.shards.state

The state displays:state显示:

  • 0 if the shard is not shard aware.如果分片不具有分片意识,则为0
  • 1 if the shard is shard aware.如果分片是分片感知的,则为1

Balancer平衡器

Note

Starting in MongoDB 6.1, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation. 从MongoDB 6.1开始,不执行自动区块分割。这是因为平衡政策的改进。自动拆分命令仍然存在,但不执行操作。For details, see Balancing Policy Changes.有关详细信息,请参阅平衡策略更改

In MongoDB versions earlier than 6.1:在6.1之前的MongoDB版本中:

The mongo methods sh.enableBalancing(namespace) and sh.disableBalancing(namespace) have no affect on the auto-splitting.mongo方法sh.enableBalancing(namespace)sh.disableBalancing(namespace)对自动拆分没有影响。

sh.status.balancer.currently-enabled

currently-enabled indicates if the balancer is currently enabled on the sharded cluster.指示平衡器当前是否已在分片集群上启用。

sh.status.balancer.currently-running

currently-running indicates whether the balancer is currently running, and therefore currently balancing the cluster.指示平衡器当前是否正在运行,因此当前是否正在平衡群集。

sh.status.balancer.collections-with-active-migrations

collections-with-active-migrations lists 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 the sh.status() output.如果没有活动迁移,该字段将不会出现在sh.status()输出中。

sh.status.balancer.failed-balancer-rounds-in-last-5-attempts

failed-balancer-rounds-in-last-5-attempts displays 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-error

last-reported-error lists the most recent balancer error message. 列出了最新的平衡器错误消息。If there have been no errors, this field will not appear in the sh.status() output.如果没有错误,该字段将不会出现在sh.status()输出中。

sh.status.balancer.time-of-reported-error

time-of-reported-error provides the date and time of the most recently-reported error.提供最近报告的错误的日期和时间。

sh.status.balancer.migration-results-for-the-last-24-hours

migration-results-for-the-last-24-hours displays the number of migrations in the last 24 hours, and the error messages from failed migrations . 显示过去24小时内的迁移次数,以及失败迁移的错误消息。If there have been no recent migrations, migration-results-for-the-last-24-hours displays No recent migrations.如果最近没有迁移,则第24小时的migration-results-for-the-last-24-hours显示no recent migration

migration-results-for-the-last-24-hours includes all migrations, including those not initiated by the balancer.包括所有迁移,包括未由平衡器启动的迁移。

Databases数据库

sh.status.databases._id

The _id displays the name of the database.显示数据库的名称。

sh.status.databases.partitioned

Starting in MongoDB 6.0 and feature compatibility version (fCV) 6.0, the partitioned flag only maintains backward compatibility with previous versions. By default, all databases are enabled for sharding regardless of the partitioned value.从MongoDB 6.0和功能兼容性版本(fCV)6.0开始,分区标志只与以前的版本保持向后兼容性。默认情况下,无论partitioned如何,所有数据库都会启用分片。

sh.status.databases.primary

The primary displays the primary shard for the database.primary显示数据库的主分片

sh.status.databases.version

The version displays the version information for the database:version显示数据库的版本信息:

{  "uuid" : UUID("cc250b66-8638-49f7-a2e8-c6f1220b9d7a"),  "lastMod" : 1 }

where:其中:

  • uuid is the database identifier.是数据库标识符。
  • lastMod is the database version.是数据库版本。

Sharded Collection分片集合

sh.status.databases.<collection>.shard-key

The shard-key displays the shard key specification document.shard-key显示分片键规范文档。

sh.status.databases.<collection>.unique

The unique displays whether MongoDB enforces uniqueness on the shard key values (i.e. whether the underlying shard key index is unique).unique显示MongoDB是否对分片键值强制执行唯一性(即底层分片键索引是否唯一)。

sh.status.databases.<collection>.balancing

The balancing displays whether balancing is enabled (true) or disabled (false) for the collection.balancing显示集合的平衡是启用(true)还是禁用(false)。

sh.status.databases.<collection>.chunks

The chunks lists all the shards and the number of chunks that reside on each shard.chunks列出了所有分片以及每个分片上的块数。

sh.status.databases.<collection>.chunk-details

The chunk-details lists the details of the chunks [1]:chunk-details列出了区块的详细信息[1]

  • The range of shard key values that define the chunk,定义块的分片键值的范围,
  • The shard where the chunk resides, and区块所在的分片,以及
  • The last modified timestamp for the chunk.块的上次修改的时间戳。
sh.status.databases.<collection>.tag

The tag lists the details of the tags associated with a range of shard key values.tag列出了与一系列分片键值相关联的标记的详细信息。

Tip

See also: 另请参阅:

sh.balancerCollectionStatus()

[1](1, 2) The sharded collection section, by default, displays the chunk information if the total number of chunks is less than 20. 默认情况下,如果块的总数小于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).要在有20个或更多块时显示信息,请调用sh.status()方法,并将verbose参数设置为true,即sh.status(true)