Important

You are viewing the documentation of an older version of the TiDB database (TiDB v5.4).

It is recommended that you use the latest LTS version of the TiDB database.

CREATE PLACEMENT POLICY

Warning

Placement Rules in SQL is an experimental feature. The syntax might change before its GA, and there might also be bugs.

If you understand the risks, you can enable this experiment feature by executing SET GLOBAL tidb_enable_alter_placement = 1;.

CREATE PLACEMENT POLICY is used to create a named placement policy that can later be assigned to tables, partitions, or database schemas.

Synopsis

CreatePolicyStmt
CREATEPLACEMENTPOLICYIfNotExistsPolicyNamePlacementOptionList
PolicyName
Identifier
PlacementOptionList
DirectPlacementOptionPlacementOptionListDirectPlacementOptionPlacementOptionList,DirectPlacementOption
DirectPlacementOption
PRIMARY_REGIONEqOptstringLitREGIONSEqOptstringLitFOLLOWERSEqOptLengthNumVOTERSEqOptLengthNumLEARNERSEqOptLengthNumSCHEDULEEqOptstringLitCONSTRAINTSEqOptstringLitLEADER_CONSTRAINTSEqOptstringLitFOLLOWER_CONSTRAINTSEqOptstringLitVOTER_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" FOLLOWERS=4;
CREATE TABLE t1 (a INT) PLACEMENT POLICY=p1;
SHOW CREATE PLACEMENT POLICY p1;
Query OK, 0 rows affected (0.08 sec)

Query OK, 0 rows affected (0.10 sec)

+--------+---------------------------------------------------------------------------------------------------+
| Policy | Create Policy                                                                                     |
+--------+---------------------------------------------------------------------------------------------------+
| p1     | CREATE PLACEMENT POLICY `p1` PRIMARY_REGION="us-east-1" REGIONS="us-east-1,us-west-1" 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?