ALTER RESOURCE GROUP

The ALTER RESOURCE GROUP statement is used to modify a resource group in a database.

ALTER RESOURCE GROUP - 图1

Note

This feature is not available on TiDB Serverless clusters.

Synopsis

AlterResourceGroupStmt

ALTER RESOURCE GROUP - 图2

IfExists

ALTER RESOURCE GROUP - 图3

ResourceGroupName

ALTER RESOURCE GROUP - 图4

ResourceGroupOptionList

ALTER RESOURCE GROUP - 图5

DirectResourceGroupOption

ALTER RESOURCE GROUP - 图6

ResourceGroupPriorityOption

ALTER RESOURCE GROUP - 图7

ResourceGroupRunawayOptionList

ALTER RESOURCE GROUP - 图8

DirectResourceGroupRunawayOption

ALTER RESOURCE GROUP - 图9

ResourceGroupRunawayWatchOption

ALTER RESOURCE GROUP - 图10

ResourceGroupRunawayActionOption

ALTER RESOURCE GROUP - 图11

BackgroundOptionList

ALTER RESOURCE GROUP - 图12

DirectBackgroundOption

ALTER RESOURCE GROUP - 图13

  1. AlterResourceGroupStmt ::=
  2. "ALTER" "RESOURCE" "GROUP" IfExists ResourceGroupName ResourceGroupOptionList
  3. IfExists ::=
  4. ('IF' 'EXISTS')?
  5. ResourceGroupName ::=
  6. Identifier
  7. | "DEFAULT"
  8. ResourceGroupOptionList ::=
  9. DirectResourceGroupOption
  10. | ResourceGroupOptionList DirectResourceGroupOption
  11. | ResourceGroupOptionList ',' DirectResourceGroupOption
  12. DirectResourceGroupOption ::=
  13. "RU_PER_SEC" EqOpt stringLit
  14. | "PRIORITY" EqOpt ResourceGroupPriorityOption
  15. | "BURSTABLE"
  16. | "BURSTABLE" EqOpt Boolean
  17. | "QUERY_LIMIT" EqOpt '(' ResourceGroupRunawayOptionList ')'
  18. | "QUERY_LIMIT" EqOpt '(' ')'
  19. | "QUERY_LIMIT" EqOpt "NULL"
  20. | "BACKGROUND" EqOpt '(' BackgroundOptionList ')'
  21. | "BACKGROUND" EqOpt '(' ')'
  22. | "BACKGROUND" EqOpt "NULL"
  23. ResourceGroupPriorityOption ::=
  24. LOW
  25. | MEDIUM
  26. | HIGH
  27. ResourceGroupRunawayOptionList ::=
  28. DirectResourceGroupRunawayOption
  29. | ResourceGroupRunawayOptionList DirectResourceGroupRunawayOption
  30. | ResourceGroupRunawayOptionList ',' DirectResourceGroupRunawayOption
  31. DirectResourceGroupRunawayOption ::=
  32. "EXEC_ELAPSED" EqOpt stringLit
  33. | "ACTION" EqOpt ResourceGroupRunawayActionOption
  34. | "WATCH" EqOpt ResourceGroupRunawayWatchOption "DURATION" EqOpt stringLit
  35. ResourceGroupRunawayWatchOption ::=
  36. EXACT
  37. | SIMILAR
  38. ResourceGroupRunawayActionOption ::=
  39. DRYRUN
  40. | COOLDOWN
  41. | KILL
  42. BackgroundOptionList ::=
  43. DirectBackgroundOption
  44. | BackgroundOptionList DirectBackgroundOption
  45. | BackgroundOptionList ',' DirectBackgroundOption
  46. DirectBackgroundOption ::=
  47. "TASK_TYPES" EqOpt stringLit

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.
QUERY_LIMITWhen the query execution meets this condition, the query is identified as a runaway query and the corresponding action is executed.QUERY_LIMIT=(EXEC_ELAPSED=’60s’, ACTION=KILL, WATCH=EXACT DURATION=’10m’) indicates that the query is identified as a runaway query when the execution time exceeds 60 seconds. The query is terminated. All SQL statements with the same SQL text will be terminated immediately in the coming 10 minutes. QUERY_LIMIT=() or QUERY_LIMIT=NULL means that runaway control is not enabled. See Runaway Queries.
BACKGROUNDConfigure the background tasks. For more details, see Manage background tasks.BACKGROUND=(TASK_TYPES=”br,stats”) indicates that the backup and restore and statistics collection related tasks are scheduled as background tasks.

ALTER RESOURCE GROUP - 图14

Note

  • The ALTER RESOURCE GROUP statement can only be executed when the global variable tidb_enable_resource_control is set to ON.
  • The ALTER RESOURCE GROUP statement supports incremental changes, leaving unspecified parameters unchanged. However, both QUERY_LIMIT and BACKGROUND are used as a whole and cannot be partially modified.
  • Currently, only the default resource group supports modifying the BACKGROUND configuration.

Examples

Create a resource group named rg1 and modify its properties.

  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. BURSTABLE;
  1. Query OK, 0 rows affected (0.08 sec)
  1. SELECT * FROM information_schema.resource_groups WHERE NAME ='rg1';
  1. +------+------------+----------+-----------+-------------+------------+
  2. | NAME | RU_PER_SEC | PRIORITY | BURSTABLE | QUERY_LIMIT | BACKGROUND |
  3. +------+------------+----------+-----------+-------------+------------+
  4. | rg1 | 100 | MEDIUM | NO | NULL | NULL |
  5. +------+------------+----------+-----------+-------------+------------+
  6. 1 rows in set (1.30 sec)
  1. ALTER RESOURCE GROUP rg1
  2. RU_PER_SEC = 200
  3. PRIORITY = LOW
  4. QUERY_LIMIT = (EXEC_ELAPSED='1s' ACTION=COOLDOWN WATCH=EXACT DURATION '30s');
  1. Query OK, 0 rows affected (0.08 sec)
  1. SELECT * FROM information_schema.resource_groups WHERE NAME ='rg1';
  1. +------+------------+----------+-----------+----------------------------------------------------------------+------------+
  2. | NAME | RU_PER_SEC | PRIORITY | BURSTABLE | QUERY_LIMIT | BACKGROUND |
  3. +------+------------+----------+-----------+----------------------------------------------------------------+------------+
  4. | rg1 | 200 | LOW | NO | EXEC_ELAPSED='1s', ACTION=COOLDOWN, WATCH=EXACT DURATION='30s' | NULL |
  5. +------+------------+----------+-----------+----------------------------------------------------------------+------------+
  6. 1 rows in set (1.30 sec)

Modify the BACKGROUND option for the default resource group.

  1. ALTER RESOURCE GROUP default BACKGROUND = (TASK_TYPES = "br,ddl");
  1. Query OK, 0 rows affected (0.08 sec)
  1. SELECT * FROM information_schema.resource_groups WHERE NAME ='default';
  1. +---------+------------+----------+-----------+-------------+---------------------+
  2. | NAME | RU_PER_SEC | PRIORITY | BURSTABLE | QUERY_LIMIT | BACKGROUND |
  3. +---------+------------+----------+-----------+-------------+---------------------+
  4. | default | UNLIMITED | MEDIUM | YES | NULL | TASK_TYPES='br,ddl' |
  5. +---------+------------+----------+-----------+-------------+---------------------+
  6. 1 rows in set (1.30 sec)

MySQL compatibility

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

See also