Have you tried using [VACUUM INTO][1] to create a vacuumed copy of the original database? When the copy has been created, then just delete the original and rename the copy back into the original name. (NB: This will only work if the database is *not* being used simultaneously by some other process.) [1]: https://www.sqlite.org/lang_vacuum.html#vacuuminto