DEV Community

Sadeed Ahmad
Sadeed Ahmad

Posted on

Vacuum Processing in PostgreSQL

Vacuum processing in PostgreSQL ensures the smooth operation of the database system. Its two primary tasks are removing dead tuples and freezing transaction IDs. For the removal of dead tuples, vacuum processing has two modes: Concurrent VACUUM and Full VACUUM.

Concurrent VACUUM, commonly referred to as VACUUM, eliminates dead tuples on a per-page basis, allowing other transactions to read the table concurrently. On the other hand, Full VACUUM removes dead tuples and performs defragmentation for the entire file, but during this process, other transactions are unable to access the tables.

Despite its significance in PostgreSQL, the advancement of vacuum processing has been relatively slow compared to other functionalities. Due to the requirement of scanning entire tables, vacuum processing can be resource-intensive.

First Block

This section of the process involves performing freeze processing and removing index tuples that point to dead tuples. At first, PostgreSQL scans the target table to create a list of dead tuples and potentially freeze old tuples. This list is saved in local memory. PostgreSQL uses the dead tuple list to remove corresponding index tuples once the scanning is complete. This step is called the "cleanup stage" and is resource-intensive.

Second Block

This block removes dead tuples and updates both the FSM and VM on a page-by-page basis.

Image description

Third Block

After the deletion of indexes, the third block carries out the cleanup process, that updates the relevant statistics and system.

After post-processing the process is considered to be completed.

Top comments (0)