VACUUM

Clean up a table or index

Synopsis:



VACUUM [index-or-table-name]


Description:

The VACUUM command is a QDB extension modeled after a similar command found in PostgreSQL. If VACUUM is invoked with the name of a table or index, then it is supposed to clean up the named table or index. The index or table name argument is ignored.

When an object (table, index, or trigger) is dropped from the database, it leaves behind empty space. This makes the database file larger than it needs to be, but can speed up insertions. In time, insertions and deletions can leave the database file structure fragmented, which slows down disk access to the database contents.

The VACUUM command cleans the main database by copying its contents to a temporary database file and reloading the original database file from the copy. This eliminates free pages, aligns table data to be contiguous, and otherwise cleans up the database file structure. It is not possible to perform the same process on an attached database file.

This command will fail if there is an active transaction. This command has no effect on an in-memory database.

An alternative to using the VACUUM command is the auto-vacuum mode. You can set the auto-vacuum mode using the PRAGMA SQL extension:

qdb_statement(&db, "PRAGMA auto_vacuum = 1;"); // on
qdb_statement(&db, "PRAGMA auto_vacuum = 0;"); // off