官术网_书友最值得收藏!

Configuring VACUUM and autovacuum

Back in the early days of PostgreSQL projects, people had to run VACUUM manually. Fortunately, this is long gone. Nowadays, administrators can rely on a tool called autovacuum, which is part of the PostgreSQL Server infrastructure. It automatically takes care of cleanup and works in the background. It wakes up once per minute (see autovacuum_naptime = 1 in postgresql.conf) and checks if there is work to do. If there is work, autovacuum will fork up to three worker processes (see autovacuum_max_workers in postgresql.conf).

The main question is, when does autovacuum trigger the creation of a worker process?

Actually, the autovacuum process does not fork processes itself. Instead, it tells the main process to do so. This is done to avoid zombie processes in the case of failure and to improve robustness.

The answer to this question can again be found in postgresql.conf:

autovacuum_vacuum_threshold = 50  
autovacuum_analyze_threshold = 50  
autovacuum_vacuum_scale_factor = 0.2  
autovacuum_analyze_scale_factor = 0.1 

autovacuum_vacuum_scale_factor tells PostgreSQL that a table is worth vacuuming if 20% of data has been changed. The trouble is that if a table consists of one row, one change is already 100%. It makes absolutely no sense to fork a complete process to clean up just one row. Therefore, autovacuum_vacuuum_threshold says that we need 20% and this 20% must be at least 50 rows. Otherwise, VACUUM won't kick in. The same mechanism is used when it comes to optimizer stats creation. 10% and at least 50 rows are needed to justify new optimizer stats. Ideally, autovacuum creates new statistics during a normal VACUUM to avoid unnecessary trips to the table.

主站蜘蛛池模板: 淮南市| 锦州市| 门源| 开鲁县| 湛江市| 南宫市| 呼玛县| 新干县| 栖霞市| 封丘县| 武宣县| 阆中市| 巧家县| 龙门县| 黎平县| 黄石市| 鄂伦春自治旗| 称多县| 娄底市| 三亚市| 苏尼特左旗| 朝阳区| 云南省| 河北省| 罗甸县| 额尔古纳市| 邢台市| 于都县| 岑溪市| 安新县| 沾益县| 镇原县| 玉树县| 乡宁县| 广元市| 宜君县| 晋州市| 平和县| 墨脱县| 卓资县| 蓬安县|