kingbase的MVCC机制在数据更新时会产生死元组(dead tuples),如果果不清理掉那些dead tuples(对任何事务都是不可见的)将会永远留在数据文件中,浪费磁盘空间,对于表来说,有过多的删除和更新,dead tuples很容易占绝大部分磁盘空间。而且dead tuples也会在索引中存在,更加加重磁盘空间的浪费。需要处理的数据查询越多,查询的速度就越慢。
select
relname,
coalesce(round(n_dead_tup * 100/(case when n_live_tup + n_dead_tup = 0 then null else n_live_tup +n_dead_tup end ),2),0.00) as dead_tup_ratio
from pg_stat_all_tables
where n_dead_tup >=10000
order by dead_tup_ratio desc
limit 5;