SQLite3 :: BusyException [英] SQLite3::BusyException

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

问题描述

现在使用SQLite3运行rails网站。

Running a rails site right now using SQLite3.

每500个请求约一次,我得到一个

About once every 500 requests or so, I get a

ActiveRecord :: StatementInvalid(SQLite3 :: BusyException:数据库被锁定:...

ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked:...

如何解决这个问题,对我的代码是微创?

What's the way to fix this that would be minimally invasive to my code?

我现在使用SQLLite,因为你可以将数据库存储在源代码控制中,这使得自然备份,你可以很快地推出更改,但很显然

I'm using SQLLite at the moment because you can store the DB in source control which makes backing up natural and you can push changes out very quickly. However, it's obviously not really set up for concurrent access. I'll migrate over to MySQL tomorrow morning.

推荐答案

默认情况下,sqlite立即返回一个阻塞的,忙的错误,如果数据库忙和锁定你可以要求它等待,并保持尝试一段时间放弃这通常解决这个问题,除非你有1000个线程访问你的数据库,当我同意sqlite将不适当。

By default, sqlite returns immediatly with a blocked, busy error if the database is busy and locked. You can ask for it to wait and keep trying for a while before giving up. This usually fixes the problem, unless you do have 1000s of threads accessing your db, when I agree sqlite would be inappropriate.


    // set SQLite to wait and retry for up to 100ms if database locked
    sqlite3_busy_timeout( db, 100 );

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

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