如何写入 SourceForge 项目网络空间中的 SQLite 数据库文件?

发布于 2024-09-29 04:24:52 字数 714 浏览 5 评论 0原文

我有一个基于 Perl 的小型 CGI 应用程序,正在为 SourceForge 项目提供的项目 Web 空间中运行。该应用程序将数据存储在 SQLite (v. 3) 数据库文件中。

当我从 shell 运行测试脚本时,我可以读取和写入此 SQLite 文件。然而,当 Apache 执行 CGI 代码时,它具有只读访问权限。写入操作会导致日志文件错误:

error.log.web-2:[Wed Oct 27 14:40:22 2010] [error] [client 127.0.0.1] DBD::SQLite::db do failed: unable to open database file

出于测试目的,我已将该 SQLite 文件的权限一直调到 777。没有区别。

然而,SourceForge 的项目网络空间有一些有趣的警告,我想知道我是否被这些问题绊倒了。一般来说,主 Web 服务器文件系统对于 Apache 来说是只读的。如果您有需要在运行时可写的文件,则应该将它们存储在其他地方的特殊“持久”目录中......并创建从您的网络空间到该目录下的实际文件的符号链接。

我已经完成了此操作,并且“持久性”位置下的符号链接和实际 SQLite 文件的权限都设置为 777。我知道这种机制通常是有效的,因为我对缓存和日志文件做了同样的事情,并且它在那里有效。

我想知道 SQLite 本身是否有什么奇怪的地方,比如它不想打开符号链接(而不是原始文件)进行写入。

I have a small Perl-based CGI application, which I am running in the project web space provided for a SourceForge project. This application stores data in a SQLite (v. 3) database file.

When I run test scripts from a shell, I can read from and write to this SQLite file. However, when the CGI code is executed by Apache, it has read-only access. Write operations result in a log file error:

error.log.web-2:[Wed Oct 27 14:40:22 2010] [error] [client 127.0.0.1] DBD::SQLite::db do failed: unable to open database file

For testing purposes, I have cranked the permissions for that SQLite file all the way up to 777. No difference.

However, there are some funny caveats to SourceForge's project web space, and I wonder if I'm being tripped up by that. Generally, the main web server filesystem is read-only to Apache. If you have files that need to be writable at runtime, you're supposed to store them in a special "persistent" directory elsewhere... and create symlinks from your web space to the actual files under that directory.

I have done this, and the permissions are set to 777 for both the symlink and the actual SQLite file under the "persistence" location. I know this mechanism works in general, because I'm doing the same thing with cache and log files and it works there.

I'm wondering if there's anything funky about SQLite itself, along the lines of it not wanting to open a symlink (rather than a raw file) for writing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀中猫帐中妖 2024-10-06 04:24:52

我相信这个问题的答案是做不到。对 SQLite 的进一步研究告诉我,驱动程序必须先获得数据库文件的锁,然后才能执行任何写入操作。当实际文件位于文件系统交叉安装的另一台计算机上时,无法获得这种类型的锁定。

我相信 SourceForge 项目网络空间托管就是这种情况。看起来(可写)“持久”目录实际上位于与只读 Web 服务器文件系统完全独立的计算机上。

简而言之,如果您因为遇到同样的问题而偶然发现这个问题...要么寻找不同的网络空间托管,要么可能是时候重新设计您的应用程序并升级到 MySQL 或其他一些数据库(无论如何,SourceForge 都会为您提供免费的 MySQL 托管)。

I believe the answer to this question is that it can't be done. Further research into SQLite tells me that the driver must get a lock on the database file before it can do any write operations. This type of lock cannot be obtained when the actual file is on a different machine with its filesystem cross-mounted.

I believe this is the case with SourceForge project web space hosting. It looks like the (writable) "persistent" directory is actually on a totally separate machine from the read-only web server filesystem.

In short, if you stumble across this question because you're having the same issue... either look for different web space hosting, or else it may be time to re-work your app and step up to MySQL or some other DB (SourceForge gives you free MySQL hosting anyway).

拒绝两难 2024-10-06 04:24:52

另一个问题是,如果您拥有特定数据库文件的权限,但无权在目录中创建临时文件。 (混合权限,或权限限制过多)

https://www.sqlite.org/tempfiles.html

如果无法写入临时文件,则无法对 sqlite 数据库文件进行任何写入。如果您将其切换到 :memory: 数据库,您可以通过或使用 @bob.faist PRAGMA temp_store = MEMORY 提到的编译指示,但实际上您应该在可能的情况下诊断并修复权限问题。

使用这些命令查看您是否有权在这些文件位置写入。

ls -l app.db
getfacl app.db
ls -l -d .  # check the directory to see if you can write the temp files there
getfacl .

使用 chmod 或 setfacl -m 修复文件或文件夹以便您对其进行写入。

另请检查您的磁盘空间。

df -k

如果它显示数据库文件所在的分区或正在尝试写入其文件的分区已满,您也可能会遇到此类问题。

希望有帮助。

Another issue is if you have permissions for the specific db file but you don't have permission to make the temporary files in the directory. (Mixed permissions, or too restrictive permissions)

https://www.sqlite.org/tempfiles.html

If you can't write the temporary files then you can't do any writes on a sqlite database file. If you switch it to a :memory: database you could get by or maybe use the pragma mentioned by @bob.faist PRAGMA temp_store = MEMORY, but really you should diagnosis and fix the permissions problem if possible.

Use these commands to see if you have permission to write in those file locations.

ls -l app.db
getfacl app.db
ls -l -d .  # check the directory to see if you can write the temp files there
getfacl .

Use chmod or setfacl -m to fix the files or folders to let you write to them.

Also check your diskspace.

df -k

If it shows that your partition where the database file is located or is trying to write its files to are full, you could also get these kinds of issues.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文