Alex Rivera | Logout

SQLite3::BusyException

Asked 2008-09-17T01:02:39.067
38

Running a rails site right now using SQLite3.

About once every 500 requests or so, I get a

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

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

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.

Edit
Report

2 Answers

58

You mentioned that this is a Rails site. Rails allows you to set the SQLite retry timeout in your database.yml config file:

production:
  adapter: sqlite3
  database: db/mysite_prod.sqlite3
  timeout: 10000

The timeout value is specified in miliseconds. Increasing it to 10 or 15 seconds should decrease the number of BusyExceptions you see in your log.

This is just a temporary solution, though. If your site needs true concurrency then you will have to migrate to another db engine.

answered 2009-04-10T22:15:41.217
1

I had a similar problem with rake db:migrate. Issue was that the working directory was on a SMB share. I fixed it by copying the folder over to my local machine.

answered 2011-02-25T00:56:18.000

Your Answer