|  | 
|  | 1 | +--- | 
|  | 2 | +alwaysopen: false | 
|  | 3 | +categories: | 
|  | 4 | +- docs | 
|  | 5 | +- operate | 
|  | 6 | +- rs | 
|  | 7 | +db_type: database | 
|  | 8 | +description: How to migrate database shards to other nodes in a Redis Software cluster. | 
|  | 9 | +linkTitle: Migrate shards | 
|  | 10 | +title: Migrate database shards | 
|  | 11 | +toc: 'true' | 
|  | 12 | +weight: 32 | 
|  | 13 | +--- | 
|  | 14 | + | 
|  | 15 | +To migrate database shards to other nodes in the cluster, you can use the [`rladmin migrate`]({{<relref "/operate/rs/references/cli-utilities/rladmin/migrate">}}) command or [REST API requests]({{<relref "/operate/rs/references/rest-api/requests/shards/actions/migrate">}}). | 
|  | 16 | + | 
|  | 17 | +## Use cases for shard migration | 
|  | 18 | + | 
|  | 19 | +Migrate database shards to a different node in the following scenarios: | 
|  | 20 | + | 
|  | 21 | +- Before node removal. | 
|  | 22 | + | 
|  | 23 | +- To balance the database manually in case of latency issues or uneven load distribution across nodes. | 
|  | 24 | + | 
|  | 25 | +- To manage node resources, such as memory usage. | 
|  | 26 | + | 
|  | 27 | +## Considerations for shard migration | 
|  | 28 | + | 
|  | 29 | +For databases with replication: | 
|  | 30 | + | 
|  | 31 | +- Migrating a shard will not cause disruptions since a primary shard will still be available. | 
|  | 32 | + | 
|  | 33 | +- If you try to migrate a primary shard, it will be demoted to a replica shard and a replica shard will be promoted to primary before the migration. If you set `"preserve_roles": true` in the request, a second failover will occur after the migration finishes to change the migrated shard's role back to primary. | 
|  | 34 | + | 
|  | 35 | +For databases without replication, the migrated shard will not be available until the migration is done. | 
|  | 36 | + | 
|  | 37 | +Connected clients shouldn't be disconnected in either case. | 
|  | 38 | + | 
|  | 39 | +If too many primary shards are placed on the same node, it can impact database performance. | 
|  | 40 | + | 
|  | 41 | +## Migrate specific shard | 
|  | 42 | + | 
|  | 43 | +To migrate a specific database shard, use one of the following methods: | 
|  | 44 | + | 
|  | 45 | +- [`rladmin migrate shard`]({{<relref "/operate/rs/references/cli-utilities/rladmin/migrate#migrate-shard">}}): | 
|  | 46 | + | 
|  | 47 | +    ```sh | 
|  | 48 | +    rladmin migrate shard <shard_id> target_node <node_id> | 
|  | 49 | +    ``` | 
|  | 50 | + | 
|  | 51 | +- [Migrate shard]({{<relref "/operate/rs/references/rest-api/requests/shards/actions/migrate#post-shard">}}) REST API request: | 
|  | 52 | + | 
|  | 53 | +    Specify the ID of the shard to migrate in the request path and the destination node's ID as the `target_node_uid` in the request body. See the [request reference]({{<relref "/operate/rs/references/rest-api/requests/shards/actions/migrate#post-request-body">}}) for more options. | 
|  | 54 | +
 | 
|  | 55 | +    ```sh | 
|  | 56 | +    POST /v1/shards/<shard_id>/actions/migrate | 
|  | 57 | +    { | 
|  | 58 | +        "target_node_uid": <node_id> | 
|  | 59 | +    } | 
|  | 60 | +    ``` | 
|  | 61 | +
 | 
|  | 62 | +    Example JSON response body: | 
|  | 63 | +
 | 
|  | 64 | +    ```json | 
|  | 65 | +    { | 
|  | 66 | +        "action_uid": "<action_id>", | 
|  | 67 | +        "description": "Migrate was triggered" | 
|  | 68 | +    } | 
|  | 69 | +    ``` | 
|  | 70 | +
 | 
