# setWriteAheadLoggingEnabled method not available in Sqlcipher for Android

**URL:** <https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529>\
**Category:** Issues\
**Created:** [April 16, 2015, 11:32am UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529 "2015-04-16T11:32:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinay\_kumar](https://avatars.discourse-cdn.com/v4/letter/v/59ef9b/32.png) [@vinay\_kumar](https://discuss.zetetic.net/u/vinay_kumar)\
**Post date:** [April 16, 2015, 11:32am UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/1 "2015-04-16T11:32:19Z")

</div>

Hi @developernotes

I see that

```
writableDatabase.beginTransactionNonExclusive(); setWriteAheadLoggingEnabled(true);

```

are not available as part of Sqlcipher for Android, but Is there any specific reason why these methods are not available as we are using them in our exisitng project for concurrent transactions. I suspect there could be performance issues as we are dealing with multiple of thousands of records. Please suggest

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [April 16, 2015, 12:57pm UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/2 "2015-04-16T12:57:59Z")

</div>

Hello @vinay_kumar

The `SQLiteDatabase::beginTransactionNonExclusive()` and `SQLiteOpenHelper::setWriteAheadLoggingEnabled()` methods were added in API 11, SQLCipher for Android uses an older snapshot of the `android.database.sqlite` package which allows for targeting down to Android 2.1. You can manually invoke these via SQL commands using `rawExecSQL`.

---

<div class="post-metadata">

**Author:** ![vinay\_kumar](https://avatars.discourse-cdn.com/v4/letter/v/59ef9b/32.png) [@vinay\_kumar](https://discuss.zetetic.net/u/vinay_kumar)\
**Post date:** [April 17, 2015, 5:34am UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/3 "2015-04-17T05:34:24Z")

</div>

> [@developernotes](#):
>
> beginTransactionNonExclusive()

oh okay. Thanks for the tip.

---

<div class="post-metadata">

**Author:** ![AVD](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@AVD](https://discuss.zetetic.net/u/AVD)\
**Post date:** [April 30, 2015, 10:22am UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/4 "2015-04-30T10:22:27Z")

</div>

Please confirm that

`beginTransactionNonExclusive()`; is equivalent to

```
rawExecSQL("PRAGMA database.locking_mode = NORMAL");`  

```

and

`setWriteAheadLoggingEnabled()` is equivalent to

```
rawExecSQL("PRAGMA journal_mode=WAL;");
```

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [April 30, 2015, 12:59pm UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/5 "2015-04-30T12:59:20Z")

</div>

Hello @AVD

In this case it is best to verify the source to understand the behavior of a different library. It appears that `beginTransactionNonExclusive()` ends up calling [this](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/database/sqlite/SQLiteSession.java#SQLiteSession.beginTransaction%28int%2Candroid.database.sqlite.SQLiteTransactionListener%2Cint%2Candroid.os.CancellationSignal%29), so they are issuing a `BEGIN IMMEDIATE;` command. The call to `setWriteAheadLoggingEnabled()` appears to end up calling [this](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/database/sqlite/SQLiteConnection.java#SQLiteConnection.setJournalMode%28java.lang.String%29) with a value of `WAL`.

---

<div class="post-metadata">

**Author:** ![nura\_zhakenger](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@nura\_zhakenger](https://discuss.zetetic.net/u/nura_zhakenger)\
**Post date:** [September 14, 2018, 10:33am UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/6 "2018-09-14T10:33:38Z")

</div>

Hi, @developernotes  
I too use SqlCipher and GreenDao as a ORM. Now I can’t enable Write Ahead Logging mode. SqlCipher and GreenDao haven’t `enableWriteAheadLogging()` function. And I checked 2 variants:

1. `rawExecSQL("PRAGMA journal_mode=WAL;");`  
but I get an exception that

> cannot change into wal mode from within a transaction: PRAGMA journal\_mode = WAL  
> i.e i can’t execute PRAGMA command in transaction.

1. `setWriteAheadLoggingEnabled(true);` function of OpenHelper. But it doesn’t help.  
Or Do I do something incorrect? How can i enable wal mode? Help, please!

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [September 14, 2018, 2:23pm UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/7 "2018-09-14T14:23:49Z")

</div>

Hi @nura_zhakenger

If you are using the current released version of SQLCipher for Android, you can just execute the following:

```auto
PRAGMA journal_mode = wal;

```

However, as you mentioned, you will not be able to do this while you are in a transaction. You might consider using the `SQLiteDatabaseHook::postKey` operation to enable WAL mode following the opening of a database connection.

We will be including [direct API support for enabling WAL mode](https://github.com/sqlcipher/android-database-sqlcipher/blob/master/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java#L668) in the next release of SQLCipher for Android.

---

<div class="post-metadata">

**Author:** ![nura\_zhakenger](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@nura\_zhakenger](https://discuss.zetetic.net/u/nura_zhakenger)\
**Post date:** [September 20, 2018, 10:41am UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/8 "2018-09-20T10:41:44Z")

</div>

Hello, @developernotes. Thanks for feedback! I tried through `SQLiteDatabaseHook::postKey` and works fine! After test I noticed that it works when database file is exists and while opening of a database, but when database file doesn’t exists and while creating it I get exception that database is locked at the line: database.rawExecSQL(“PRAGMA journal\_mode = WAL”);

---

<div class="post-metadata">

**Author:** ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)\
**Post date:** [September 20, 2018, 8:51pm UTC](https://discuss.zetetic.net/t/setwriteaheadloggingenabled-method-not-available-in-sqlcipher-for-android/529/9 "2018-09-20T20:51:51Z")

</div>

Hi @nura_zhakenger

Are you able to run the SQLCipher for Android [test suite](https://github.com/sqlcipher/sqlcipher-android-tests)? We have several tests that operate under WAL mode and verify behavior, such as [this](https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/app/src/main/java/net/zetetic/tests/ReadWriteWriteAheadLoggingTest.java) for example. Does that behavior differ from the way your application operates? Keep in mind, our call to `enableWriteAheadLogging` is really [adjusting](https://github.com/sqlcipher/android-database-sqlcipher/blob/master/android-database-sqlcipher/src/main/java/net/sqlcipher/database/SQLiteDatabase.java#L668) the journal mode similar to what you have above.
