Database Manual / Reference / Database Commands / Sharding

balancerStop (database command数据库命令)

Definition定义

balancerStop

Disables the balancer in a sharded cluster. If a balancing round is in progress, the operation waits for balancing to complete.禁用分片群集中的平衡器。如果正在进行平衡回合,则操作将等待平衡完成。

You can only issue the balancerStop against the admin database on a mongos instance.您只能对mongos实例上的admin数据库发出balancerStop

Important

Leaving the balancer disabled for extended periods of time can lead to unbalanced shards, which degrade cluster performance. Only disable the balancer if necessary, and ensure that you re-enable the balancer when maintenance is complete.长时间禁用平衡器可能会导致分片不平衡,从而降低集群性能。仅在必要时禁用平衡器,并确保在维护完成后重新启用平衡器

Tip

In mongosh, this command can also be run through the sh.stopBalancer() helper method.mongosh中,此命令也可以通过sh.stopBalancer()辅助方法运行。

Helper methods are convenient for mongosh users, but they may not return the same level of information as database commands. 助手方法对mongosh用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。In cases where the convenience is not needed or the additional return fields are required, use the database command.如果不需要便利性或需要额外的返回字段,请使用database命令。

Starting in MongoDB 6.0.3, 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.0.3开始,不执行自动块分割。这是因为平衡了政策的改进。自动拆分命令仍然存在,但不执行操作。

In MongoDB versions earlier than 6.1, the command disables auto-splitting for the sharded cluster. To enable auto-splitting when the balancer is disabled, you can use sh.enableAutoSplit().在早于6.1的MongoDB版本中,该命令禁用分片集群的自动拆分。要在禁用平衡器时启用自动拆分,可以使用sh.enableAutoSplit()

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.adminCommand(
{
balancerStop: 1,
maxTimeMS: <number>
}
)

Command Fields命令字段

Field字段Type类型Description描述
balancerStopany任意Any value.任何值。
maxTimeMSinteger整数

Time limit for disabling the balancer.禁用平衡器的时间限制。

Defaults to 60000 milliseconds.默认值为60000毫秒。

Example示例

To stop the balancer thread, connect to a mongos instance and issue the following command:要停止平衡器线程,请连接到mongos实例并发出以下命令:

db.adminCommand( { balancerStop: 1 } )

Learn More了解更多