可以在NFS文件系统上锁定sqlite文件吗?

[英]Locking sqlite file on NFS filesystem possible?


Let's say there are two python scripts that want to write data to the same table which is stored in an SQLite file using the sqlite3 module. The SQLite-file is stored on an NFS filesystem. In the SQLite-FAQ I read:

假设有两个python脚本想要将数据写入同一个表,该表使用sqlite3模块存储在SQLite文件中。 SQLite文件存储在NFS文件系统中。在SQLite-FAQ中我读到:

SQLite uses reader/writer locks to control access to the database. [...] But use caution: this locking mechanism might not work correctly if the database file is kept on an NFS filesystem. This is because fcntl() file locking is broken on many NFS implementations. You should avoid putting SQLite database files on NFS if multiple processes might try to access the file at the same time.

SQLite使用读取器/写入器锁来控制对数据库的访问。 [...]但请注意:如果数据库文件保存在NFS文件系统上,则此锁定机制可能无法正常工作。这是因为许多NFS实现都会破坏fcntl()文件锁定。如果多个进程可能同时尝试访问该文件,则应避免将SQLite数据库文件放在NFS上。

Does this mean it is not possible at all or is there some way to ensure that one process waits until the other is done?

这是否意味着它根本不可能或者是否有某种方法可以确保一个进程等到另一个进程完成?

The INSERTs are not complex. Just some:

INSERT并不复杂。一些:

INSERT_STATEMENT = "INSERT INTO some_table (row, col, val) VALUES (?, ?, ?)"
connection.executemany(INSERT_STATEMENT, triples)

And the inserted sets are disjoint.

并且插入的集合是不相交的。

A further question: Does the NFS-Problems occure when two processes try to write to the same table or when they try to write to the same database (which is a file)? Would it be a workaround to let each process create its own table in the same database (file) and write to that?

还有一个问题:当两个进程尝试写入同一个表或尝试写入同一个数据库(即文件)时,是否会出现NFS问题?让每个进程在同一个数据库(文件)中创建自己的表并写入该表是否是一种解决方法?

1 个解决方案

#1


19  

Do not use SQLite with NFS. It is as simple as that. NFS semantics are different than regular filesystems and are looser. You will eventually get corruption. Every now and then someone on the SQLite-users mailing list posts with their "workarounds". They never work although they appear to in the short term.

不要将SQLite与NFS一起使用。它是如此简单。 NFS语义与常规文件系统不同,并且更宽松。你最终会腐败。 SQLite用户邮件列表中的某个人偶尔发布他们的“变通办法”。他们从不工作,虽然他们似乎在短期内。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2012/03/28/720273d1897edc9185d6906ada3a51fb.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告