Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite Journal behaviour changed?

I had the idea that the SQLite journal would only remain in the filesystem while there were pending operations.

However, it seems to me that at least in Android 4.1+, the normal behaviour is for the SQLite journal to remain in the filesystem, even after setting a transaction as successful / ended, and even closing the Database.

Does someone have an idea on why and when this behaviour changed?

like image 802
pandre Avatar asked Mar 17 '23 10:03

pandre


1 Answers

@CL is right, the journal mode seems to change depending on the API level (maybe it changes too by manufacturer?).

However, for future reference, I've queried the database for the journal_mode in several API levels and the results are:

  • Android 2.3.7 (API 10) = delete
  • Android 4.0.4 (API 15) = truncate
  • Android 4.1.1 (API 16) = persist
  • Android 4.3.0 (API 18) = persist
  • Android 4.4.4 (API 19) = persist
  • Android 5.0.0 (API 21) = persist
  • Android 5.1.0 (API 22) = persist

Code for getting the journal mode:

Cursor c = db.rawQuery("PRAGMA journal_mode;", null);
c.moveToFirst();
String journalMode = c.getString(c.getColumnIndex("journal_mode"));

About the journal modes:

The DELETE journaling mode is the normal behavior. In the DELETE mode, the rollback journal is deleted at the conclusion of each transaction. Indeed, the delete operation is the action that causes the transaction to commit.

The TRUNCATE journaling mode commits transactions by truncating the rollback journal to zero-length instead of deleting it. On many systems, truncating a file is much faster than deleting the file since the containing directory does not need to be changed.

The PERSIST journaling mode prevents the rollback journal from being deleted at the end of each transaction. Instead, the header of the journal is overwritten with zeros. This will prevent other database connections from rolling the journal back. The PERSIST journaling mode is useful as an optimization on platforms where deleting or truncating a file is much more expensive than overwriting the first block of a file with zeros.

More info

like image 77
pandre Avatar answered Mar 29 '23 12:03

pandre