Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!
Background:
Several tips:
pragma journal_mode
). There is NORMAL
, and then there is OFF
, which can significantly increase insert speed if you're not too worried about the database possibly getting corrupted if the OS crashes. If your application crashes the data should be fine. Note that in newer versions, the OFF/MEMORY
settings are not safe for application level crashes.PRAGMA page_size
). Having larger page sizes can make reads and writes go a bit faster as larger pages are held in memory. Note that more memory will be used for your database.CREATE INDEX
after doing all your inserts. This is significantly faster than creating the index and then doing your inserts.INTEGER PRIMARY KEY
if possible, which will replace the implied unique row number column in the table.I've also asked similar questions here and here.