如果我保持与数据库的连接,是否必须安装文件系统?
我正在使用 sqlite 访问我的数据库,并且我始终保持连接打开。
我收到了卸载存储数据库的磁盘的新请求。问题是,我必须关闭连接吗?或者仅仅关闭数据库就足够了?
I am using sqlite to access my database, and I keep the connection open all the time.
I got new request to unmount the disk where the db is stored. The question is, do I have to close the connection? Or is it enough just to close the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您使用的框架。对于 SQLite 本身来说,关闭数据库就足够了。在此之前,请确保您已完成所有交易。
我想您正在使用某种框架,因为 SQLite 本身没有 disconnect 功能或方法。它只有一个close方法,如果您在框架中close或disconnect,该方法可能会自动调用。
当然,SQLite 是一个基于文件的数据库。所以无论如何,不存在“联系”这样的东西。
That depends on the framework you are using. For SQLite itself it should be enough to close the database. Just make sure you have finished all transactions before you do so.
I suppose you are using some framework, since SQLite itself does not have a disconnect feature or method. It just has a close method which is probably called automatically if you either close or disconnect in your framework.
Naturally, SQLite is a file-based database. So there is no such thing as a "connection", anyway.
SQLite 的连接对应于一个打开的文件(或者更多,如果有一个事务日志打开的话;当我在这里尝试并使用 lsof 进行探测时,我得到了另外两个打开的 FD,一个用于日志,一个用于日志)包含目录),因此当任何与数据库的连接打开时,您无法卸载文件系统;操作系统将拒绝并告诉您它正忙。卸载托管数据库的文件系统的唯一方法是首先关闭与数据库的所有连接。
SQLite's connections correspond to an open file (or more, if there's a transaction journal open; when I try that here and probe with
lsof
, I get an additional two FDs open, one for the journal and one for the containing directory) so while any connection to the database is open, you cannot unmount the filesystem; the OS will refuse and tell you that it's busy. The only way to unmount the filesystem that is hosting the database is to close all connections to the database first.