ALTER RANGE applies a to a range.
Required privileges
Refer to the respective subcommands.Synopsis
Parameters
| Parameter | Description |
|---|---|
range_id | The name or ID of the range you want to change. |
Subcommands
| Subcommand | Description |
|---|---|
CONFIGURE ZONE | for a database. |
RELOCATE | Move 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 theadmin role.
Parameters
| Parameter | Description |
|---|---|
variable | The name of the to change. |
value | The value of the to change. |
DISCARD | Remove a replication zone. |
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
| Parameter | Description |
|---|---|
LEASE | Move . |
VOTERS | Move only. |
NONVOTERS | Move only. |
FROM a_expr | Move a replica from a store ID. |
TO a_expr | Move a lease or replica to a new store ID. |
select_stmt | A that produces one or more rows. |
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 Name | Description |
|---|---|
meta | The “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-configured meta 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. |
liveness | The “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-configured liveness 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. |
system | There 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-configured system replication zone with num_replicas set to 5 to make these ranges more resilient to node failure. |
timeseries | The “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.
Move lease or replica
Find the cluster store IDs
To useALTER 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 useALTER 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: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: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: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.
