Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to vacuum a database?

As referenced by this Firefox bug, what does the act of vacuuming a database accomplish? Is this operation supported by all modern database software, or only certain ones?

like image 879
An̲̳̳drew Avatar asked Jan 24 '10 19:01

An̲̳̳drew


People also ask

How long does it take to VACUUM database?

For various reasons, it's not uncommon for them to take 15-20 days, and we've seen some take upwards of 40 days. Vacuum has historically been a somewhat opaque process: it runs for a long time until it finishes, at which point it logs some basic information about what happened.

What does the VACUUM command do?

By default, VACUUM FULL skips the sort phase for any table that is already at least 95 percent sorted. If VACUUM is able to skip the sort phase, it performs a DELETE ONLY and reclaims space in the delete phase such that at least 95 percent of the remaining rows aren't marked for deletion.

Does VACUUM lock the table?

Since VACUUM does not take any exclusive lock on tables, it does not (or minimal) impact other database work. The configuration of Auto-VACUUM should be done based on the usage pattern of the database.

Does MySQL have VACUUM?

The MySQL approximation of PostgreSQL's vacuum is OPTIMIZE TABLE tablename (MySQL docs). It performs a similar function in MySQL as PostgreSQL in that, depending on the storage engine used, it reclaims unused space, reorganizes indexes and tables, and defragments data files.


2 Answers

Databases that use MVCC to isolate transactions from each other need to periodically scan the tables to delete outdated copies of rows. In MVCC, when a row is updated or deleted, it cannot be immediately recycled because there might be active transactions that can still see the old version of the row. Instead of checking if that is the case, which could be quite costly, old rows are assumed to stay relevant. The process of reclaiming the space is deferred until the table is vacuumed which, depending on the database, can be initiated automatically or explicitly.

like image 147
edgar.holleis Avatar answered Sep 28 '22 19:09

edgar.holleis


It is specifically referring to SQL lite vacuum command. http://www.sqlite.org/lang_vacuum.html

It is removing space left over from DELETE statements.

like image 24
MindStalker Avatar answered Sep 28 '22 18:09

MindStalker