Sobes.tech
Junior — Middle

What is the difference between VACUUM and AUTOVACUUM commands in PostgreSQL?

sobes.tech AI

Answer from AI

The VACUUM command in PostgreSQL is used to clean tables of 'dead' rows that remain after updates and deletes, in order to free space and prevent the database size from growing. It can be run manually and has two types: regular VACUUM and VACUUM FULL (which additionally compresses the table).

AUTOVACUUM is an automatic background process that periodically runs VACUUM and ANALYZE on tables to keep them in optimal condition without user intervention. It is configured through parameters and runs continuously, preventing the accumulation of 'dead' rows.

In summary:

  • VACUUM is a command that can be run manually to clean tables.
  • AUTOVACUUM is an automatic mechanism that runs VACUUM on a schedule and as needed.