# Couldn't decrease number of shards for table

**URL:** <https://community.cratedb.com/t/couldnt-decrease-number-of-shards-for-table/2014>\
**Category:** CrateDB\
**Tags:** data-storage, sql\
**Created:** [March 26, 2025, 7:42am UTC](https://community.cratedb.com/t/couldnt-decrease-number-of-shards-for-table/2014 "2025-03-26T07:42:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jun\_Zhou](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/jun_zhou/32/1079_2.png) [@Jun\_Zhou](https://community.cratedb.com/u/Jun_Zhou)\
**Post date:** [March 26, 2025, 7:42am UTC](https://community.cratedb.com/t/couldnt-decrease-number-of-shards-for-table/2014/1 "2025-03-26T07:42:28Z")

</div>

I’m using CrateDB 5.10.3 and I want decrease the number of shards for some tables, while getting below error.

```auto
cr> SET GLOBAL PERSISTENT "cluster.max_shards_per_node" = '1500';
SET OK, 1 row affected (0.078 sec)
cr> ALTER TABLE spl.state_machine_def SET ("blocks.write"=true);
ALTER OK, -1 rows affected (0.195 sec)
cr> ALTER TABLE spl.state_machine_def SET ("number_of_shards" = 4);
IllegalStateException[index spl.state_machine_def must have all shards allocated on the same node to shrink index]

java.lang.IllegalStateException: index spl.state_machine_def must have all shards allocated on the same node to shrink index
        at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.validateShrinkIndex(MetadataCreateIndexService.java:589)
        at org.elasticsearch.cluster.metadata.MetadataCreateIndexService.prepareResizeIndexSettings(MetadataCreateIndexService.java:638)
        at org.elasticsearch.cluster.metadata.MetadataCreateIndexService$IndexCreationTask.execute(MetadataCreateIndexService.java:436)
        at org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:45)
        at org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:665)
        at org.elasticsearch.cluster.service.MasterService.calculateTaskOutputs(MasterService.java:280)
        at org.elasticsearch.cluster.service.MasterService.runTasks(MasterService.java:175)
        at org.elasticsearch.cluster.service.MasterService.lambda$doStart$0(MasterService.java:121)
        at org.elasticsearch.cluster.service.TaskBatcher.runIfNotProcessed(TaskBatcher.java:170)
        at org.elasticsearch.cluster.service.BatchedTask.run(BatchedTask.java:70)
        at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
        at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.lang.Thread.run(Thread.java:1575)

```

---

<div class="post-metadata">

**Author:** ![hammerhead](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/hammerhead/32/270_2.png) [@hammerhead](https://community.cratedb.com/u/hammerhead)\
**Post date:** [March 26, 2025, 7:45am UTC](https://community.cratedb.com/t/couldnt-decrease-number-of-shards-for-table/2014/2 "2025-03-26T07:45:43Z")

</div>

Hi @Jun_Zhou,

You will need to relocate all shards for that table to a single node using `ALTER TABLE spl.state_machine_def SET ("routing.allocation.require._name" = '<selected_node_name>');`

There is a complete example here: [Guide to decrease the number of shards in your cluster](https://community.cratedb.com/t/guide-to-decrease-the-number-of-shards-in-your-cluster/873)

---

<div class="post-metadata">

**Author:** ![Jun\_Zhou](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/jun_zhou/32/1079_2.png) [@Jun\_Zhou](https://community.cratedb.com/u/Jun_Zhou)\
**Post date:** [March 26, 2025, 8:33am UTC](https://community.cratedb.com/t/couldnt-decrease-number-of-shards-for-table/2014/3 "2025-03-26T08:33:46Z")

</div>

Thanks a lot @hammerhead.
