Report an OOM Issue

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

Original topic: 反馈一个OOM问题

| username: porpoiselxj

Bug Report

[TiDB Version] v7.1.1
[Impact of the Bug]
The tidb-server experiences OOM and keeps restarting. After setting a memory usage limit, it no longer restarts but the memory periodically spikes and then gets restricted.

The system automatically cleans up expired information from the historical statistics table mysql.stats_history:
delete from mysql.stats_history use index(idx_create_time) where create_time > select now() - INTERVAL 604800 SECOND

Since this table contains large fields, if the above statement hits a large amount of data, it will consume a huge amount of memory, causing tidb-server to OOM.

[Temporary Solution]
Manually delete, removing 100 rows at a time, or even fewer, until all expired data is deleted.

| username: Billmay表妹 | Original post link

What is the reproduction path of this bug?

| username: Billmay表妹 | Original post link

Does it happen every time?

| username: porpoiselxj | Original post link

This is the first time I’ve encountered this, and I don’t know how to reproduce it.

It should be that the historical data cleanup failed, and after accumulating to a certain amount, it will cause an OOM. As for why it accumulates so much despite frequent cleanups, I’m not sure. Anyway, once it fails, it basically won’t succeed afterward because it will definitely OOM.

| username: 芮芮是产品 | Original post link

Your SQL can use 40GB of memory.

| username: dba远航 | Original post link

You can write a script to periodically count the data in this table, and when it reaches a certain threshold, trigger an automatic deletion mechanism to avoid anomalies caused by deleting a large amount of data at once.

| username: jansu-dev | Original post link

Hello, thank you for your feedback. This is a known issue that has already been fixed. The fix method is consistent with your temporary solution (batch). For more details, please refer to: OOM in the ClearOutdatedHistoryStats · Issue #48431 · pingcap/tidb (

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.