Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Do not use `cp` to back up SQLite databases. It is not transactionally safe.

Anyone know if comitting the sqlite db file to git is not safe either?



If you’re not actively writing to the database you can cp or commit it safely. SQLite uses a journal or a write ahead log (WAL) file to process transactions.

If you cp a database mid transaction you will loose the transaction as it is processed in the separate journal or WAL file until commit. If you copy mid commit then you will have incomplete data in the main database file and possibly data corruption.


Anything that only uses the file system copying mechanics is not safe (which includes a git check-in). I wrote a more detailed comment here: https://news.ycombinator.com/item?id=31387447




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: