Shared SQLite Database Sharing between Multiple Applications

It is possible to create an SQlite database in memory:

rc = sqlite3_open(":memory:", &db); 

but if I understood the documentation correctly, this database is local to the created application.

I have a requirement for an in-memory SQLite database that can be accessed by several applications. Besides creating a database in ramdisk, is there any way to do this?

This is for the embedded Linux platform.

+4
source share
3 answers

You cannot share a database in memory through processes - it really is not intended for this because it lacks the correct type of integrity promises (but that means it is faster) - so either put the database on a larger amount of constant storage (for example, ramdisk) or put the database in a single process ("database manager") and use some form of local communication strategy (unix domain sockets, named pipes, etc.) so that other processes can ask the database manager, to make APROSAM for them.

+4
source

No, you will need to create db on ramdisk / tmpfs if you want it to be in memory and share it with other applications.

+1
source

You can create a database (and cross process lock) in a process with the required lifetime in shared memory. All you have to do is treat it like any other shared memory resource (remembering to lock / unlock when accessing it). Unfortunately, I think this might require intervention with the SQLITE source to use the memory you provide (shared), rather than allocating it.

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/shm.h.html

0
source

All Articles