We have a simple application built with Couchbase. Our problem is that when purging all documents the sqlite database remains more or less the same size, why is this? We are using Couchbase Lite 2.1.3 (Swift)
Here is what we do:
We have a Couchbase server with 40k documents (no attachments).
We launch the application with a user that subscribes on all channels so everything is synchronised. The database size (not the WAL or shm but the other one named only sqlite3) is 115Kb before the synchronisation and around 80mb after.
We stop the replicator, purge all documents and compact, change the users channels to subscribe on NO channels and then we start the replicator again. This all seems to work fine. When looking at the database through a sqlite software, all documents are gone but the sqlite file is still 80 mb.
Why is this and what can we do? We really do not want to delete the database.
The freelist_count is not less than 1/4 of the result of page_count, they are almost the same.
The select count(*) matches though, they are both 0.
What we do in the code is the following:
purge all documents
We have tried to use db.close as well after the compact but it makes no difference. We do not want to use the close method but we did try it. Anyways, after this we just close the application in the simulator and Xcode but and the file size remains…
We did try to open the sqlite3.db file with a software called DB Browser for SQLite. In this software there is a compact functionality. After using that and closing the software the file size shrinked. So I am guessing we are doing something wrong in Xcode or that the method don’t work properly… Any ideas?
That’s weird; after the compact or close, LiteCore should have run incremental_vacuum, which should have removed the free pages and shrunk the file. (You can see the source code here, if you’re curious.)
The SQLite docs say that PRAGMA incremental_vacuum “causes up to N pages to be removed from the freelist. The database file is truncated by the same amount. … if the “( N )” argument is omitted, then the entire freelist is cleared.” So afterwards the database file should be very small.
You could try entering the same pragma into the DB Browser app and see what happens…