当其他进程正在读取SQLite数据集时写入 [英] Writing to SQLite dataset when other processes are reading from it

查看:31
本文介绍了当其他进程正在读取SQLite数据集时写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进程要写入SQLite数据库时,在此处中阅读。保留的锁。然后,一旦进程准备好写入磁盘,它将获得挂起的锁,在此期间没有新进程可以获取共享锁,但是允许现有的共享锁完成其业务。一旦清除了剩余的共享锁,该过程即可写入。

Reading the SQLite documentation here, when a process wants to write to a SQLite database it obtains a reserved lock. Then once the process is ready to write to disk it obtains a pending lock, during which no new processes can obtain a shared lock, but existing shared locks are allowed to finish their business. Once the remaining shared locks clear, the process can write.

但是...当我尝试在其他进程正在从该数据库读取数据的同时编写数据库时,我立即得到错误:数据集已锁定。

However...when I try to write a database while other processes are reading from that database, I just get an immediate "Error: dataset is locked".

sqlite> insert into meta_models (model) values ("hello_world");
Error: database is locked

为什么不进行SQLite操作,请按照我概述的步骤进行操作上面的等待共享锁清除?

Why doesn't SQLite it go through the steps I outlined above of waiting for the shared locks to clear?

推荐答案

SQLite确实执行了这些步骤,但是在等待

SQLite does go through these steps, but it timed out while waiting for the remaining shared locks to clear.

您可以使用 PRAGMA busy_timeout

这篇关于当其他进程正在读取SQLite数据集时写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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