|  | 71 | +    You can track the action's progress with a [`GET /v1/actions/<action_uid>`]({{<relref "/operate/rs/references/rest-api/requests/actions#get-action">}}) request. | 
|  | 72 | + | 
|  | 73 | +## Migrate multiple shards | 
|  | 74 | + | 
|  | 75 | +To migrate multiple database shards, use one of the following methods: | 
|  | 76 | + | 
|  | 77 | +- [`rladmin migrate shard`]({{<relref "/operate/rs/references/cli-utilities/rladmin/migrate#migrate-shard">}}): | 
|  | 78 | + | 
|  | 79 | +    ```sh | 
|  | 80 | +    rladmin migrate shard <shard_id1> <shard_id2> <shard_id3> target_node <node_id> | 
|  | 81 | +    ``` | 
|  | 82 | + | 
|  | 83 | +- [Migrate multiple shards]({{<relref "/operate/rs/references/rest-api/requests/shards/actions/migrate#post-multi-shards">}}) REST API request: | 
|  | 84 | + | 
|  | 85 | +    Specify the IDs of the shards to migrate in the `shard_uids` list and the destination node's ID as the `target_node_uid` in the request body. See the [request reference]({{<relref "/operate/rs/references/rest-api/requests/shards/actions/migrate#post-multi-request-body">}}) for more options. | 
|  | 86 | +
 | 
|  | 87 | +    ```sh | 
|  | 88 | +    POST /v1/shards/actions/migrate | 
|  | 89 | +    { | 
|  | 90 | +        "shard_uids": ["<shard_id1>","<shard_id2>","<shard_id3>"], | 
|  | 91 | +        "target_node_uid": <node_id> | 
|  | 92 | +    } | 
|  | 93 | +    ``` | 
|  | 94 | +
 | 
|  | 95 | +    Example JSON response body: | 
|  | 96 | +
 | 
|  | 97 | +    ```json | 
|  | 98 | +    { | 
|  | 99 | +        "action_uid": "<action_id>", | 
|  | 100 | +        "description": "Migrate was triggered" | 
|  | 101 | +    } | 
|  | 102 | +    ``` | 
|  | 103 | +
 | 
|  | 104 | +    You can track the action's progress with a [`GET /v1/actions/<action_uid>`]({{<relref "/operate/rs/references/rest-api/requests/actions#get-action">}}) request. | 
|  | 105 | + | 
|  | 106 | +## Migrate all shards from a node | 
|  | 107 | + | 
|  | 108 | +To migrate all shards from a specific node to another node, run [`rladmin migrate all_shards`]({{<relref "/operate/rs/references/cli-utilities/rladmin/migrate#migrate-all_shards">}}): | 
|  | 109 | + | 
|  | 110 | +```sh | 
|  | 111 | +rladmin migrate node <origin_node_id> all_shards target_node <node_id> | 
|  | 112 | +``` | 
|  | 113 | + | 
|  | 114 | +## Migrate primary shards | 
|  | 115 | + | 
|  | 116 | +You can use the [`rladmin migrate all_master_shards`]({{<relref "/operate/rs/references/cli-utilities/rladmin/migrate#migrate-all_master_shards">}}) command to migrate all primary shards for a specific database or node to another node in the cluster. | 
|  | 117 | + | 
|  | 118 | +To migrate a specific database's primary shards: | 
|  | 119 | +
 | 
|  | 120 | +```sh | 
|  | 121 | +rladmin migrate db db:<id> all_master_shards target_node <node_id> | 
|  | 122 | +``` | 
|  | 123 | +
 | 
|  | 124 | +To migrate all primary shards from a specific node: | 
|  | 125 | +
 | 
|  | 126 | +```sh | 
|  | 127 | +rladmin migrate node <origin_node_id> all_master_shards target_node <node_id> | 
|  | 128 | +``` | 
|  | 129 | +
 | 
|  | 130 | +## Migrate replica shards | 
|  | 131 | +
 | 
|  | 132 | +You can use the [`rladmin migrate all_slave_shards`]({{<relref "/operate/rs/references/cli-utilities/rladmin/migrate#migrate-all_slave_shards">}}) command to migrate all replica shards for a specific database or node to another node in the cluster. | 
|  | 133 | +
 | 
|  | 134 | +To migrate a specific database's replica shards: | 
|  | 135 | + | 
|  | 136 | +```sh | 
|  | 137 | +rladmin migrate db db:<id> all_slave_shards target_node <node_id> | 
|  | 138 | +``` | 
|  | 139 | + | 
|  | 140 | +To migrate all replica shards from a specific node: | 
|  | 141 | + | 
|  | 142 | +```sh | 
|  | 143 | +rladmin migrate node <origin_node_id> all_slave_shards target_node <node_id> | 
|  | 144 | +``` | 
0 commit comments