在带有-journal文件的只读文件系统上打开sqlite3 DB [英] Opening a sqlite3 DB on a read-only filesystem with a -journal file

查看:373
本文介绍了在带有-journal文件的只读文件系统上打开sqlite3 DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sqlite3数据库,我需要读取(而不是写入)在一个只读文件系统上.还有一个与数据库关联的-journal文件,这会干扰打开数据库,因为sqlite代码要做的第一件事就是删除该-journal文件,而不能,因为文件系统是只读的.将journal_mode设置为off无济于事,因为这显然仅适用于新事务.有没有办法让sqlite3完全忽略所有与数据库相关的-journal文件的提及?

I've got a sqlite3 DB that I need to read (not write) sitting on a read-only filesystem. There is also a -journal file associated with the database, which is interfering with opening the database because the first thing the sqlite code wants to do is delete that -journal file and it cannot because the filesystem is read-only. Setting the journal_mode to off doesn't help because that apparently only applies to new transactions. Is there a way to tell sqlite3 to simply ignore all mention of a -journal file associated with a DB?

推荐答案

不幸的是.

问题是日记文件的存在表明事务处于不完整状态,需要通过将日记文件的内容传输回数据库文件来回滚.

The problem is that the existence of a journal file indicates that a transaction was left in an incomplete state, and needs to be rolled back by transferring the content of the journal file back into the database file.

这需要对文件系统的写访问权,并且SQLite不允许您在不执行此回滚的情况下打开文件.

This requires write access to the file system, and SQLite will not allow you to open the file without performing this rollback.

您可以在此处详细了解以下内容:只读数据库:

You can read more about this here: Read-Only Databases:

如果SQLite数据库位于只读介质上并且需要恢复,则任何SQLite数据库(无论是否为WAL模式)都不可读.因此,例如,如果应用程序崩溃并使SQLite数据库留下热日志,则除非打开过程对数据库文件,包含数据库文件的目录和热日志具有写特权,否则无法打开该数据库.这是因为从崩溃中遗留下来的未完成的事务必须在读取数据库之前回滚,并且如果没有对所有文件和包含它们的目录的写许可,就不会发生回滚.

No SQLite database (regardless of whether or not it is WAL mode) is readable if it is located on read-only media and it requires recovery. So, for example, if an application crashes and leaves an SQLite database with a hot journal, that database cannot be opened unless the opening process has write privilege on the database file, the directory containing the database file, and the hot journal. This is because the incomplete transaction left over from the crash must be rolled back prior to reading the database and that rollback cannot occur without write permission on all files and the directory containing them.

如果您不关心丢弃日记文件可能导致的损坏,则可以制作数据库文件的副本,并将日记留在后面.但是,如果您有能力执行此操作,实际上我也可以将日志文件也复制到可写文件系统中,然后照常打开该数据库,这样可以正确地回滚事务.

If you don't care about the possible corruption that discarding the journal file might lead to, you can make a copy of the database file, and leave the journal behind. Though, if you have the ability to do that, I would in fact copy the journal file too, to a writable file system, and open that database as normal, which would roll back the transaction properly.

尽管只读文件系统上的副本在当前状态下不可用.

The copy on the read-only file system though is not usable in its current state.

这篇关于在带有-journal文件的只读文件系统上打开sqlite3 DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