可以在NFS文件系统上锁定sqlite文件吗? [英] Locking sqlite file on NFS filesystem possible?

查看:102
本文介绍了可以在NFS文件系统上锁定sqlite文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

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.

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

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?

INSERT不复杂.只是一些:

The INSERTs are not complex. Just some:

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

插入的集合是不相交的.

And the inserted sets are disjoint.

另一个问题:当两个进程试图写入同一表或试图写入同一数据库(文件)时,是否会发生NFS问题?让每个进程在同一个数据库(文件)中创建自己的表并将其写入的方法是否可行?

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?

推荐答案

请勿将SQLite与NFS一起使用.它是如此简单. NFS语义不同于常规文件系统,并且较宽松.您最终将获得腐败.不时地,SQLite用户邮件列表中的某人发布了其解决方法".尽管从短期来看,它们从未起作用.

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.

这篇关于可以在NFS文件系统上锁定sqlite文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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