Updated on 2026-04-29 GMT+08:00

Deleting Shards

Scenarios

To prevent resource waste when instance data and workload decrease, you can reduce the number of shards. This scales down your cluster to fit the current workload. If your shard specifications are higher than needed, releasing unnecessary shards can help reduce costs. This section describes how to release shards from a cluster instance.

Precautions

  • You can delete shards only from instances of version 4.0 and later.
  • Deleting a shard initiates data migration between the remaining shards. This process can result in increased network and disk I/O overhead, potentially degrading the cluster's overall read/write performance and increasing delay. Before deleting a shard, consider using DRS to migrate data to a new instance or downgrading the shard specifications to minimize costs.
  • The migration speed can be affected by factors such as data volume and node specifications, potentially taking several days to complete. If there is more than 1,000 GB of data on the shard to be deleted, the migration may take a significantly longer period and could fail. In such cases, consider using alternative cost-saving solutions.
  • Before deleting a shard, verify all pre-check items. To minimize the impact, verify them during off-peak hours.
  • If the shard to be deleted has been associated with a shard IP address, the system will automatically release this IP address after the deletion. Before performing the deletion, check the workload status and fully evaluate the impact.
  • If there are duplicate keys between the shard you want to delete and other shards, the deletion will fail. Ensure that all keys are unique, and then try to delete the shard again.
  • To prevent your instance from becoming read-only, ensure that the total storage of the remaining shards is at least 120% of the cluster's used storage.
  • A shard associated with read replicas cannot be deleted.
  • If the cluster balancer is enabled for your instance, it will be temporarily disabled during the scale-in and then enabled again. Ensure that the cluster balancer remains disabled during the scale-in. Otherwise, the deletion may fail.
  • During shard deletion, avoid performing DDL operations such as creating and deleting collections or indexes. These operations may cause shard deletion to fail and affect your workload.
  • Delete orphaned documents before deleting a shard. Orphaned documents may cause shard deletion to fail. For details, see Deleting Orphaned Documents.
  • Backup is not supported during shard deletion, and automated backups are suspended. Deleting a shard will prevent existing backups from being restored to the current instance, including database- and table-level restoration. If needed, restore the data to a new instance. Create a manual backup immediately after deleting a shard.
  • Once a shard deletion task is started, no other changes are allowed, and the task cannot be stopped or rolled back. Exercise caution and perform this operation during off-peak hours.

Pre-check Items for Deleting Shards

  • The instance and all of its nodes are running properly.
  • The primary/secondary replication delay does not exceed 30s.
  • The shard to be deleted is not the primary shard.
  • The shard to be deleted does not contain jumbo chunks.
  • No shard contains duplicated keys (_id).
  • The shard to be deleted is not associated with any read replica.
  • The remaining available storage space is at least 120% of the used space.
  • Orphaned documents are deleted.
    1. If the shard to be deleted is a primary shard, you must run the movePrimary command to migrate the primary shard of the corresponding database to another shard before deleting the shard. The movePrimary command may affect service running. Therefore, this command is disabled by default.
    2. The default chunk size of DDS is 64 MB. If a chunk exceeds 64 MB and cannot be split (typically because all documents in the chunk have the same shard key), the system marks it as a jumbo chunk. Such chunks cannot be migrated.

No.

Check Item

Criteria

Instructions

1

Instance status

The instance status is Available.

On the Instances page, check whether the target instance is running properly.

2

Node status

The statuses of all nodes in the cluster are Available.

In the Node Information area on the Basic Information page, check whether the nodes are running properly.

3

Shard count

After the deletion, the number of shards must be greater than 2.

If there are two shards currently, no shard cannot be deleted. Reducing the number would leave fewer than two shards, which does not meet the cluster architecture requirements.

4

Storage space after deletion

Total storage of the remaining shards > Used storage of the cluster x 120%

In the Node Information area on the Basic Information page, click the shard tab to view the storage space and storage usage of each shard.

Calculate the total storage of the remaining shards. The following is an example:

Total storage: 150 GB (3 shards x 50 GB)

To be deleted: 1 shard

Storage after the deletion: 100 GB

Used storage: 1.5 GB

Minimum required storage: 1.5 GB x 120% = 1.8 GB

Conclusion: 100 GB > 1.8 GB. The check is passed.

5

Balancer status

The balancer must be disabled.

  1. Connect to the cluster instance using Mongo Shell.
  2. Run the following command to query the balancer status:
    sh.startBalancer()
  3. If false is displayed in the command output, the balancer is disabled.

6

Primary shard

The shard to be deleted is not the primary shard of any database.

  1. Connect to the cluster instance using Mongo Shell.
  2. Run the following command. If any result is returned, the shard is the primary shard of a database.
db.getSiblingDB("config").databases.find({"primary": "shard_x"})
NOTE:

shard_x indicates the name of the shard to be deleted. You can obtain the shard name on the shard tab page in the Node Information area on the Basic Information page.

7

Jumbo chunk

The shard to be deleted does not contain jumbo chunks.

  1. Connect to the cluster instance using Mongo Shell.
  2. Run the following command. If any result is returned, the shard contains jumbo chunks.
db.getSiblingDB("config").chunks.find({"shard": "shard_x", "jumbo":true})

Deleting a Shard

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and a project.
  3. Click in the upper left corner of the page and choose Databases > Document Database Service.
  4. On the Instances page, click the name of the target cluster instance.
  5. In the Node Information area on the Basic Information page, click the shard tab, locate the target shard, and choose More > Delete in the Operation column.

    Figure 1 Deleting a shard

  6. Click Yes.
  7. In the Node Information area on the Basic Information page, verify that the number of shards has decreased.