Skip to content

*: add slow log control variables (tidb_slow_log_rules, tidb_slow_log_max_per_sec) and hint WRITE_SLOW_LOG#21009

Merged
ti-chi-bot[bot] merged 42 commits intopingcap:masterfrom
zimulala:zimuxia/slow-log
Jan 21, 2026
Merged

*: add slow log control variables (tidb_slow_log_rules, tidb_slow_log_max_per_sec) and hint WRITE_SLOW_LOG#21009
ti-chi-bot[bot] merged 42 commits intopingcap:masterfrom
zimulala:zimuxia/slow-log

Conversation

@zimulala
Copy link
Contributor

@zimulala zimulala commented Oct 17, 2025

First-time contributors' checklist

What is changed, added or deleted? (Required)

pingcap/tidb#64010
Add slow log control variables (tidb_slow_log_rules, tidb_slow_log_max_per_sec) and hint write_slow_log

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions (in Chinese).

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

@ti-chi-bot ti-chi-bot bot added missing-translation-status This PR does not have translation status info. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 17, 2025
@qiancai qiancai added v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3. translation/doing This PR’s assignee is translating this PR. and removed missing-translation-status This PR does not have translation status info. labels Oct 17, 2025
@zimulala zimulala changed the title *: add two variables tidb_slow_log_rules and tidb_slow_log_max_per_sec *: add slow log control variables (tidb_slow_log_rules, tidb_slow_log_max_per_sec) and hint write_slow_log Oct 22, 2025
- 默认值:`0`
- 类型:整数型
- 范围:`[0, 1000000]`
- 控制每秒打印慢日志每秒的次数上限,默认值 0。当该变量值为 0 时,则表示不限制每秒打印的慢日志数量。当该变量值大于 0 时,TiDB 会限制每秒打印的慢日志数量不超过该值,超过部分的慢日志将被丢弃,不会写入慢日志文件。该变量常与 [`tidb_slow_log_rules`](#tidb_slow_log_rules) 结合使用,以防止在高负载情况下产生过多的慢日志。
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其中峰值可能超过配值(峰值 = 2*tidb_slow_log_max_per_sec),平均打印速率仍然受 tidb_slow_log_max_per_sec 限制。这个内容是否需要说明?

* [tidb_slow_log_max_per_sec](/system-variables.md#tidb_slow_log_max_per_sec):设置控制每秒打印慢日志的上限,默认值为 0。
* 当值为 0,其表示不限制每秒打印的慢日志数量。
* 当值大于 0 时,TiDB 每秒最多打印指定数量的慢日志,超过部分将被丢弃,不会写入慢日志文件。
* 建议在启用了 tidb_slow_log_rules 后配置该变量,以防规则触发频繁打印慢日志。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要不要再补充下,可能影响系统查询性能。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在下面几行的建议里面

Copy link
Contributor

@yibin87 yibin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot
Copy link

ti-chi-bot bot commented Nov 26, 2025

@yibin87: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@zimulala
Copy link
Contributor Author

PTAL @lilin90

@zimulala
Copy link
Contributor Author

zimulala commented Dec 1, 2025

PTAL @lilin90 @huoyao1125

Copy link
Member

@lilin90 lilin90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/bot-review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds documentation for new slow log control features in TiDB v9.0.0, including two system variables (tidb_slow_log_rules and tidb_slow_log_max_per_sec) and a new hint (WRITE_SLOW_LOG). These features provide more flexible and fine-grained control over slow query logging compared to the traditional single threshold approach.

Key Changes:

  • Introduced tidb_slow_log_rules variable to define multi-dimensional slow log trigger rules
  • Added tidb_slow_log_max_per_sec variable to rate-limit slow log output per TiDB instance
  • Documented the WRITE_SLOW_LOG hint to force slow log output regardless of thresholds

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
system-variables.md Added documentation for two new system variables: tidb_slow_log_rules (SESSION/GLOBAL scope for defining trigger rules) and tidb_slow_log_max_per_sec (GLOBAL scope for rate limiting)
identify-slow-queries.md Added documentation for the WRITE_SLOW_LOG hint and expanded the system variables section with detailed explanations of the new variables, including usage scenarios and interaction between rules and thresholds

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 4, 2025
@zimulala
Copy link
Contributor Author

@lilin90
PTAL

zimulala and others added 7 commits January 20, 2026 16:44
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Co-authored-by: Lilian Lee <lilin@pingcap.com>
Copy link
Member

@lilin90 lilin90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jan 20, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 21, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 21, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-20 09:30:49.406129149 +0000 UTC m=+486277.020086005: ☑️ agreed by lilin90.
  • 2026-01-21 02:06:45.182123954 +0000 UTC m=+546032.796080820: ☑️ agreed by hfxsd.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 21, 2026

@XuHuaiyu: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Member

@lilin90 lilin90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@ti-chi-bot ti-chi-bot bot added the approved label Jan 21, 2026
@hfxsd
Copy link
Collaborator

hfxsd commented Jan 21, 2026

/approve

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 21, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hfxsd, lilin90

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot merged commit 1538836 into pingcap:master Jan 21, 2026
7 checks passed
@zimulala zimulala deleted the zimuxia/slow-log branch January 21, 2026 02:55
@lilin90 lilin90 added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Mar 2, 2026
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #21406.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR. type/compatibility-or-feature-change This PR involves compatibility changes or feature behavior changes. v9.0-beta.3 This PR/issue applies to TiDB v9.0-beta.3.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants