> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# /admin/rebalance

```
URL: http://<db.host>:<db.port>/admin/rebalance
```

Rebalance the data in the cluster so that all nodes contain an equal number of
records approximately and/or rebalance the shards to be equally distributed (as
much as possible) across all the ranks.

The database must be offline for this operation, see
[/admin/offline](/content/api/rest/admin_offline_rest)

* If [/admin/rebalance](/content/api/rest/admin_rebalance_rest) is invoked after a
  change is made to the cluster, e.g., a host was added or removed,
  [sharded data](../../concepts/tables/#sharding) will be evenly
  redistributed across the cluster by number of shards per rank while unsharded
  data will be redistributed across the cluster by data size per rank
* If [/admin/rebalance](/content/api/rest/admin_rebalance_rest) is invoked at some
  point when unsharded data (a.k.a.
  [randomly-sharded](../../concepts/tables/#random-sharding)) in the
  cluster is unevenly distributed over time, sharded data will not move while
  unsharded data will be redistributed across the cluster by data size per rank

NOTE: Replicated data will not move as a result of this call

This endpoint's processing time depends on the amount of data in the system,
thus the API call may time out if run directly.  It is recommended to run this
endpoint asynchronously via [/create/job](/content/api/rest/create_job_rest).

## Input Parameter Description

<ParamField body="options" type="map of string to strings">
  Optional parameters.

  The default value is an empty map ( \{} ).

  <Expandable title="options">
    <ParamField body="rebalance_sharded_data">
      If *true*, [sharded data](../../concepts/tables/#sharding) will be rebalanced approximately equally across the cluster. Note that for clusters with large amounts of sharded data, this data transfer could be time consuming and result in delayed query responses.

      The default value is `true`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="rebalance_unsharded_data">
      If *true*, unsharded data (a.k.a. [randomly-sharded](../../concepts/tables/#random-sharding)) will be rebalanced approximately equally across the cluster. Note that for clusters with large amounts of unsharded data, this data transfer could be time consuming and result in delayed query responses.

      The default value is `true`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="table_includes">
      Comma-separated list of unsharded table names to rebalance. Not applicable to sharded tables because they are always rebalanced. Cannot be used simultaneously with *table\_excludes*. This parameter is ignored if *rebalance\_unsharded\_data* is *false*.
    </ParamField>

    <ParamField body="table_excludes">
      Comma-separated list of unsharded table names to not rebalance. Not applicable to sharded tables because they are always rebalanced. Cannot be used simultaneously with *table\_includes*. This parameter is ignored if *rebalance\_unsharded\_data* is *false*.
    </ParamField>

    <ParamField body="aggressiveness">
      Influences how much data is moved at a time during rebalance.  A higher *aggressiveness* will complete the rebalance faster.  A lower *aggressiveness* will take longer but allow for better interleaving between the rebalance and other queries. Valid values are constants from 1 (lowest) to 10 (highest).

      The default value is `10`.
    </ParamField>

    <ParamField body="compact_after_rebalance">
      Perform compaction of deleted records once the rebalance completes to reclaim memory and disk space. Default is *true*, unless *repair\_incorrectly\_sharded\_data* is set to *true*.

      The default value is `true`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="compact_only">
      If set to *true*, ignore rebalance options and attempt to perform compaction of deleted records to reclaim memory and disk space without rebalancing first.

      The default value is `false`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="repair_incorrectly_sharded_data">
      Scans for any data sharded incorrectly and re-routes the data to the correct location. Only necessary if [/admin/verifydb](/content/api/rest/admin_verifydb_rest) reports an error in sharding alignment. This can be done as part of a typical rebalance after expanding the cluster or in a standalone fashion when it is believed that data is sharded incorrectly somewhere in the cluster. Compaction will not be performed by default when this is enabled. If this option is set to *true*, the time necessary to rebalance and the memory used by the rebalance may increase.

      The default value is `false`.

      The supported values are:

      * true
      * false
    </ParamField>
  </Expandable>
</ParamField>

## Output Parameter Description

The Kinetica server embeds the endpoint response inside a standard response structure which contains status information and the actual response to the query.  Here is a description of the various fields of the wrapper:

<ResponseField name="status" type="String">
  'OK' or 'ERROR'
</ResponseField>

<ResponseField name="message" type="String">
  Empty if success or an error message
</ResponseField>

<ResponseField name="data_type" type="String">
  'admin\_rebalance\_response' or 'none' in case of an error
</ResponseField>

<ResponseField name="data" type="String">
  Empty string
</ResponseField>

<ResponseField name="data_str" type="JSON or String">
  This embedded JSON represents the result of the /admin/rebalance endpoint:

  <Expandable title="data_str">
    <ResponseField name="info" type="map of string to strings">
      Additional information.
    </ResponseField>
  </Expandable>

  Empty string in case of an error.
</ResponseField>
