简体   繁体   English

如何从多个Perl进程使用相同的SQLite3数据库?

[英]How to use the same SQLite3 database from multiple Perl processes?

I've an unfortunate situation where multiple Perl processes write and read the same SQLite3 database at the same time. 我有一个不幸的情况,多个Perl进程同时编写和读取相同的SQLite3数据库。

This often causes Perl processes to crash as two processes would be writing at the same time, or one process would be reading from the database while the other tries to update the same record. 这通常会导致Perl进程崩溃,因为两个进程将同时写入,或者一个进程将从数据库读取而另一个进程尝试更新同一记录。

Does anyone know how I could coordinate the multiple processes to work with the same sqlite database? 有谁知道如何协调多个进程使用相同的sqlite数据库?

I'll be working on moving this system to a different database engine but before I do that, I somehow need to fix it to work as it is. 我将努力将此系统移动到不同的数据库引擎,但在我这样做之前,我不知何故需要修复它才能正常工作。

SQLite is designed to be used from multiple processes. SQLite旨在用于多个进程。 There are some exceptions if you host the sqlite file on a network drive, and there maybe a way to compile it such that it expects to be used from one process, but I use it from multiple processes regularly. 如果您在网络驱动器上托管sqlite文件有一些例外,并且可能有一种方法可以编译它,以便它可以在一个进程中使用,但我会定期从多个进程使用它。 If you are experiencing problems, try increasing the timeout value. 如果遇到问题,请尝试增加超时值。 SQLite uses the filesystem locks to protect the data from simultaneous access. SQLite使用文件系统锁来保护数据不被同时访问。 If one process is writing to the file, a second process might have to wait. 如果一个进程正在写入该文件,则第二个进程可能必须等待。 I set my timeouts to 3 seconds, and have very little problems with that. 我将我的超时设置为3秒,并且几乎没有问题。

Here is the link to set the timeout value 以下是设置超时值的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM