Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the effective way to compact sqlite3 db?

Tags:

sqlite

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?

like image 677
user938363 Avatar asked Nov 10 '22 13:11

user938363


2 Answers

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;
like image 100
Sándor Krisztián Avatar answered Jan 04 '23 02:01

Sándor Krisztián


I had success compacting my SQLite DB with VACUUM.

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

Updated: Before this anwer said VACUUM table_name

like image 34
palswim Avatar answered Jan 04 '23 01:01

palswim