PostgreSQL Vacuum and Vacuum full are not two different processes

PostgreSQL Vacuum and Vacuum full are not two different processes


PostgreSQL Vacuum: PostgreSQL‘s VACUUM and VACUUM FULL are not separate processes but rather different operational modes of the same maintenance command. Here’s why:

Core Implementation

Both commands share the same underlying codebase and are executed through the vacuum_rel() function in PostgreSQL‘s source code (src/backend/commands/vacuum.c). The key distinction lies in the FULL option, which triggers additional steps:

  • Standard VACUUM:
    • Removes dead tuples (obsolete rows) and marks space reusable within PostgreSQL
    • Additionally, it updates the visibility map to optimize future queries
    • Moreover, it Runs concurrently with read/write operations
  • VACUUM FULL:
    • Rewrites the entire table into a new disk file, compressing it and reclaiming space for the operating system
    • Rebuilds all indexes and requires an ACCESS EXCLUSIVE lock, blocking other operations

Key Differences in Behavior

Aspect Standard VACUUM VACUUM FULL
Space Reclamation Internal reuse only OS-level space release
Locking Non-blocking Full table lock
Performance Impact Lightweight, incremental Heavy, resource-intensive
Use Case Routine maintenance Severe table bloat remediation

Why They Aren’t Separate Processes

  • Shared Code Path: Both use the same core logic for dead-tuple identification and cleanup. VACUUM FULL adds a table-rewrite step by calling cluster_rel()
  • Configuration Integration: Parameters like autovacuum_vacuum_scale_factor apply to both, and autovacuum workers handle standard VACUUM by default
  • Unified Command Structure: The FULL option is a modifier rather than a standalone tool, as seen in the SQL syntax:
VACUUM (FULL, ANALYZE) table_name;  -- vs.
VACUUM table_name;

When to Use Each

  • Standard VACUUM: Daily maintenance to prevent bloat from MVCC dead tuples
  • VACUUM FULL: Rarely, for extreme cases where table size has grown uncontrollably due to long-unvacuumed updates/deletes

In summary, while their outcomes differ significantly, VACUUM and VACUUM FULL are part of a single maintenance framework, differentiated primarily by the aggressiveness of space reclamation and locking behavior.

 

Comprehensive Guide to Aggregate Functions in PostgreSQL

 

PostgreSQL Vacuum Internals – What happens during PostgreSQL Vacuum Processing?

About MinervaDB Corporation 60 Articles
A boutique private-label enterprise-class MySQL, MariaDB, MyRocks, PostgreSQL and ClickHouse consulting, 24*7 consultative support and remote DBA services company with core expertise in performance, scalability and high availability. Our consultants have several years of experience in architecting and building web-scale database infrastructure operations for internet properties from diversified verticals like CDN, Mobile Advertising Networks, E-Commerce, Social Media Applications, SaaS, Gaming and Digital Payment Solutions. Our globally distributed team working on multiple timezones guarantee 24*7 Consulting, Support and Remote DBA Services delivery for MySQL, MariaDB, MyRocks, PostgreSQL and ClickHouse.