sqlite3 db update extremely slow

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Mon Jul 16 16:21:03 EDT 2007


coldpizza schreef:
> I am trying to fill a sqlite3 database with records, and to this end I
> have written a class that creates the db, the table and adds rows to
> the table.
> 
> The problem is that the updating process is *extremely* slow, and
> occasionally I get the message "database locked".
> 
> I tried removing "self.con.commit()" in the add_record method, but
> then nothing is saved in the db. I don't know whether this has
> anything to do with it, but I have found no option to enable
> autocommit.

Remove self.con.commit() from add_record(), and do it once after all 
records are added.

The reason that the process is slow with a commit after every INSERT is 
that sqlite syncs the inserted data to disk before it continues.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Python-list mailing list