我的桌子上有85%的死行,这给我带来了麻烦。我按照此SO response执行了VACUUM (VERBOSE) MY_TABLE
,并根据结果,当前没有活动的会话阻碍我的xmin视野(因此,我看不到我可以终止哪个会话来导致autovacuum删除死者行)。
VACUUM (VERBOSE) MY_TABLE
的结果如下:
...
CPU: user: 0.01 s, system: 0.01 s, elapsed: 0.04 s.
INFO: "my_table": found 69454 removable, 364950 nonremovable row versions in 41903 out of 82105 pages
DETAIL: 165590 dead row versions cannot be removed yet, oldest xmin: 3914663626
There were 10532004 unused item pointers.
Skipped 3 pages due to buffer pins, 39715 frozen pages.
...
然后,运行此查询:
SELECT pid, datname, usename, state, backend_xmin
FROM pg_stat_activity
WHERE backend_xmin IS NOT NULL
ORDER BY age(backend_xmin) DESC;
收益:
pid | datname | usename | state | backend_xmin
-------+----------+-----------------+--------+--------------
16664 | my_table | ¤ | active | 3914835133
30837 | my_table | my_user | active | 3915292658
...
因此,我看不到任何xmin最低为3914663626
的会话。
我还尝试了该SO答案中的另外两个查询:一个用于准备事务和复制插槽,两个都没有产生行。
vacuum
还能阻止这些死行吗?
(如果您想知道VACUUM (VERBOSE) MY_TABLE
的完整输出,大约30行。)