piskvorky / sqlitedict

Persistent dict, backed by sqlite3 and pickle, multithread-safe.
Apache License 2.0
1.17k stars 131 forks source link

.terminate() failed to delete file xx.sqlite, clear() can not reset the file size... #42

Closed ClericPy closed 8 years ago

ClericPy commented 8 years ago

.terminate() raise an error for it's in use when del the file, and after clear() the file size is still as large as before(43MB, not 3KB). Indeed I prefer sqlitedict to tinydb...

piskvorky commented 8 years ago

Not sure I understand -- terminate() closes the connection and then attempts to delete the sqlite file.

What problem exactly are you reporting -- can you post the full log, at DEBUG level?

And also your OS, version of python, version of sqlitedict. Thanks!

ClericPy commented 8 years ago

Thanks for your answer & sorry for bother you... there is one python process is using that db and never be killed(maybe some sub-process), so it is not an issue any more. by the way, may I ask one more question, the file size didn't release after I used db.clear(), even it had nothing in.

piskvorky commented 8 years ago

Alright, closing this issue.

Regarding clear(): it clears (deletes) all rows in a table, but doesn't VACUUM the space. Basically sqlite does some internal optimizations and gradually re-uses the now-empty space, rather than removing it.

I think that the vacuum operation was sometimes causing trouble we though was unnecessary, so we don't call it by default from clear().

If you need the space, feel free to call VACUUM manually. Or delete/terminate the entire DB file and start from scratch.

ClericPy commented 8 years ago

You really did me a big favor, and I learned much from here, thanks conn=sqlite3.connect('xx.sqlite') conn.execute("VACUUM") conn.execute("VACUUM") conn.execute("VACUUM") conn.close() makes good

piskvorky commented 8 years ago

No problem. Enjoy!

Naeemkh commented 4 years ago

@ClericPy Thanks for the response. Is there any reason to execute the "VACUUM" three times. It seems one time does the work. Please let me know your thoughts.