首页 > 解决方案 > visibility map: all visible pages

问题描述

The relallvisible field in pg_class view display the Number of pages that are marked all-visible in the table's visibility map.

When I try this example:

INSERT INTO foo (x) SELECT n FROM generate_series(1, 10000000) as n;  

analyze table foo;

select nspname, relpages, reltuples, relallvisible, relfrozenxid, relminmxidfrom pg_class as c
join pg_namespace as ns on c.relnamespace = ns.oid
where relname = 'foo';
 nspname | relpages |  reltuples  | relallvisible | relfrozenxid | relminmxid
---------+----------+-------------+---------------+--------------+------------
 public  |    44248 | 9.99998e+06 |             0 |        60995 |          1
(1 row)

Why is relallvisible field equal to 0 and not equal to the total number of pages that is 44248?

标签: postgresql

解决方案


因为VACUUM从来没有在桌子上跑过。该命令构建并维护可见性地图。

您可能使用的是 PostgreSQL v12 或更低版本,并且该表没有收到足够的更新或删除来触发 autovacuum。如果您的用例涉及仅插入表,请升级 - 从 v13 开始,autovacuum 也将在仅插入表上运行。


推荐阅读