sqlite

Database; use; embedded relational database

vacuum

英[?v?kju?m] 美[?v?kju?m ]

n. Vacuum; blank; emptiness; clean

v. Clean with a vacuum cleaner

SQLite Vacuum command syntax

Function: The VACUUM command copies the contents of the main database to a temporary database file, then clears the main database and reloads the original database file from the copy. This eliminates free pages, arranges the data in the table to be contiguous, and cleans up the database file structure. If the table does not have an explicit integer primary key (INTEGER PRIMARY KEY), the VACUUM command may change the row ID (ROWID) of the entry in the table. The VACUUM command only works on the master database, it is not possible to use the VACUUM command on attached database files. The VACUUM command fails if there is an active transaction. The VACUUM command is an operation for any in-memory database. Because the VACUUM command recreates database files from scratch, VACUUM can also be used to modify many database-specific configuration parameters.

Syntax: $sqlite3 database_name "VACUUM;" sqlite> VACUUM; sqlite> VACUUM table_name;

SQLite Vacuum command example

SQLite 的 Auto-VACUUM 與 VACUUM 不大一樣,它只是把空閑頁移到數(shù)據(jù)庫末尾,從而減小數(shù)據(jù)庫大小。通過這樣做,它可以明顯地把數(shù)據(jù)庫碎片化,而 VACUUM 則是反碎片化。所以 Auto-VACUUM 只會讓數(shù)據(jù)庫更小。

在 SQLite 提示符中,您可以通過下面的編譯運行,啟用/禁用 SQLite 的 Auto-VACUUM:

sqlite> PRAGMA auto_vacuum = NONE;  -- 0 means disable auto vacuum
sqlite> PRAGMA auto_vacuum = INCREMENTAL;  -- 1 means enable incremental vacuum
sqlite> PRAGMA auto_vacuum = FULL;  -- 2 means enable full auto vacuum
您可以從命令提示符中運行下面的命令來檢查 auto-vacuum 設(shè)置:

$sqlite3 database_name "PRAGMA auto_vacuum;"