in reply to SQLite database (or any) file in main memory!

Maybe creating a "filesystem" in memory, and "copy" file there?

That is called a ramdisk, just google for how to create one. On linux, you create it, and mount it to some mountpoint, then you can copy into it. However, you may NOT see any speed improvement, because if you have enough ram , the OS's memory management system will probably already keep the sqlite db file in memory, if it is used on a frequent basis. If you don't have enough ram, you shouldn't be using a ramdisk anyways.:-)

I asked a similar question when I first started, about putting perl and it's libs in a ramdisk, to improve speed. But I found that it was like above. It takes time for the OS to load it the first time, then after that, it keeps a copy in memory automatically, unless it is forced out by some other memory hog.


I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: SQLite database (or any) file in main memory!

Replies are listed 'Best First'.
Re^2: SQLite database (or any) file in main memory!
by tirwhan (Abbot) on Oct 06, 2005 at 14:25 UTC

    However, you may NOT see any speed improvement, because if you have enough ram , the OS's memory management system will probably already keep the sqlite db file in memory, if it is used on a frequent basis.

    While this is true for many databases and other applications, it is not really true for SQLite. SQLite does an fsync() after every transaction, thus flushing out the cache, then closes and reopens the file. You therefore lose a lot of the OS's caching benefits, because changes will be written out immediately and reread. See my other post further down on how to get around that (another option IIRC is to run SQLite in non-synchronous mode, but that's only useful if you don't care much about your data :-).

Re^2: SQLite database (or any) file in main memory!
by Ace128 (Hermit) on Oct 06, 2005 at 13:53 UTC
    Yes, this crossed my mind too! But I want control! :) Aka, KNOW its there! And Im also for a solution that works in Windows too! Thus, explicitly do it in Perl! (and not rely on some 3:rd part application, creating a Ramdisk...) But I guess the OS puts it there if used regularly.. (although it would be quite fonky to do this with Perl anyway :) )

      Take a look at this free ram disk. I've been using it (occasionally) for a couple of years now both on NT and XP without problems.

      Whether your application performance will benefit I don't know, but it very small and easy to install and it is certainly the easy option for what you are trying to do. It would take you less than 5 minutes to try it out.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.