Google is committed to advancing racial equity for Black communities. See how.

Compatibility WAL (Write-Ahead Logging) for Apps

Android 9 introduces a special mode of SQLiteDatabase called Compatibility WAL (write-ahead logging) 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 application's database by default unless the application 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 filesystem, WAL can lead to a 4x improvement in write speed.

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

Disabling 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 does not provide a performance advantage over traditional rollback journal modes. For example, on a F2FS filesystem, 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%.

Validation

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.