

If you aren't using explicit BEGIN/ COMMIT, you're still creating transactions, one per SQL statement. It takes an unfinalized transaction to do that. It's unnecessary because VACUUM will still run if there's simply an idle connection to the DB. If you literally mean that you sqlite3_close() the conn after each query, it's both unnecessary from the point of view of this question and it'll also slow SQLite down considerably. even though I try to close all readers right away. Once a month or once a year might suffice.
Sqlite vacuum manual#
In such cases, you'd schedule the VACUUM for manual downtime, such as during upgrades.įrequent VACUUM isn't super useful in a lot of apps anyway. You might not be allowed to lock the whole system up for arbitrarily long times. If you can never predict a time when the DB will be idle, you might not want to VACUUM automatically at all, since it can take a long time, and such always-in-use apps generally have tight service levels. in an always-running app serving a single regional organization App startup time, before any of these other threads start.

Sqlite vacuum update#
UPDATE 1) is not relevant - looks like I'm facing some cascade delete problems (I've described them in this topic).I continuously get an error when I run VACUUM that some statements are still running. Shouldn't it be real number of affected rows? That is not what I expected? Shouldn't it be ~23.6 mb as the original database was? !NOT RELEVANT FOR NOW!Ģ) For some reason rowsAffected equals 0 even if I use two cmd.ExecuteNonQuery() one after another - first one slightly shrinks database from 47.3 mb to 45.7 mb, second one leaves it's size unchanged).


After VACUUM command second database becomes 45.7 mb. Var rowsAffected = cmd.ExecuteNonQuery() ġ) I have sample.db (23.6 mb) and sample_big.db (47.3 mb) which contains the same data (second database is a copy of first database where all objects were deleted and added again). Using (SQLiteCommand cmd = conn.CreateCommand()) Code: Select all using (SQLiteConnection conn = new SQLiteConnection(mySQLiteConnectionStringBuilder.ToString()))
