Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compress sqlite database

I have a sqlite database in my offline app that has reached 32mb. Its created from asset files on launch which are 6mb in size.

Is there any built in compression function that permenantly causes the database to become smaller, I dont mind the performance hit while reading. It would then use less of the users phone memory.

Any ideas?

The DB has two tables which are mostly long text fields. The size is the end result of 7000+ inserts upon first application launch.

like image 697
sprocket12 Avatar asked Nov 14 '13 15:11

sprocket12


People also ask

Can you compress SQLite database?

The SQLite Compressed and Encrypted Read-Only Database (CEROD) Extension is an add-on to the public domain version of SQLite that allows an application to read compressed and encrypted database files in addition to ordinary SQLite database files.

How do I limit the size of a SQLite database?

The maximum string or BLOB length can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_LENGTH,size) interface. The SQLITE_MAX_COLUMN compile-time parameter is used to set an upper bound on: The number of columns in a table. The number of columns in an index.

Why is SQLite not scalable?

SQLite's scalability is limited and only appropriate for smaller databases. Since the platform does not have any user management facility, it is not suitable for multiple user access. For larger files, the memory requirement singificantly increases for SQLite DB.

What does VACUUM do SQLite?

The VACUUM command works by copying the contents of the database into a temporary database file and then overwriting the original with the contents of the temporary file. When overwriting the original, a rollback journal or write-ahead log WAL file is used just as it would be for any other database transaction.


2 Answers

You could try using VACUUM on your database. See the SQLite doc here : http://www.sqlite.org/lang_vacuum.html

like image 55
SolarBear Avatar answered Sep 22 '22 12:09

SolarBear


CEVFS: Compression & Encryption VFS for SQLite 3

CEVFS is a SQLite Virtual File System which uses its own pager and is inserted between the pager used by the b-tree (herein referred to as the upper pager) and the OS interface. This allows it to intercept the read/write operations to the database and seamlessly compress/decompress and encrypt/decrypt the data.

like image 36
Dennis V Avatar answered Sep 18 '22 12:09

Dennis V