SQLite3的数据库文件突然断电或者操作系统崩溃会损坏吗?
我使用sqlite3的open()方法打开数据库文件并获取数据库连接,直到程序退出该连接才会关闭。如果出现意外错误,如计算机突然断电、操作系统崩溃等,数据库文件的模式是否会被破坏,或者句柄丢失?更具体地说,如果我重新启动计算机,它还能保持可写吗?顺便说一句,我不关心发生错误时的数据丢失。
非常感谢!
I open the database file and obtain a database connection using open() method of sqlite3 and the connection will not be closed until program exits. If there occurs an unexpected error such as computer's suddenly power-off or OS crash, will the mode of the database file be damaged, or its handle lost? More specifically, can it remain writable if I reboot my computer? BTW, I don't care about the data loss when errors occurs.
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SQLite 是专门为防止这种情况而设计的。从官方 SQLite is Transactional 页面:
您可能还对 SQLite 文章SQLite 中的原子提交感兴趣,如果您需要了解它们如何防止上述崩溃的具体细节。
Regarding writing after a crash: (from File Locking and Concurrency)
最糟糕的情况是您需要删除崩溃后留下的热日志。
SQLite is specifically designed to protect against this. From the official SQLite is Transactional page:
You might also be interested in the SQLite article Atomic Commit in SQLite if you need to know the specific details on how they protect against crashes such as the above.
Regarding writing after a crash: (from File Locking and Concurrency)
The worst that can happen will be that you need to delete the hot journal that is left over after a crash.
由于 Sqlite 符合 ACID,因此关闭电源不应该成为问题。
http://en.wikipedia.org/wiki/ACID
As Sqlite is ACID-compliant, a power-off shouldn't be an issue.
http://en.wikipedia.org/wiki/ACID
突然断电可能会发生任何事情。不过,我建议 UPS 降低任何风险。
anything could potentially happen on sudden power off. However I'd suggest UPS to mitigate any risk.