ALTER RESOURCE GROUP

ALTER RESOURCE GROUP 语句用于在当前所选数据库中修改资源组。

语法图

AlterResourceGroupStmt

ALTER RESOURCE GROUP - 图1

IfExists

ALTER RESOURCE GROUP - 图2

ResourceGroupName

ALTER RESOURCE GROUP - 图3

ResourceGroupOptionList

ALTER RESOURCE GROUP - 图4

DirectResourceGroupOption

ALTER RESOURCE GROUP - 图5

ResourceGroupPriorityOption

ALTER RESOURCE GROUP - 图6

ResourceGroupRunawayOptionList

ALTER RESOURCE GROUP - 图7

DirectResourceGroupRunawayOption

ALTER RESOURCE GROUP - 图8

ResourceGroupRunawayWatchOption

ALTER RESOURCE GROUP - 图9

ResourceGroupRunawayActionOption

ALTER RESOURCE GROUP - 图10

BackgroundOptionList

ALTER RESOURCE GROUP - 图11

DirectBackgroundOption

ALTER RESOURCE GROUP - 图12

  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 支持以下 DirectResourceGroupOption, 其中 Request Unit (RU) 是 TiDB 对 CPU、IO 等系统资源统一抽象的单位。

参数含义举例
RU_PER_SEC每秒 RU 填充的速度RU_PER_SEC = 500 表示此资源组每秒回填 500 个 RU。
PRIORITY任务在 TiKV 上处理的绝对优先级PRIORITY = HIGH 表示优先级高。若未指定则默认为 MEDIUM
BURSTABLE允许对应的资源组超出配额后使用空余的系统资源。
QUERY_LIMIT当查询执行满足该条件时,识别该查询为 Runaway Query 并执行相应的操作QUERY_LIMIT=(EXEC_ELAPSED=’60s’, ACTION=KILL, WATCH=EXACT DURATION=’10m’) 表示当执行时间超过 60 秒后识别为 Runaway Query,对该查询执行终止操作,并在 10 分钟内对同样的 SQL 直接执行终止操作。QUERY_LIMIT=()QUERY_LIMIT=NULL 则表示不进行 Runaway 控制。具体参数介绍参见管理资源消耗超出预期的查询 (Runaway Queries)。 |
BACKGROUND后台任务相关的设置。具体参数介绍参见管理后台任务BACKGROUND=(TASK_TYPES=”br,stats”) 表示将备份恢复和收集统计信息相关的任务作为后台任务调度。

ALTER RESOURCE GROUP - 图13

注意

  • ALTER RESOURCE GROUP 语句只能在全局变量 tidb_enable_resource_control 参数设置为 ON 时才能执行。
  • ALTER RESOURCE GROUP 语句支持以增量方式修改,未指定的参数保持不变。但其中 QUERY_LIMITBACKGROUND 各自作为一个整体,无法部分修改其中的参数。
  • 目前仅 default 资源组支持修改 BACKGROUND 相关设置。

示例

创建一个名为 rg1 的资源组,并修改它的属性。

  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)

修改 default 资源组的后台任务 BACKGROUND 相关设置。

  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 兼容性

MySQL 也支持 ALTER RESOURCE GROUP,但是接受的参数和 TiDB 不同,两者并不兼容。

另请参阅