skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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…

    @Override
        public void onOpen(SQLiteDatabase db) 
    {
            super.onOpen(db);
            db.disableWriteAheadLogging();
    }
    
    • I have solved problems like this way and surely will work in your case as well.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search