Important

You are viewing the documentation of TiDB v6.0 (DMR). PingCAP does not provide bug fixes for v6.0. Any bugs will be fixed in future releases.

For general purposes, please use the latest LTS version of the TiDB database.

ALTER PLACEMENT POLICY

ALTER PLACEMENT POLICY is used to modify existing placement policies that have previously been created. All the tables and partitions which use the placement policy will automatically be updated.

ALTER PLACEMENT POLICY replaces the previous policy with the new definition. It does not merge the old policy with the new one. In the following example, FOLLOWERS=4 is lost when the ALTER PLACEMENT POLICY is executed:

CREATE PLACEMENT POLICY p1 FOLLOWERS=4;
ALTER PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1";

Synopsis

AlterPolicyStmt
ALTERPLACEMENTPOLICYIfExistsPolicyNamePlacementOptionList
PolicyName
Identifier
PlacementOptionList
PlacementOptionPlacementOptionListPlacementOptionPlacementOptionList,PlacementOption
PlacementOption
CommonPlacementOptionSugarPlacementOptionAdvancedPlacementOption
CommonPlacementOption
FOLLOWERSEqOptLengthNum
SugarPlacementOption
PRIMARY_REGIONEqOptstringLitREGIONSEqOptstringLitSCHEDULEEqOptstringLit
AdvancedPlacementOption
LEARNERSEqOptLengthNumCONSTRAINTSEqOptstringLitLEADER_CONSTRAINTSEqOptstringLitFOLLOWER_CONSTRAINTSEqOptstringLitLEARNER_CONSTRAINTSEqOptstringLit

Examples

Note

To know which regions are available in your cluster, see SHOW PLACEMENT LABELS.

If you do not see any available regions, your TiKV installation might not have labels set correctly.

CREATE PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1";
CREATE TABLE t1 (i INT) PLACEMENT POLICY=p1; -- Assign policy p1 to table t1
ALTER PLACEMENT POLICY p1 PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1,us-west-2" FOLLOWERS=4; -- The rules of t1 will be updated automatically.
SHOW CREATE PLACEMENT POLICY p1\G;
Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.10 sec)

***************************[ 1. row ]***************************
Policy        | p1
Create Policy | CREATE PLACEMENT POLICY `p1` PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1,us-west-2" FOLLOWERS=4
1 row in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also

Was this page helpful?