Page 1 of 1

Can i load a 10gb database with 8gb RAM?

Posted: Fri Jun 10, 2022 11:43 am
by Keya
Im relatively new to databases, im just wondering if I can load say a 10gb SQL dump (basically just "INSERT" statements) if i only have say 8gb of RAM? If not, how to approach this?

Re: Can i load a 10gb database with 8gb RAM?

Posted: Fri Jun 10, 2022 11:47 am
by infratec
It's not exactly clear what you want to do.
If you want to execute the content of the file, simply read it line by line and execute each line.
Or read and concat the lines until you find a ; at the end.

Re: Can i load a 10gb database with 8gb RAM?

Posted: Fri Jun 10, 2022 12:05 pm
by Keya
but can I execute each instruction of such a large database when the database is larger than my amount of RAM? does the database manage some sort of hard drive cache system?

Re: Can i load a 10gb database with 8gb RAM?

Posted: Fri Jun 10, 2022 12:31 pm
by NicTheQuick
That completely depends on the database you are using. It's not a Purebasic related question in my opinion.

Re: Can i load a 10gb database with 8gb RAM?

Posted: Fri Jun 10, 2022 1:10 pm
by ricardo_sdl
You probably can load the entire file in memory, but it will be really slow. The operating system will use memory paging a lot. You can use infratec's suggestion and read it line by line and do your inserts, this will probably work, but it will take a lot of time. Check your database documentation, it may have some tool or command that can read the file directly and faster than using a programming language in the middle.

Re: Can i load a 10gb database with 8gb RAM?

Posted: Fri Jun 10, 2022 1:13 pm
by Marc56us
Unless you are using an in-memory database (like :memory: for SQLite) there is of course no problem loading more data than the amount of RAM available. The SGBD engine will swap Ram/Disk if needed.

PS.
1. For large amounts of data, you can save a lot of time by using CSV loading (i.e. LOAD DATA INFILE) rather than a succession of INSERT statements. (Data part of SQL Dump must be formated for CSV import)
2. If the database is in AUTO-COMMIT (which is often the case) you also save time (a lot) by disabling it during the loading. This is done by forcing the single transaction
BEGIN; ... Loading the database ... COMMIT; (or ROLLBACK if it failed)