https://www.2ndquadrant.com/en/blog/autovacuum-tuning-basics/
最主要的手段还是修改
scale_factor
以及根据硬件配置修改cost_limit
。单独修改 autovacuum_max_workers 只会回收的更慢。
Cleanup of dead tuples is not the only task of autovacuum. It’s also responsible for updating data distribution statistics, used by the optimizer when planning queries. You may collect those manually by running ANALYZE, but it suffers similar issues as VACUUM – you’re likely to run it either too often or not often enough.
In other words, you should have some basic monitoring in place, collecting metrics from the database. For cleanup, you need to be looking at least at these values:
pg_stat_all_tables.n_dead_tup
– number of dead tuples in each table (both user tables and system catalogs)(n_dead_tup / n_live_tup)
– ratio of dead/live tuples in each table(pg_class.relpage