Home > Back-end >  it is possible to stop creating .db-shm and .db-wal files in sqlite database android?
it is possible to stop creating .db-shm and .db-wal files in sqlite database android?

Time:09-21

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?

CodePudding user response:

i wondering if it is possible through code in android?

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.

  • I would suggest that this is the better option. It caters for WAL or JOURNAL mode and a single backup file.

There is also the option to save the -wal and -shm files.

  • Related