C
C#•12h ago
reeeeeee

SQLite proper disposal when shutting down the app

I have a question regarding SQLite database and its WAL mode (making changes to separate file and checkpointing it when its enough). Is it possible to handle "forceful shutdown", like end process from task manager? (i have some API and windows services which are using the database). Or if there is some kind of database setting, that when you lose the last connection, the database gets automatically checkpointed to main file. Because I can't seem to find a way to do it, but with DB Browser for SQLIte (some kind of SQLIte IDE software, like SSMS for sql), if i end the process, the checkpoint happens, but I dont know how. Any idea what would be the best solution? I have osme kind of automatic checkpoint on "normal" shutdown, but thats kinda it... I hope you understand what I want to achieve 🙂
3 Replies
canton7
canton7•11h ago
If you "end process" in task manager that's it iirc - you're dead. Are you sure that DB Browser isn't just periodically checkpointing in the background? Also, do you need to checkpoint? I've used plenty of applications which just didn't checkpoint often at all (and if you wanted to back up the database, you also needed to backup the WAL, and that was documented and fine) (since sqlite is just an in-process library, there's no way to "checkpoint on connection close" in that sense - if the process is killed, that also kills all sqlite code, as it's running in-process) After all, the entire point of the WAL is so that if your process is unexpectedly killed, between the dabatase and the WAL you're still in a good state
reeeeeee
reeeeeeeOP•9h ago
I dont know about that, but it does clear all the files (shm, wal) after you stop it any way i would like to implement some kind of mechanism to always have the most latest data in main DB file - so if a client has a problem, they can simply send only .db file and dont worry about some cached infos yeah, i understand that I dont know what would be the best way mm, how do you mean in good state?
jcotton42
jcotton42•4h ago
Database not corrupted.

Did you find this page helpful?