-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help for sql error "database is locked" #148
Comments
Could you try to open the database like below? gDb, err = sql.Open("sqlite3", "file:databaselocked.sqlite?cache=shared&mode=rwc") |
I have made the code change in the test program <databaselocked.go> and it works now, thank you :) But after making the same code changes in the API Server, it still does not work... The original sql error "database is locked" is gone but a new error pops up. The new sql error occurs randomly, +-6% of the SQL Update sqlStmnt.Exec() statements
I have made an attempt to write another test programme that reflects what the api server is doing. The new test program launches the same number of goroutines. Each goroutine executes an SQL Select and an SQL Update statement (autocommit mode). => This is the new test program <databaselocked2.go> to make it easier for you to reproduce it.
Thanks for your help. |
FYI The error also occurs (randomly) when putting the database in write-ahead-mode and still with at least +-50 requests / second):
|
You should separate sqlite connection per goroutines. |
|
I have done more tests. This time I have implemented the same programme for the SQLite and the MySQL database, and I have used the config setting db.SetMaxOpenConns(i). These tests were run on an Ubuntu Server v13.10 (running the tests in Windows7 gives other results). Remember that the errors only pop up when doing things in parallel and for more than 100 operations per seconds (which represents a website with medium traffic in my case). The results are interesting. Variation 1. database/sql db.SetMaxOpenConns(i) from is not called and therefore the database/sql package imposes no limit on the nbr of connections (same as before). Result SQLite (same as before): sqlite3.Error{Code:6, ExtendedCode:262, err:"database table is locked: counters"} Result MySQL: &mysql.MySQLError{Number:0x410, Message:"Too many connections"} Variation 2. db.SetMaxOpenConns(i) is set to db.SetMaxOpenConns(75). This will throttle the number of active connections. I have chosen deliberately 75 which is a value < 100 (100 = the setting in the MySQL server config). Result SQLite (same as before): sqlite3.Error{Code:6, ExtendedCode:262, err:"database table is locked: counters"} Result MySQL: it works perfectly without errors :) Global Conclusions so far:
I do not know how to solve this for SQLite.Please help ... |
Could you please show me the last your code? |
This is the latest test programme for SQLite and MySQL with instructions included. Thank you. |
I am using write-ahead logging as well as shared cache and I am still getting this error:
Has this issue been resolved? Should I implement a priority queue to avoid concurrency issues? Thanks! |
Try latest commit |
Should be done. |
Looks it is not fixed. |
Old thread but this might help someone: Running the gist in @pantaluna 's comment ( https://gist.github.com/pantaluna/7ad0988269119507539b ) still produces the same error ( A related issued: applikatoni/applikatoni#35 |
See #274 (comment) |
Hi,
I have written an HTTP API server in Go that uses SQLite3 and your great package to implement data persistence.
The daemon works fine on the dev machine but once it is deployed on a test server and put under a slightly heavier load (100 API requests / second via HTTP) then I noticed that the API server throws SQL error . The sql errors occur randomly and in less then 0.2% of the transactional statements.
Some stats of a stress test:
I have narrowed the problem down to the SQLite3 database (and maybe how I use it) when doing Insert, Update and Delete (Select works fine if no program is doing transactions and is blazingly fast).
The sql error starts popping up as soon as the execution of an sql statement has to wait more than 5 seconds.
=> So I have made a small test program to make it easier for you to reproduce it.
https://gist.github.com/pantaluna/89ffe94ec30fb28d9fb8
I noticed that the 5 second timeout is hardcoded in the go-sqlite3 package. I do not see increasing the timeout setting in the go-sqlite3 package as a real solution, nor throttling down the number of active sql connections to 1 (that is possible in database/sql).
I think the whole database is locked when an sql client executes a (simple) transactional statement; even if the Updates occur on different tables, or on the same table but different rows (the latter is implemented in the test program).
Can you please advice me on how to use the go-sqlite3 package correctly, and avoid those random errors?
Thank you.
The text was updated successfully, but these errors were encountered: