sqlite icon indicating copy to clipboard operation
sqlite copied to clipboard

很容易就报错 数据库被锁

Open xiaoyi510 opened this issue 3 years ago • 15 comments

sqlite database is locked (5) (SQLITE_BUSY)

xiaoyi510 avatar Jul 11 '22 06:07 xiaoyi510

reproduce example please?

glebarez avatar Jul 11 '22 15:07 glebarez

reproduce example please?

I have the same situation, I am a beginner, I was locked after frequent update operations

tomoyo233 avatar Jul 21 '22 14:07 tomoyo233

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

tomoyo233 avatar Jul 21 '22 14:07 tomoyo233

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:

Let me know if this helped

glebarez avatar Jul 21 '22 15:07 glebarez

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:

Let me know if this helped

Thank you very much, it has worked for me

tomoyo233 avatar Jul 22 '22 04:07 tomoyo233

db?cache=shared&mode=rwc&_journal_mode=WAL can i use this ?

xiaoyi510 avatar Aug 13 '22 13:08 xiaoyi510

db?cache=shared&mode=rwc&_journal_mode=WAL

can i use this ?

Yes, but following is mandatory:

  1. specify file:// scheme, so that SQLite understands the 'cache' and 'mode' parameters.
  2. specify journal mode as _pragma=journal_mode(WAL)

glebarez avatar Aug 13 '22 13:08 glebarez

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

xiaoyi510 avatar Aug 13 '22 14:08 xiaoyi510

(OL$OCIUQAJ5RLUTPM@X2MS

xiaoyi510 avatar Aug 13 '22 14:08 xiaoyi510

How many parameters do I have? demo:

  • &_pragma=journal_mode(WAL)

how add param busy_timeout

xiaoyi510 avatar Aug 13 '22 14:08 xiaoyi510

&_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)

xiaoyi510 avatar Aug 13 '22 15:08 xiaoyi510

&_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)

yes

glebarez avatar Aug 13 '22 16:08 glebarez

&_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.

tomoyo233 avatar Nov 19 '22 03:11 tomoyo233

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

pplmx avatar Sep 20 '23 07:09 pplmx

db?cache=shared&mode=rwc&_journal_mode=WAL can i use this ?

Yes, but following is mandatory:

  1. specify file:// scheme, so that SQLite understands the 'cache' and 'mode' parameters.
  2. 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

loeffel-io avatar Jul 04 '24 14:07 loeffel-io