mirror of https://github.com/usememos/memos.git
fix: add mmap size setting to database connection to prevent OOM errors
This commit is contained in:
parent
552318209b
commit
05f31e457e
|
|
@ -33,6 +33,7 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
|
|||
// good practice to be explicit and prevent future surprises on SQLite upgrades.
|
||||
// - Journal mode set to WAL: it's the recommended journal mode for most applications
|
||||
// as it prevents locking issues.
|
||||
// - mmap size set to 0: it disables memory mapping, which can cause OOM errors on some systems.
|
||||
//
|
||||
// Notes:
|
||||
// - When using the `modernc.org/sqlite` driver, each pragma must be prefixed with `_pragma=`.
|
||||
|
|
@ -41,7 +42,7 @@ func NewDB(profile *profile.Profile) (store.Driver, error) {
|
|||
// - https://pkg.go.dev/modernc.org/sqlite#Driver.Open
|
||||
// - https://www.sqlite.org/sharedcache.html
|
||||
// - https://www.sqlite.org/pragma.html
|
||||
sqliteDB, err := sql.Open("sqlite", profile.DSN+"?_pragma=foreign_keys(0)&_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)")
|
||||
sqliteDB, err := sql.Open("sqlite", profile.DSN+"?_pragma=foreign_keys(0)&_pragma=busy_timeout(10000)&_pragma=journal_mode(WAL)&_pragma=mmap_size(0)")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to open db with dsn: %s", profile.DSN)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue