This question already has an answer here:
I have a 100 mega bytes sqlite db file that I would like to load to memory before performing sql queries. Is it possible to do that in python?
Thanks
This question already has an answer here:
I have a 100 mega bytes sqlite db file that I would like to load to memory before performing sql queries. Is it possible to do that in python?
Thanks
If you are using Linux, you can try tmpfs which is a memory-based file system.
It's very easy to use it:
Remember, anything in tmpfs will be lost after reboot. So, you may copy db file back to disk if it changed.
Note that you may not need to explicitly load the database into SQLite's memory at all. Simply prime your operating system disk cache by copying it to null.
This has the advantage of the operating system taking care of memory management, especially discarding it if something more important comes along.
Here's an example (taken from here) in Tcl (could be useful for getting the general idea along):
apsw is an alternate wrapper for sqlite, which enables you to backup an on-disk database to memory before doing operations.
From the docs:
connection
above is your on-disk db.