Skip to main content
The ALTER RANGE applies a to a range.

Required privileges

Refer to the respective subcommands.

Synopsis

alter_range syntax diagram

Parameters

ParameterDescription
range\_idThe name or ID of the range you want to change.
Additional parameters are documented for the respective subcommands.

Subcommands

SubcommandDescription
CONFIGURE ZONE for a database.
RELOCATEMove a lease or replica between stores in an emergency situation.

CONFIGURE ZONE

ALTER RANGE... CONFIGURE ZONE is used to add, modify, reset, or remove for a range. To view details about existing replication zones, see . You can use replication zones to control the number and location of replicas for specific sets of data, both when replicas are first added and when they are rebalanced to maintain cluster equilibrium. For instructions showing how to troubleshoot replication zones that may be misconfigured, see .

Required privileges

The user must be a member of the or have been granted or privileges. To configure , the user must be a member of the admin role.

Parameters

ParameterDescription
variableThe name of the to change.
valueThe value of the to change.
DISCARDRemove a replication zone.
For usage, see Synopsis.

RELOCATE

ALTER RANGE... RELOCATE is used to move a lease or between . This is helpful in an emergency situation to relocate data in the cluster.
Most users should not need to use this statement; it is for use in emergency situations. If you are in an emergency situation where you think using this statement may help, Cockroach Labs recommends contacting .

Required privileges

To alter a range and move a lease or replica between stores, the user must have one of the following:
  • Membership to the role for the cluster.

Parameters

ParameterDescription
LEASEMove .
VOTERSMove only.
NONVOTERSMove only.
FROM a\_exprMove a replica from a store ID.
TO a\_exprMove a lease or replica to a new store ID.
select\_stmtA that produces one or more rows.
For usage, see Synopsis.

Examples

Configure replication zones

Create a replication zone for a system range

In addition to the databases and tables that are visible via the SQL interface, CockroachDB stores internal data in what are called system ranges. CockroachDB comes with pre-configured replication zones for some of these ranges:
Target NameDescription
metaThe “meta” ranges contain the authoritative information about the location of all data in the cluster. These ranges must retain a majority of replicas for the cluster as a whole to remain available and historical queries are never run on them, so CockroachDB comes with a pre-configuredmeta replication zone with num\_replicas set to 5 to make these ranges more resilient to node failure and a lower-than-default gc.ttlseconds to keep these ranges smaller for reliable performance. If your cluster is running in multiple datacenters, it’s a best practice to configure the meta ranges to have a copy in each datacenter.
livenessThe “liveness” range contains the authoritative information about which nodes are live at any given time. These ranges must retain a majority of replicas for the cluster as a whole to remain available and historical queries are never run on them, so CockroachDB comes with a pre-configuredliveness replication zone with num\_replicas set to 5 to make these ranges more resilient to node failure and a lower-than-default gc.ttlseconds to keep these ranges smaller for reliable performance.
systemThere are system ranges for a variety of other important internal data, including information needed to allocate new table IDs and track the status of a cluster’s nodes. These ranges must retain a majority of replicas for the cluster as a whole to remain available, so CockroachDB comes with a pre-configuredsystem replication zone with num\_replicas set to 5 to make these ranges more resilient to node failure.
timeseriesThe “timeseries” ranges contain monitoring data about the cluster that powers the graphs in CockroachDB’s DB Console. If necessary, you can add a timeseries replication zone to control the replication of this data.
Use caution when editing replication zones for system ranges, as they could cause some (or all) parts of your cluster to stop working.
To control replication for one of the above sets of system ranges, use the statement to define the relevant values (other values will be inherited from the parent zone):

Move lease or replica

Find the cluster store IDs

To use ALTER RANGE... RELOCATE, you will need to know your cluster’s store IDs. To get the store IDs, run the following statement:

Find range ID and leaseholder information

To use ALTER RANGE... RELOCATE, you need to know how to find the range ID, leaseholder, and other information for a , , or . You can find this information using the statement. For example, to get all range IDs, leaseholder store IDs, and leaseholder localities for the table, use the following query:

Move the lease for a range to a specified store

To move the lease for range ID 70 to store ID 4:

Move the lease for all of a table’s ranges to a store

To move the leases for all data in the table to a specific store:
When it isn’t possible to move a lease for a range to the specified store, the result column will show the message unable to find store... as shown above.

Move a replica from one store to another store

If you know the store where a range’s replica is located, you can move it to another store:

Move all of a table’s replicas on one store to another store

To move the replicas for all data in the table on one store to another store:
See the result column in the output for the status of the operation. If it’s ok, the replica was moved with no issues. Other messages will indicate whether the target store is already full (VOTER_FULL), or if the replica you’re trying to remove doesn’t exist.

Move all of a range’s voting replicas from one store to another store

To move all of a range’s voting replicas from one store to another store:
See the result column in the output for the status of the operation. If it’s ok, the replica was moved with no issues. Other messages will indicate whether the target store is already full (VOTER_FULL), or if the replica you’re trying to remove doesn’t exist.

Move all of a range’s non-voting replicas from one store to another store

To move a range’s , use the statement below.
This statement will only have an effect on clusters that have non-voting replicas configured, such as . If your cluster is not a multiregion cluster, it doesn’t do anything, and will display errors in the result field as shown below.

See also