Help Center> Data Replication Service> FAQs> Real-Time Migration> How Do I Disable the Balancer?
Updated on 2024-03-27 GMT+08:00

How Do I Disable the Balancer?

Before using the DRS service to migrate collections between sharded clusters, you must disable the balancer of the collections to be migrated.

  • You can disable the DDS cluster balancer by calling an API. For details, see Enabling or Disabling Cluster Balancing or contact DDS technical support. For a self-built MongoDB database, refer to the following steps.
  • After the migration is complete, enable the balancer. The balancer is disabled during the migration, generating different numbers of chunks on each shard of the source database. After the balancer is enabled, chunks will be distributed between shards in the cluster, which may affect the performance of the source database.

Procedure

  1. Log in to a database through mongo shell.
  2. Run the following command in the command window of the mongos node to switch to the config database:

    use config

  3. Run the following commands to check whether the balancer can be disabled:

    while( sh.isBalancerRunning() ) {      
              print("waiting...");           
              sleep(1000);
    }
    • If the command output is waiting, the balancer is migrating chunks. In this case, do not disable the balancer. Otherwise, data inconsistency may occur.
      Figure 1 Viewing the command output
    • If no command output is displayed, the balancer is not migrating any chunks. In this case, you can disable the balancer:

  4. Disable the balancer.

    • If you migrate the entire DB instance, run the following command to disable the balancer.
      sh.stopBalancer()
    • If you need to disable the balancer of the sharded collections to be migrated, run the following command:
      sh.disableBalancing("database.collection")

      database.collection indicates the namespace of the collection to be migrated.

Real-Time Migration FAQs

more