CREATE RESOURCE GROUP

You can use the CREATE RESOURCE GROUP statement to create a resource group.

CREATE RESOURCE GROUP - 图1

Note

This feature is not available on TiDB Serverless clusters.

Synopsis

CreateResourceGroupStmt

CREATE RESOURCE GROUP - 图2

IfNotExists

CREATE RESOURCE GROUP - 图3

ResourceGroupName

CREATE RESOURCE GROUP - 图4

ResourceGroupOptionList

CREATE RESOURCE GROUP - 图5

DirectResourceGroupOption

CREATE RESOURCE GROUP - 图6

ResourceGroupPriorityOption

CREATE RESOURCE GROUP - 图7

  1. CreateResourceGroupStmt ::=
  2. "CREATE" "RESOURCE" "GROUP" IfNotExists ResourceGroupName ResourceGroupOptionList
  3. IfNotExists ::=
  4. ('IF' 'NOT' 'EXISTS')?
  5. ResourceGroupName ::=
  6. Identifier
  7. ResourceGroupOptionList ::=
  8. DirectResourceGroupOption
  9. | ResourceGroupOptionList DirectResourceGroupOption
  10. | ResourceGroupOptionList ',' DirectResourceGroupOption
  11. DirectResourceGroupOption ::=
  12. "RU_PER_SEC" EqOpt stringLit
  13. | "PRIORITY" EqOpt ResourceGroupPriorityOption
  14. | "BURSTABLE"
  15. ResourceGroupPriorityOption ::=
  16. LOW
  17. | MEDIUM
  18. | HIGH

The resource group name parameter (ResourceGroupName) must be globally unique.

TiDB supports the following DirectResourceGroupOption, where Request Unit (RU) is a unified abstraction unit in TiDB for CPU, IO, and other system resources.

OptionDescriptionExample
RU_PER_SECRate of RU backfilling per secondRU_PER_SEC = 500 indicates that this resource group is backfilled with 500 RUs per second
PRIORITYThe absolute priority of tasks to be processed on TiKVPRIORITY = HIGH indicates that the priority is high. If not specified, the default value is MEDIUM.
BURSTABLEIf the BURSTABLE attribute is set, TiDB allows the corresponding resource group to use the available system resources when the quota is exceeded.

CREATE RESOURCE GROUP - 图8

Note

  • The CREATE RESOURCE GROUP statement can only be executed when the global variable tidb_enable_resource_control is set to ON. TiDB automatically creates a default resource group during cluster initialization. For this resource group, the default value of RU_PER_SEC is UNLIMITED (equivalent to the maximum value of the INT type, that is, 2147483647) and it is in BURSTABLE mode. All requests that are not bound to any resource group are automatically bound to this default resource group. When you create a new configuration for another resource group, it is recommended to modify the default resource group configuration as needed.

Examples

Create two resource groups rg1 and rg2.

  1. DROP RESOURCE GROUP IF EXISTS rg1;
  1. Query OK, 0 rows affected (0.22 sec)
  1. CREATE RESOURCE GROUP IF NOT EXISTS rg1
  2. RU_PER_SEC = 100
  3. PRIORITY = HIGH
  4. BURSTABLE;
  1. Query OK, 0 rows affected (0.08 sec)
  1. CREATE RESOURCE GROUP IF NOT EXISTS rg2
  2. RU_PER_SEC = 200;
  1. Query OK, 0 rows affected (0.08 sec)
  1. SELECT * FROM information_schema.resource_groups WHERE NAME ='rg1' or NAME = 'rg2';
  1. +------+------------+----------+-----------+
  2. | NAME | RU_PER_SEC | PRIORITY | BURSTABLE |
  3. +------+------------+----------+-----------+
  4. | rg1 | 100 | HIGH | YES |
  5. | rg2 | 200 | MEDIUM | NO |
  6. +------+------------+----------+-----------+
  7. 2 rows in set (1.30 sec)

MySQL compatibility

MySQL also supports CREATE RESOURCE GROUP. However, the acceptable parameters are different from that of TiDB so that they are not compatible.

See also