44

I want to know how to vacuum sqlite database. I tried a syntax MANUAL VACUUM command for the whole database from command prompt:

 $sqlite3 database_name "VACUUM;";

But it's giving error as:

near "database_name": syntax error.

and also AUTO VACUUM:

PRAGMA auto_vacuum = INCREMENTAL;

And tried it for a particular table as:

VACUUM table_name;

But no result.

zx8754
  • 52,746
  • 12
  • 114
  • 209
meghalee
  • 441
  • 1
  • 4
  • 3

5 Answers5

36

You don't to specify the table name in the syntax. Only VACUUM works.

Also, it will clean the main database only and not any attached database files.

For more info, refer to the SQLite documentation.

vqdave
  • 2,361
  • 1
  • 18
  • 36
SHANK
  • 2,978
  • 23
  • 31
  • 1
    this page suggests that its possible on the table http://www.tutorialspoint.com/sqlite/sqlite_vacuum.htm – Vihaan Verma Nov 26 '14 at 07:08
  • 1
    `VACUUM` from sqlite3 command line will only VACUUM main database. Attached databases can be VACUUMED only from sqlite3 verison `version 3.15.0`. For older versions, database name *must* be specified, this works from `bash` as mentioned in @yöliitäjä answer: `$sqlite3 database_name 'VACUUM;'` – Arnis Juraga Feb 19 '18 at 17:52
  • @VihaanVerma: It seems vacuuming tables not supported (on my SQLite v3.35.5 at least). When I run `VACUUM MyTable` it fails with message `Execution finished with errors. Result: unknown database MyTable`. – Mustafa Özçetin Aug 03 '23 at 11:34
26

Give the command like this:

$sqlite3 database_name 'VACUUM;'

As a matter of fact, this is the way to do also other queries from command line:

$sqlite3 database_name 'select * from tablename;'

You can use the full path to the db:

$sqlite3 /path/to/db/foo.db 'VACUUM;'
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
yöliitäjä
  • 261
  • 3
  • 3
19

Run the command:

VACUUM;

if you use DB Browser for Sqlite or

open Sqlite from command prompt:

cd C:\your_folder
C:\Users\your_user\AppData\Local\Android\Sdk\platform-tools\sqlite3.exe  -line your_db_name.db

and run

VACUUM;
live-love
  • 48,840
  • 22
  • 240
  • 204
0

Do double-click on the database file, it will run directly in the command line. Then just type VACUUM;

Ariel
  • 157
  • 1
  • 4
  • 18
0

With DB Browser for SQLite it is trivial. Open your database file with DB Browser for SQLite and execute the VACUUM command in the Execute SQL tab (Either press F5 or click the Execute button):

enter image description here

Mustafa Özçetin
  • 1,893
  • 1
  • 14
  • 16