VACUUM 是 PostgreSQL 的维护进程,用于回收来自 dead tuples(MVCC 留下的过时行版本)的存储空间并更新统计信息。由于 Postgres 的 MVCC 在每个 UPDATE/DELETE 上都会创建 dead rows,VACUUM 对于防止 bloat 并保持数据库健康至关重要。Autovacuum 可以自动化此过程。
Dead tuples 存在的原因(与 MVCC 的关系)
MVCC: an UPDATE/DELETE doesn't overwrite a row — it marks the old version obsolete
(a "dead tuple") and may create a new one. Dead tuples accumulate over time.
→ Without cleanup, dead tuples cause BLOAT: wasted disk space, slower scans
(more data to read), degraded performance.
VACUUM reclaims this dead space → keeps tables compact and queries fast.
