虽然进程正在运行,但postgresql autovacuum无法正常工作

时间:2013-10-22 20:23:00

标签: database postgresql ubuntu autovacuum

我在Ubuntu上运行PostgreSQL 9.2。  autovacuum进程正在服务器上运行。

数据库负载很重,1000次添加和100次删除,但似乎autovacuum没有启动。

原木中没有与真空相关的东西。

执行ps -ef | grep -i vacuum

生成:postgres 1406 1130 0 Oct13 00:00:14 postgres: autovacuum launcher process

运行查询SELECT last_autovacuum , last_autoanalyze FROM pg_stat_user_tables; 在最后一个autovacuum列中没有产生记录,2在suto_analyze列中输入。

postgresql.conf的相关部分是:

#------------------------------------------------------------------------------
# AUTOVACUUM PARAMETERS
#------------------------------------------------------------------------------

autovacuum = on         # Enable autovacuum subprocess?  'on'
                    # requires track_counts to also be on.
log_autovacuum_min_duration = 250   # -1 disables, 0 logs all actions and
                    # their durations, > 0 logs only
                    # actions running at least this number
                    # of milliseconds.
autovacuum_max_workers = 3      # max number of autovacuum subprocesses
                    # (change requires restart)
#autovacuum_naptime = 1min      # time between autovacuum runs
autovacuum_vacuum_threshold = 128   # min number of row updates before
                    # vacuum
autovacuum_analyze_threshold = 128  # min number of row updates before
                    # analyze
#autovacuum_vacuum_scale_factor = 0.2   # fraction of table size before vacuum
#autovacuum_analyze_scale_factor = 0.1  # fraction of table size before analyze
#autovacuum_freeze_max_age = 200000000  # maximum XID age before forced vacuum
                    # (change requires restart)
#autovacuum_vacuum_cost_delay = 20ms    # default vacuum cost delay for
                    # autovacuum, in milliseconds;
                    # -1 means use vacuum_cost_delay
#autovacuum_vacuum_cost_limit = -1  # default vacuum cost limit for
                    # autovacuum, -1 means use
                    # vacuum_cost_limit

有什么想法?

1 个答案:

答案 0 :(得分:7)

引用配置中的相关条目可能是:

  

autovacuum_vacuum_scale_factor = 0.2

使用此默认设置,如果已删除或更新了少于20%的行(或者行数少于autovacuum_vacuum_threshold但在此处无关紧要的话,autovacuum会跳过表),这是正常的。

documentation中查看其定义:

  

autovacuum_vacuum_scale_factor (浮点)

     

指定要添加到的表大小的一小部分   确定是否触发VACUUM时的autovacuum_vacuum_threshold。   默认值为0.2(表大小的20%)。此参数只能设置   在postgresql.conf文件中或在服务器命令行上。这个   可以通过更改存储来覆盖各个表的设置   参数。

如果您不喜欢默认值,要对某些表进行autovacuum处理,您可以根据具体情况降低此参数。例如,将其设置为1%:

ALTER TABLE tablename SET (autovacuum_vacuum_scale_factor=0.01);