Hi,
For those who are interested in my use case, you may read this part or skip it:I need to create a huge DB (300 mb right now, and this is only some test data. Not at least close to all the Data). To create this DB I read a CSV file with information that need to be parsed for my needs. I handle all the DB action with ORMLite (http://ormlite.com/). The creation of this DB on the filesystem needs increadibly long (like forever, I stopped after half an hour). The in-memory will handle it in ~5 minutes. So it will be really important for me to create the DB in-memory. The DB needs to be reloaded every 1 or 2 weeks, over the weekend, so it should be finished within a day. But the created Data has to be used from other programms, so it won't be very clever to use it in-memory.
is there a possibility to save a h2 in-meory DB to the filesystem and read it like a regular h2 file DB ? The best would be to do all this with ORMLite, but this isn't really that important to me.
With best regards Robin--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/eQfeJqHE07EJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
Can you do a script to, then create it again as a file based database off the script?
Or what about creating it as a file based db, but on a ram disk, then copy to actual filesystem once created?
To unsubscribe from this group, send email to h2-database+unsubscribe@googlegroups.com.
First I'd recommend trying to optimize the on-disk approach - that way you don't have to deal with/worry about persistence.
If it still doesn't perform well - the in memory database can be spooled off to disk with the SCRIPT TO:
SCRIPT TO 'file.gz' COMPRESSION GZIP;
and restored with:
RUNSCRIPT 'file.gz' COMPRESSION GZIP; (Or using org.h2.tools.RunScript)
Or what about creating it as a file based db, but on a ram disk, then copy to actual filesystem once created?
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/ZlyM-Gc9xjsJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
It sounded from the original post as if you'd already created an in memory/embedded database with something like jdbc:h2:mem: and populated it via CSVREAD(). After it's populated, you can use SCRIPT TO statements from inside your database to send the data in the in-memory database out to a file which can later be used to restore the data into another H2 database that is file based.
On modern Linux kernels you can simply place your file under /dev/shm
And on Windows you can use DataRam's RAMDisk.The free version can create disks up to 4Gig. It can also auto backup to a physical file at customizable intervals and reload it on startup. Quite nice.
"the created Data has to be used from other programms, so it won't be very clever to use it in-memory"I hear:
- It needs to be persisted and made available - either by using a file or allowing others to connect to it? Based on the next comment, I presume a file that you can pass around or others will come get.
"is there a possibility to save a h2 in-memory DB to the filesystem and read it like a regular h2 file DB"
- Not directly. You can:
a.) Backup from in memory to a file, then restore that file into a new file based (Non - in memory) database that you create. then either give others access to the file, or...
b.) Make the in memory database, or subsequently restored-to-file-based-database accessible over the network from h2 jdbc clients by using org.h2.tools.Server instead of embedded mode H2
c.) depending on the complexity of the data and how you want to share it ... use sql statement CSVWRITE()
Also - one more thing I remembered - if you're doing CREATE TABLE AS SELECT STUFF FROM CSVREAD(); - H2 creates enourmously long varchar column types by default (cuz it doesn't know how long the data _could_ be). It's often more appropriate to pre-create your table with sane datatypes/lengths and then INSERT INTO YOURTABLE (FIELDLIST) SELECT FIELDLIST FROM CSVREAD(), then index/analyze the table according to your subsequent operations on it.