database - 尽管进程正在运行,但 postgresql autovacuum 不工作

标签 database postgresql ubuntu autovacuum

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

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

日志中没有任何与 vacuum 相关的内容。

执行 ps -ef | grep -i 真空

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

运行查询 SELECT last_autovacuum , last_autoanalyze FROM pg_stat_user_tables; 在最后一个 autovacuum 列中不产生任何记录,在 suto_analyze 列中产生 2 个条目。

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

有什么想法吗?

最佳答案

引用配置中的相关条目大概是:

autovacuum_vacuum_scale_factor = 0.2

使用此默认值,如果删除或更新的行少于 20%(或少于 autovacuum_vacuum_threshold 行,但在 128 时,autovacuum 跳过该表是正常的,这在这里无关紧要) .

请参阅 documentation 中的定义:

autovacuum_vacuum_scale_factor (floating point)

Specifies a fraction of the table size to add to autovacuum_vacuum_threshold when deciding whether to trigger a VACUUM. The default is 0.2 (20% of table size). This parameter can only be set in the postgresql.conf file or on the server command line. This setting can be overridden for individual tables by changing storage parameters.

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

ALTER TABLE tablename SET (autovacuum_vacuum_scale_factor=0.01);

关于database - 尽管进程正在运行,但 postgresql autovacuum 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19527571/

相关文章:

database - Grails:如何在内存数据库中预填充数据并拆除

mysql - 从没有直接连接的多个表中获取数据

java - 连接到数据库( Derby )

sql - 使用连接构建复杂的 SQL 查询

linux - 通过具有基本身份验证的代理在curl中发送请求

sql - 优化PostgreSQL以进行快速测试

ruby-on-rails - rails 5.2 : how do I revert the Postgres specific interpretation of an array in 'where' as a parameterized IN clause?

linux - 如何在 sh 文件中并行运行 shell 脚本命令?

ubuntu - 如何将我的全局 vue-cli 安装升级到最新版本?

sql - 优化 BETWEEN 日期语句