# [FAQ]关于 TiDB 因 “tikv:9006" 导致报错 “auto analyze failed“ 如何处理

## Key Words

TiDB, auto analyze table, tikv 9006

## Description

v5.x 集群 auto analyze table 一直失败，从日志报错看 analyze table 因为超过 gc_life_time 时间，导致失败。

```text
Sep 27, 2022 @ 14:13:59.587
message:[2022/09/27 06:13:59.587 +00:00] [ERROR] [update.go:1191] ["[stats] auto analyze failed"] [sql="analyze table `message`.`Message`"] [cost_time=19m59.855372293s] [error="[tikv:9006]GC life time is shorter than transaction duration, transaction starts at 2022-09-27 05:53:59.686 +0000 UTC, GC safe point is 2022-09-27 06:03:43.686 +0000 UTC"] @timestamp:Sep 27, 2022 @ 14:13:59.587 container_name:tidb kubernetes.namespace:tidb1379661944610494065 user_cluster_id:1379661944610494065 user_cluster_env:shoot/aws/us-east-1/shoot--prod--4d8560d5 level:ERROR log_file:tidb.log host_name:ip-10-250-10-75.ec2.internal stream:stdout instance:db-tidb-1 component:tidb _id:CUWUfYMBm6NINQ7HtouB _type:_doc _index:filebeat-tidb-2022.09.27 _score: -
```

## Content

从 v5.2 开始，为了避免 analyze 期间的更新丢失，analyze 读取其开始时刻的 snapshot[pull/24575](https://github.com/pingcap/tidb/pull/24575)，且 modify_count 和 count 增量更新[pull/24720](https://github.com/pingcap/tidb/pull/24720)。详见[RFC for a More Accurate ModifyCount](https://docs.google.com/document/d/1VjJjAkp_EzUBroOzkZHq9OszrrY-1gnMxT1N_KYFpZs/edit?usp=sharing)。Analyze 读取 snapshot 会带来 GC 相关的问题（阻塞 GC 或者因为数据被 GC 报错）。

从 v6.2 开始， analyze 读取最新版本的数据[pull/35232](https://github.com/pingcap/tidb/pull/35232)，modify_count 增量更新， count 原地更新[pull/36588](https://github.com/pingcap/tidb/pull/36588)。设置 tidb_enable_analyze_snapshot 为 true 可以回退到 2。详见 [Analyze Isolation With GC Design Doc](https://pingcap.feishu.cn/wiki/wikcnrrgifusrVJp6Fhh1nTkKxc) 和 [issues/36552](https://github.com/pingcap/tidb/issues/36552)。

另外提供调整 auto analyze 并发度，加快统计信息收集速度。 <https://github.com/pingcap/tidb/pull/37078>

### 解决方法

1.无视 auto analyze 报错，手动 analyze 收集统计信息

优势：手动 analyze 比 auto analyze 更快

劣势：不够自动化，手动 analyze 可能造成性能波动(TiDB Cloud 目前不能实现手动)

2.调大 tidb_gc_life_time(超过 auto analyze 用时)，使 auto analyze 能顺利完成

优势：更自动化

劣势: GC 不够及时可能导致性能下降

## Affected Versions

N/A
