PostgreSQL 某些表的last_vacuum为空

Dav*_*d S 2 postgresql autovacuum

我遇到一个问题,似乎我的数据库中的一些大型表没有被 autovacuum 守护进程清理。这是我所看到的:

SELECT schemaname, relname, n_live_tup, n_dead_tup, last_autovacuum
FROM pg_stat_all_tables
ORDER BY n_dead_tup DESC LIMIT 5;
+------------+-----------------------------+------------+------------+-------------------------------+
| schemaname |          relname            | n_live_tup | n_dead_tup |        last_autovacuum        |
+------------+-----------------------------+------------+------------+-------------------------------+
| md         | calculation_log_item        |   35989527 |    3559253 | 2020-07-13 03:41:37.49764-04  |
| audit      | transaction_statement       |     700356 |     557278 | NULL                          |
| audit      | record_history              |     701635 |     438849 | NULL                          |
| md         | program_requirement_state   |     193500 |      29204 | 2020-07-14 03:06:02.339032-04 |
| md         | calculation_log             |     157942 |      11792 | NULL                          |
+------------+-----------------------------+------------+------------+-------------------------------+
(5 rows)

Run Code Online (Sandbox Code Playgroud)

因此,很明显守护进程正在运行,因为昨晚有值(注意:我在 2020 年 7 月 14 日发布此内容)。但是,我不明白为什么 transaction_statement 和 record_history 不是。与活元组相比,它们有很多死元组。

我正在使用 PostgreSQL v11。这是完整的版本信息:

select version();
+---------------------------------------------------------------------------------------------------------------------------------+
|                                                             version                                                             |
+---------------------------------------------------------------------------------------------------------------------------------+
| PostgreSQL 11.8 (Ubuntu 11.8-1.pgdg18.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0, 64-bit |
+---------------------------------------------------------------------------------------------------------------------------------+
(1 row)
Run Code Online (Sandbox Code Playgroud)

可能是什么原因造成的?如果您认为我的问题含糊不清或需要其他信息来回答(例如 postgresql.conf 设置等),请添加评论。

Lau*_*lbe 5

autovacuum 不清理表的原因可能有多种:

  • 表存储参数的配置与默认值不同:enable_autovacuum = offautovacuum_vacuum_scale_factor高得离谱或类似。

    \d+通过查看中表格的输出来找出答案psql

  • 桌子上的变化率如此之高,以至于 autovacuum 无法跟上。

    如果您发现为表运行的 autovacuum 工作程序永远不会完成,就会出现这种情况。补救措施是降低autovacuum_vacuum_cost_delay

  • 表或其索引中的数据损坏会使 autovacuum 失败并出现错误,因此它永远不会完成对表的处理。查看日志文件来诊断这一点。