What is the purpose of PRAGMA cipher_memory_security?

What is the right place to execute PRAGMA cipher_memory_security = OFF;?
Can I do it in onUpgrade method? So it will be executed only one time. Or I need to execute it each time I open a database.
Can you tell what exactly this pragma does and what is the drawbacks of setting is off.

Thanks for you help.

Aliaksandr Tabunou

Hello @aliaksandr.tabunou

PRAGMA cipher_memory_security allows the user to opt in/out of specific behaviors regarding memory management within SQLCipher.

When enabled, all memory allocated for the database (including that used for page cache, temporary storage, values) will be locked on allocation, bringing the virtual address space into RAM, preventing it from being written to a swap file. When memory is released, it will be unlocked and the block will be zeroed out prior to being freed.

When this feature is disabled, locking/unlocking of the memory address only occur for the internal SQLCipher data structures used to store key material, and cryptographic structures.

PRAGMA cipher_memory_security is enabled by default.

If you wish to disable cipher_memory_security on Android, it would likely be best performed with the preKey event of the SQLiteDatabaseHook.

Thanks a lot.

So if execute db.rawExecSQL(“PRAGMA cipher_memory_security = OFF”); only one time. Will it be OFF all other sessions.

I noticed if I execute this pragma statement my queries run faster about 40%. After restarting the app I needed to execute it again to make it work.

So we need to run the pragma statement each time we open a database? Correct me if I’m wrong.

Thanks for your help.

Aliaksandr Tabunou

Hello @aliaksandr.tabunou

Correct, you will need to execute that statement every time you create a database connection.

@developernotes Thanks for confirming it.