Postgres Vacuum 没有释放 space

Postgres Vacuum doesnt free up space

我的数据库中有一个table占用了161GB的硬盘space。 200Gb 硬盘中只剩下 5 GB 可用 space。

  1. 以下命令显示我的 table 正在消耗 161GB 硬盘 space,
    select pg_size_pretty(pg_total_relation_size('Employee'));

  2. table 中有将近 527 行。现在我删除了 250 行。我再次检查了 Employee 的 pg_total_relation_size。大小还是161GB.

  3. 看到上面查询的输出后,我运行真空命令:
    VACUUM VERBOSE ANALYZE Employee;

  4. 我检查了 VACUUM 是否真的发生了,
    SELECT relname, last_vacuum, last_autovacuum FROM pg_stat_user_tables; 我可以看到最后一次真空时间与我 运行 VACUUM 命令的时间相匹配。

  5. 我也运行下面的命令看看有没有死元组,
    SELECT relname, n_dead_tup FROM pg_stat_user_tables; n_dead_tup 员工 table 的计数为 0。

  6. 如果我 运行,
    select pg_size_pretty(pg_total_relation_size('Employee')); 它仍然显示 161GB。

请问这是什么原因?也请纠正我如何释放 interface_list.

vacuum 身体上 "free" space。它仅将不再使用的 space 标记为 re-usable。因此后续的 UPDATE 或 INSERT 语句可以使用 space 而不是附加到 table。

Quote from the manual

The standard form of VACUUM removes dead row versions in tables and indexes and marks the space available for future reuse. However, it will not return the space to the operating system, except in the special case where one or more pages at the end of a table become entirely free and an exclusive table lock can be easily obtained

(强调我的)

如果您 re-insert 删除了 250 行,您将看到 table 不再增长,因为新插入的行仅使用标记为空闲的 space通过 vacuum

如果您真的想将 table 的物理大小减小到 "needed" 的大小,您需要 运行 vacuum full.

Quote from the manual

VACUUM FULL actively compacts tables by writing a complete new version of the table file with no dead space. This minimizes the size of the table, but can take a long time. It also requires extra disk space for the new copy of the table, until the operation completes

(强调我的)