sqlite: Optimize the DB and the files sizes #4602
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
VACUUM
on theSqliteStateStore
. We should have done this when we moved the media cache toSqlitEventCacheStore
, to defragment the file and reduce its size on the filesystem. Because of that there are databases from that time that still take much more space than they need.PRAGMA optimize
after running the eventual migrations. The SQLite docs recommend to do this regularly, especially after a schema change. Doing this consistently during construction seems to be the easiest solution.VACUUM
which basically writes the content of the DB file to the WAL file before writing it back to the DB file, so we end up taking twice the size of the database. The docs say that the WAL file is written to the database when it reaches 4MB, so 10MB seems like a good limit that shouldn't truncate the file too often.