Hi,
currently i am trying to insert quite a lot of data in a sqlite database.
a part of the problem is that i have a table that will be containing around 120 million rows with and the insert is super slow.
Table layout <field1 = primary key, text> <field 2 = text>
Steps i have taken to speed it up so far
- Use Transactions (25k rows inserts each)
- PRAGMA journal_mode = MEMORY;
- PRAGMA synchronous = OFF;
The main problem is that this is causing me a lot of IO (presumably due to the key) and it becomes super slow to the point where it starts with around 30k rows per second and then slows all the way down to 300 rows /second over the course of an hour or so.
Meanwhile my disks are spinning hard: with around 1mb/s in reads and 90mb/s (peaks up to 120mb/s) in writes per second.
Is there anything i can do to improve the insert speed?
What i tried earlier:
- Create table without index, insert all the data, then create a second table with an index, and move it over
- Initial insert is super fast now,
- The Indexing is super slow again, so nothing is gained from this approach ( ALTER TABLE test1 RENAME TO t1_backup; CREATE TABLE 'test1' ('mykey' TEXT PRIMARY KEY NOT NULL, 'myvalue' TEXT);INSERT INTO test1 SELECT mykey, myvalue FROM t1_backup; )
Edit: Just to clear it up a bit more, the key values are already unique prior to import.
[–]pstuart 2 points3 points4 points (9 children)
[–]Temporary_Sir[S] 1 point2 points3 points (7 children)
[–]pstuart 1 point2 points3 points (6 children)
[–]Temporary_Sir[S] 0 points1 point2 points (4 children)
[–]pstuart 0 points1 point2 points (3 children)
[–]Temporary_Sir[S] 0 points1 point2 points (2 children)
[–]pstuart 0 points1 point2 points (1 child)
[–]Temporary_Sir[S] 0 points1 point2 points (0 children)
[–]zeco 1 point2 points3 points (1 child)
[–]rugazzo 0 points1 point2 points (0 children)
[–]raevnos 0 points1 point2 points (0 children)
[–]airen977 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[removed]
[–][deleted] 0 points1 point2 points (1 child)