Ruby: SQLite3::BusyException: database is locked:

For anyone else encountering this issue with SQLite locking in development when a Rails console is open, try this:

Just run the following:

ActiveRecord::Base.connection.execute("BEGIN TRANSACTION; END;")

For me anyway, it appears to clear any transaction that the console was holding onto and frees up the database.

This is especially a problem for me when running delayed_job, which seems to fail at closing the transaction quite often.


SQLite is not really supposed to be used for concurrent access which is the issue you are running into here. You can try increasing the timeout in your database.yml file which may be a workaround for you in this case. However, I would recommend you switch to another database that supports multiple connections like MySQL or PgSQL.


For me...the issue I had was that it seemed that the Rails Console I had open for a while was locking up a connection with SQLite.

So once I exited that console, and restarted my webserver (Thin) it worked perfectly.

I tried @trisweb's suggestion but it didn't work for me.