很容易就报错 数据库被锁
sqlite database is locked (5) (SQLITE_BUSY)
reproduce example please?
reproduce example please?
I have the same situation, I am a beginner, I was locked after frequent update operations
reproduce example please?
Sorry, I forgot to tell you, I have goroutine to query the database, I think it has something to do with this
reproduce example please?
Sorry, I forgot to tell you, I have goroutine to query the database, I think it has something to do with this
You're right. SQLite by default only allows single writer at the same time. AFAIK there's couple of thing you can try:
- busy timeout: path/to/some.db?_pragma=busy_timeout(5000)
- journal mode: path/to/some.db?_pragma=journal_mode(WAL)
Let me know if this helped
reproduce example please?
Sorry, I forgot to tell you, I have goroutine to query the database, I think it has something to do with this
You're right. SQLite by default only allows single writer at the same time. AFAIK there's couple of thing you can try:
- busy timeout: path/to/some.db?_pragma=busy_timeout(5000)
- journal mode: path/to/some.db?_pragma=journal_mode(WAL)
Let me know if this helped
Thank you very much, it has worked for me
db?cache=shared&mode=rwc&_journal_mode=WAL can i use this ?
db?cache=shared&mode=rwc&_journal_mode=WAL
can i use this ?
Yes, but following is mandatory:
- specify file:// scheme, so that SQLite understands the 'cache' and 'mode' parameters.
- specify journal mode as _pragma=journal_mode(WAL)
dsn: file://C:/Users/Administrator/AppData/Local/Temp/GoLand/conf/rb.db?cache=shared&mode=rwc&_journal_mode=WAL&_pragma=journal_mode(WAL)
echo error: failed to initialize database, got error SQL logic error: out of memory
./conf/rb.db?cache=shared&mode=rwc&_journal_mode=WAL&_pragma=journal_mode(WAL) is connect success

How many parameters do I have? demo:
- &_pragma=journal_mode(WAL)
how add param busy_timeout
&_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)
&_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)
yes
&_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)
yes Hello, I should have solved the problem that,Only 1 open connection allowed.
sqlDB, err := db.DB() sqlDB.SetMaxOpenConns(1) // SetMaxOpenConns sets the maximum number of open connections to the database.
NOT WORKS
dsn := "file:./ex.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)"
db, _ := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
WORKS
dsn := "file:./ex.db"
db, _ := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
sqlDB, _ := db.DB()
sqlDB.SetMaxOpenConns(1)
ENV
go version go1.21.1 windows/amd64
github.com/glebarez/sqlite v1.9.0
db?cache=shared&mode=rwc&_journal_mode=WAL can i use this ?
Yes, but following is mandatory:
- specify file:// scheme, so that SQLite understands the 'cache' and 'mode' parameters.
- specify journal mode as _pragma=journal_mode(WAL)
what does this mean? can you please provide an example for 1
long story short: is this supported? file::memory:?cache=shared because it seems like its not working