适用范围
磐维3.0.0以下版本
问题概述
对环境巡检时,发现/database的磁盘使用率高达86%,并且还在每日递增,跟业务了解情况后,业务反馈数据量并没有这么大,于是开始分析。

问题原因
进库查询各个数据库大小,发现postgres库比两个业务库的数据量都大,占用了247G.

由于数据库开启了WDR功能,导致数据库产生了大量的性能数据,导致postgres库很大。
解决方案
关闭WDR功能
对死元组进行清理
查找死元组大于25%的表:
select db_name,nspname,relname,relsize,n_live_tup,n_dead_tup,dead_tup_ratio from (select current_database() db_name,b.nspname,c.relname,c.relkind,pg_relation_size(c.oid),pg_size_pretty(pg_relation_size(c.oid)) relsize ,a.seq_scan,a.seq_tup_read,a.idx_scan,a.idx_tup_fetch,a.n_tup_ins,a.n_tup_upd,a.n_tup_del,a.n_tup_hot_upd,a.n_live_tup,a.n_dead_tup,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 a, pg_class c,pg_namespace b where c.relnamespace=b.oid and c.relkind=$$r$$ and a.relid=c.oid and n_dead_tup !=‘0’ and n_dead_tup>‘1000’ order by pg_relation_size(c.oid) desc limit 10) where dead_tup_ratio>25;
进行vaccum full操作:

#在生产环境做vacuum full操作时一定要谨慎
vacuum full statement_history;
…
…
清理完成后,postgres库只剩26GB

/database磁盘使用率由86%->41%





