n00b question (db locking)

72 views
Skip to first unread message

Ariel Girón

unread,
Jun 17, 2016, 6:58:24 PM6/17/16
to sqlite3-ruby
What is this about?

[agiron@useclwslpv132 06/17/16 03:31 PM dropbox]$ cat test3.rb
require "sqlite3"
# Open a database
db = SQLite3::Database.new "test.db"
# Create a database
rows = db.execute <<-SQL
  create table numbers (
    name varchar(30),
    val int
  );
SQL
# Execute a few inserts
{
  "one" => 1,
  "two" => 2,
}.each do |pair|
  db.execute "insert into numbers values ( ?, ? )", pair
end
# Find a few rows
db.execute( "select * from numbers" ) do |row|
  p row
end
[agiron@useclwslpv132 06/17/16 03:32 PM dropbox]$ ruby test3.rb
/usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/statement.rb:108:in `step': database is locked (SQLite3::BusyException)
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/statement.rb:108:in `block in each'
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/statement.rb:107:in `loop'
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/statement.rb:107:in `each'
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:158:in `to_a'
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:158:in `block in execute'
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:95:in `prepare'
        from /usr/local/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.11/lib/sqlite3/database.rb:134:in `execute'
        from test3.rb:7:in `<main>'
[agiron@useclwslpv132 06/17/16 03:32 PM dropbox]$

Aaron Patterson

unread,
Jun 17, 2016, 7:04:43 PM6/17/16
to sqlite...@googlegroups.com
I'm not sure.  I can't seem to reproduce this error.  What version of libsqlite are you using?  You should be able to get that from `SQLite3.libversion`.  Also, what version of Ruby are you using? Does it only happen with that version of Ruby?

Thanks.

--
You received this message because you are subscribed to the Google Groups "sqlite3-ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlite3-ruby...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Eric Wong

unread,
Jun 21, 2016, 10:50:10 PM6/21/16
to sqlite...@googlegroups.com
Ariel Girón <ariel...@gmail.com> wrote:
> `step': database is locked (SQLite3::BusyException)

I normally use immediate transactions and busy_timeout=5000
(5 seconds, the Sequel default) to avoid these errors.

But there's nothing in your script which would indicate there's
concurrent access (unless you have another forgotten process
running).

I can't reproduce the error, either.

Does setting the busy_timeout help?

db = SQLite3::Database.new "test.db"
db.busy_timeout = 5000
<rest of your script>


Otherwise, it might help to provide an strace dump if you're
running under Linux. Something along the lines of:

strace -f -o dump.txt -v ruby test.rb

and show us the relevant contents of dump.txt leading up to the
failure (be sure to filter out any potentially sensitive info
from that file)
Reply all
Reply to author
Forward
0 new messages