Table of contentsClick link to navigate to the desired location
This content has been automatically translated from Ukrainian.
PostgreSQL has a mechanism MVCC (i will tell you more details below) - multi-version of lines. When you update or delete data, older versions of strings do not disappear immediately. They remain in the table files as "dead cargo". Over time, such rows become numerous, tables inflate, indices lose their effectiveness, and queries begin to work more slowly.
To keep the base in a healthy state, PostgreSQL uses a process VACUUM. It removes unused versions of strings, frees up space, and helps update statistics for the query scheduler. This is a kind of cleaning that almost does not need to be started manually, because automatic autovacuum usually works.
There is also VACUUM FULL - more radical version. It not only cleans the "garbage", but also physically rearranges the table, returning space to the file system. Price — full table lock for operation time. Therefore, FULL is rarely and mainly used in night windows or after mass removals.
Without VACUUM, PostgreSQL gradually degrades: tables grow, indexes lose accuracy, queries become slow, and autovacuum may start working too aggressively. Therefore, VACUUM is not just a technical tool, but a basic mechanism that allows PostgreSQL to maintain performance for many years.
MVCC (Multi-Version Concurrency Control)
MVCC (Multi-Version Concurrency Control) this is the way PostgreSQL and other DBMSs allow many clients to read and modify data simultaneously without work-paralyzing locks.
In conventional non-MVCC databases, simultaneous writing and reading can create conflicts. MVCC decides this as follows: when you update a string, the base does not rewrite it on top of the old one, but creates a new version. The old one remains available for those transactions that still "see" it. Each transaction works with its own snapshot of data without disturbing the others.
The advantage is simple - readers do not block the recording, and the recording does not block readers. That is why PostgreSQL can handle a large number of parallel operations without significant delays.
The drawback is also obvious - old versions accumulate. And it is VACUUM that is responsible for getting these "dead" strings to be removed and keeping the base clean.
This post doesn't have any additions from the author yet.