i want to stop creating .db-shm
and .db-wal
files. i only want .db
files in database folder of my data directory.
some older device generate .db-shm
and .db-wal
while some latest device generate .db-journal
.
this things create problem while I am trying to backup/restore my database file.
i wondering if it is possible through code in android?
2
Answers
Yes it is possible.
You can force Journal mode (this uses the -journal file BUT with journal mode the additional file contains a log of the changes made so the file is not needed (only used for rolling back)) by using the SQLiteDatabase’s disableWriteAheadLogging method (I would suggest doing this in the onOpen method if using a subclass of SQLiteOpenHelper.)
You can also use the SQLite’s journal_mode PRAGMA (again I would suggest in the onOpen method if using a subclass of SQLiteOpenHelper.)
Another option would to keep WAL mode but to ensure that the database is fully checkpointed. Closing the database should fully checkpoint the database and then if the -wal file still exists, it should be empty, in which case it is not required.
There is also the option to save the -wal and -shm files.
Yes, It’s possible to stop creating both .wal and .shm files. One thing observed is that up to the Android 9 version the System creates .wal and .shm with original .db file and in Android 10 or latest versions such files do not exist but have a new file called with the extension .journal.
To Stop creating files like .wal and .shm, Simply add method in your SQLite helper class as…