Compatibility write-ahead logging for apps

Android 9 introduces a special mode of SQLiteDatabase called Compatibility write-ahead logging (WAL) that allows a database to use journal_mode=WAL while preserving the behavior of keeping a maximum of one connection per database.

Compatibility WAL is enabled for an app's database by default unless the app has either:

  1. Opted-in or out of write-ahead logging by calling SQLiteDatabase.enableWriteAheadLogging or disableWriteAheadLogging
  2. Explicitly requested journal mode by calling SQLiteDatabase.OpenParams.setJournalMode(String mode)

Enabling the WAL journal mode can lead to a significant improvement in performance and reduction in the amount of writes. For example, on an ext4 file system, WAL can lead to a 4x improvement in write speed.

Compatibility WAL is enabled by default and doesn't require any additional implementation.

Disable Compatibility WAL

To disable the Compatibility WAL mode, overlay the db_compatibility_wal_supported config resource.

For example:

<bool name="db_compatibility_wal_supported">false</bool>

You may want to disable Compatibility WAL for configurations where the WAL journal mode doesn't provide a performance advantage over traditional rollback journal modes. For example, on a F2FS file system, although SQLite supports atomic writes and the DELETE journal performance is similar to WAL, WAL can increase the amount of writes by 10% to 15%.


To validate the Compatibility WAL mode, run CTS tests from the CtsDatabaseTestCases module. CTS tests will verify the expected behavior when Compatibility WAL is enabled.