How to Prevent TiDB Process from Restarting When Memory Exceeds Limits

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何实现TIDB内存过限时进程不被重启

| username: TiDBer_4nyUburF

【TiDB Usage Environment】Production Environment
【TiDB Version】
【Reproduction Path】What operations were performed when the issue occurred
【Encountered Issue: Issue Phenomenon and Impact】TiDB process is restarted when memory usage exceeds the limit, currently all are default configurations
【Resource Configuration】
【Attachments: Screenshots/Logs/Monitoring】

| username: Jolyne | Original post link

  1. Refer to the official website’s tidb-server configuration to set the memory limit parameters.
  2. You can change the tidb_mem_oom_action parameter from cancel to log.
| username: Miracle | Original post link

You can check if this parameter meets your requirements:

| username: 小龙虾爱大龙虾 | Original post link

There is no way to avoid the operating system killing processes. If it doesn’t kill this one, it will kill other processes, which don’t take up much memory. What you can try is:

  1. Identify and handle the SQL queries that consume a lot of memory in advance.
  2. Use the high-version global memory control parameter tidb_server_memory_limit to help control memory usage.
| username: dba远航 | Original post link

You can change the parameter of tidb_mem_oom_action from cancel to log, and then use temporary disk, see the image below.

| username: TiDBer_小阿飞 | Original post link

  • Database version and memory-related configurations:
    • TiDB version
    • tidb_mem_quota_query
    • memory-usage-alarm-ratio
    • mem-quota-query
    • oom-action
    • tidb_enable_rate_limit_action
    • tidb_server_memory_limit
    • oom-use-tmp-storage
    • tmp-storage-path
    • tmp-storage-quota
    • tidb_analyze_version
      TiDB OOM 故障排查 | PingCAP 文档中心
| username: tidb菜鸟一只 | Original post link

Your version is 4.0, and tidb_server_memory_limit is not available. You can only limit the memory usage of a single SQL query through tidb_mem_quota_query. However, this lower version doesn’t control it very well. It is still recommended to monitor the database SQL more frequently and optimize those with high memory usage. Alternatively, consider upgrading to version 6.4 to use the tidb_server_memory_limit parameter, which can basically ensure that the tidb-server will not be killed by OOM.

| username: 路在何chu | Original post link

Write a script to monitor large SQL queries, the version is too low.