Writing to SQLite dataset when other processes are reading from it

落花浮王杯 提交于 2020-01-11 14:31:10

问题


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

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


回答1:


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

You can adjust this timeout with PRAGMA busy_timeout.



来源:https://stackoverflow.com/questions/24165446/writing-to-sqlite-dataset-when-other-processes-are-reading-from-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!