有时候遇到一个 region 卡在 wait index,而 tikv、 tiflash proxy 都没有更多关于该 region 的信息,没有其他办法的情况下,可以尝试通过移除该 region 的 TiFlash peer,然后等待它自己重新同步数据。
pd-ctl
>> operator add remove-peer ${region-id} ${tiflash-store-id}
统计某个表的 region (不含索引)的个数/平均大小/平均key数
select table_id,db_name,table_name,count(*),avg(approximate_size),avg(approximate_keys) from information_schema.tikv_region_status where db_name = 'tpch_1' and table_name='lineitem' and is_index=0 group by table_id,db_name,table_name order by db_name,table_name;
统计某个表的 region 在 TiKV / TiFlash 各个节点上的分布情况
select c.type, a.store_id, a.address, a.db_name, a.table_name, a.is_leader, a.is_index, a.cnt from (select r.db_name, r.table_name, r.store_id, s.address, r.is_index, r.is_leader, count(*) as cnt from (select s.region_id, s.db_name, s.table_name, s.is_index, p.store_id, p.is_leader, p.status from information_schema.tikv_region_status s,information_schema.tikv_region_peers p where db_name ='tpch_1' and table_name='lineitem' and s.region_id = p.region_id order by p.store_id) as r, information_schema.tikv_store_status s where r.store_id=s.store_id group by r.store_id, r.is_leader, s.address, r.is_index) a, information_schema.cluster_info c where c.instance = a.address order by c.type desc, a.store_id;
也可使用 show table <tbl-name> regions
语句:SHOW TABLE REGIONS
抓取 TiFlash 火焰图
http://{tiflash-ip}:{proxy-status-port}/debug/pprof/profile?seconds=10&frequency=99
查看表的逻辑占用空间大小
TiDB> select table_id, db_name, table_name, sum(APPROXIMATE_SIZE) / 1024 as size_gb from `TIKV_REGION_STATUS` where db_name != 'METRICS_SCHEMA' and db_name != 'INFORMATION_SCHEMA' and db_name != 'PERFORMANCE_SCHEMA' group by table_id, db_name, table_name order by size_gb desc limit 50;