Deleting a Database Does Not Reduce Disk Space

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

Original topic: 删除数据库,磁盘空间没变少

| username: 等一分钟

【TiDB Usage Environment】Production Environment
【TiDB Version】v6.5.1
I deleted dozens of databases, but the disk space did not decrease. What could be the problem?

| username: Miracle | Original post link

The default GC time is ten minutes. You can check it again later.

| username: 华南灌水王 | Original post link

You need to wait for a while.

After deleting data in TiDB, the kv segments to be cleaned are first written into mysql.gc_delete_range, which contains a ts recording the timestamp of the deletion.
Then, it checks once every @@tidb_gc_run_interval. If the current cluster’s min(minStartTs, now) + @@tidb_gc_life_time > ts, it will actually clean up.
So the data might not be cleaned up due to:

  1. @@tidb_gc_run_interval hasn’t reached yet, and the cleanup logic hasn’t started.
  2. @@tidb_gc_life_time hasn’t passed yet, so the data is still alive.
  3. There is an ongoing txn that is blocking the calculation of min(minStartTs, now).

You can specifically search for “[gc worker]” in the TiDB log (only one TiDB will become the gc leader, so you might need to check around).

| username: 等一分钟 | Original post link

I have already deleted it several days ago.

| username: 等一分钟 | Original post link

Will this have an impact?

| username: zhanggame1 | Original post link

select * from mysql.tidb to check the progress of GC

| username: 等一分钟 | Original post link

The image you provided is not visible. Please provide the text you need translated.

| username: TIDB-Learner | Original post link

Excluding issues with TiDB itself, it is possible that disk space has not been released. Try using lsof | grep deleted.

| username: jetora | Original post link

The Principles and Common Issues of GC in TiKV Component

| username: 等一分钟 | Original post link

Is there a way to check for invalid regions?

| username: TiDBer_jYQINSnf | Original post link

In the PD monitoring panel, there are empty regions.
There are no invalid regions.

All regions are connected sequentially. It only means that the data in the middle of this range has been completely deleted, making this region empty. It does not mean that this range has disappeared.

| username: tidb菜鸟一只 | Original post link

Check the number of empty regions in Grafana, it should release a lot.

| username: Soysauce520 | Original post link

Check the PD scheduling to see if the region merging is slow.

| username: TiDBer_QKDdYGfz | Original post link

It should be related to RocksDB’s compaction.

| username: zhaokede | Original post link

Manual compaction can be triggered.

| username: TiDBer_7S8XqKfl-1158 | Original post link

GC cleanup indeed takes time. You can adjust the parameters to shorten the interval for GC to clean up garbage data.

| username: h5n1 | Original post link

Check if there is any content in select count(*) from mysql.gc_delete_range;, and see if there is the phrase gc work is too busy in the TiDB log.

| username: TiDBer_7S8XqKfl-1158 | Original post link

GC cleanup takes time.

| username: 呢莫不爱吃鱼 | Original post link

The GC time you set hasn’t arrived yet, right?

| username: 随缘天空 | Original post link

Search for manually merging regions and deleting redundant, invalid empty regions.