OperationalError:数据库被锁定 [英] OperationalError: database is locked

查看:1026
本文介绍了OperationalError:数据库被锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中做了一些重复的操作(测试),突然,我得到一个奇怪的错误:

  OperationalError:数据库已锁定

我已重新启动服务器,但错误仍然存​​在。

来自django doc:

>

SQLite是一个轻量级的
数据库,因此不能支持
的高水平并发性。
OperationalError:数据库被锁定
错误指示您的应用程序
遇到比
更多的并发性sqlite可以在默认
配置中处理。这个错误意味着
一个线程或进程在数据库连接上有一个独占的
锁,而
另一个线程超时等待
锁释放。



Python的SQLite包装器有一个默认的
超时值,它决定了
第二个线程允许等待
在锁定超时之前的时间,
引发OperationalError:database
是被锁定的错误。



如果你得到这个错误,你可以
解决它: / p>

切换到另一个数据库后端。
在某一点上,SQLite对于现实世界的应用程序变得过于
lite,
和这些类型的并发错误
表明你已经达到了这一点。



重写代码以减少
并发,并确保数据库
的交易是短期的。



将默认超时值增加
设置超时数据库选项
optionoption


http://docs.djangoproject.com/en/dev/ref/databases/#数据库锁定错误选择


I have made some repetitive operations in my application (testing it), and suddenly I’m getting a weird error:

OperationalError: database is locked

I've restarted the server, but the error persists. What can it be all about?

解决方案

From django doc:

SQLite is meant to be a lightweight database, and thus can't support a high level of concurrency. OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database connection and another thread timed out waiting for the lock the be released.

Python's SQLite wrapper has a default timeout value that determines how long the second thread is allowed to wait on the lock before it times out and raises the OperationalError: database is locked error.

If you're getting this error, you can solve it by:

Switching to another database backend. At a certain point SQLite becomes too "lite" for real-world applications, and these sorts of concurrency errors indicate you've reached that point.

Rewriting your code to reduce concurrency and ensure that database transactions are short-lived.

Increase the default timeout value by setting the timeout database option optionoption

http://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errorsoption

这篇关于OperationalError:数据库被锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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