Can you explain what the VACUUM command means in the context of working with a database?
sobes.tech AI
Answer from AI
The VACUUM command is used in some DBMSs, such as PostgreSQL and SQLite, to clean and optimize the database. It removes 'dead' rows — records that have been deleted or updated but still occupy space on the disk. This helps free up space, reduce fragmentation, and improve query performance.
For example, in PostgreSQL, after a large number of DELETE or UPDATE operations, a table may contain a lot of unused space. Running VACUUM allows the database to reorganize data and update statistics for the query planner.
In SQLite, VACUUM rewrites the entire database into a new file, thereby reducing its size.
Example of usage in SQL:
VACUUM;
Important: VACUUM can be a resource-intensive operation, so it is usually run during periods of low load.