Skip to content
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

很容易就报错 数据库被锁 #52

Open
xiaoyi510 opened this issue Jul 11, 2022 · 15 comments
Open

很容易就报错 数据库被锁 #52

xiaoyi510 opened this issue Jul 11, 2022 · 15 comments

Comments

@xiaoyi510
Copy link

sqlite database is locked (5) (SQLITE_BUSY)

@glebarez
Copy link
Owner

reproduce example please?

@tomoyo233
Copy link

reproduce example please?

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

@tomoyo233
Copy link

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

@glebarez
Copy link
Owner

glebarez commented Jul 21, 2022

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

@tomoyo233
Copy link

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

@xiaoyi510
Copy link
Author

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

@glebarez
Copy link
Owner

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)

@xiaoyi510
Copy link
Author

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
Copy link
Author

(OL$OCIUQAJ5RLUTPM@X2MS

@xiaoyi510
Copy link
Author

How many parameters do I have?
demo:

  • &_pragma=journal_mode(WAL)

how add param busy_timeout

@xiaoyi510
Copy link
Author

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

@glebarez
Copy link
Owner

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

yes

@tomoyo233
Copy link

tomoyo233 commented Nov 19, 2022

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

@pplmx
Copy link

pplmx commented Sep 20, 2023

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

@loeffel-io
Copy link

loeffel-io commented Jul 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants