问题
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