7

After a few delete and insert, our sqlite3 was inflated from 300K to over 4MB. In Firefox sqlite3 manager, we open the db and compact it. There is no size change. Then we move the db file to a server which responses to sqlite3 command. We did (following post (by Lars Windolf) on VACUUM):

$sqlite3 /path/to/db/mydb.sqlite3 "VACUUM;"

However there is no size reduction at all. We are running out of ideas. What's the effective way doing compact of sqlite3?

halfer
  • 19,824
  • 17
  • 99
  • 186
user938363
  • 9,990
  • 38
  • 137
  • 303
  • Are you inserting crazy large BLOBs? – Graham Perks Feb 10 '14 at 04:19
  • no, just some short string records. – user938363 Feb 10 '14 at 04:29
  • 1
    Hmm. You could dump & recreate the DB, and see what happens. If the recreated one is just as large, go through the dump and see if there are any surprising objects in there. `echo '.dump' | sqlite3 mydb.sqlite > dump.sql` then `cat dump.sql | sqlite3 mydb2.sqlite`. – Graham Perks Feb 10 '14 at 04:37
  • Show the output of `sqlite3_analyzer`. – CL. Feb 10 '14 at 13:13
  • 1
    We end up export and import 2 tables (among of about 30) to a clean db and the size only increases by 50K (to 350K, the inflated one is over 4MB). We tried VACCUM & compact in sqlite3 manager and VACUUM in sqlite3 command line, none of them worked. Has no clue why VACUUM not working. – user938363 Feb 10 '14 at 16:58
  • I observed the database to grow when I used [a workaround for DROP COLUMN](https://stackoverflow.com/a/40184783/2932052). – Wolf Apr 11 '23 at 14:54

3 Answers3

5

From SQLite: https://www.tutorialspoint.com/sqlite/sqlite_vacuum.htm

You can compact table:

sqlite> VACUUM table_name;

Compact the whole database:

sqlite> VACUUM;

Set to compact automatically the full database, it shrinks when you have delete/update records:

sqlite> PRAGMA auto_vacuum = FULL;

Set to auto compact database, but must be manually activated:

sqlite> PRAGMA auto_vacuum = INCREMENTAL;
  • 1
    In my opinion, the better reference is the original SQLite documentation (→ [VACUUM](https://www.sqlite.org/lang_vacuum.html "VACUUM")) – Wolf Apr 11 '23 at 14:51
2

I had success compacting my SQLite DB with VACUUM.

sqlite3 /path/to/db/mydb.sqlite3 'VACUUM'

Updated: Before this anwer said VACUUM table_name

towi
  • 21,587
  • 28
  • 106
  • 187
palswim
  • 11,856
  • 6
  • 53
  • 77
  • 4
    I get `Error: unknown database FULL`. The [docs](https://www.sqlite.org/lang_vacuum.html) don't mention `FULL` either. I think the correct command is just `VACUUM` without arguments. – Thomas Jan 31 '21 at 09:24
-4

you install SQLiteDatabaseBrowser and File menu to compact .

see Img

Mr_Moradi
  • 354
  • 5
  • 9