Browse Source

fix: 数据库启用 WAL 模式,增加连接数与超时设置 (#349)

fix: 数据库启用 WAL 模式,增加连接数与超时设置
pull/355/head
ssongliu 2 years ago committed by GitHub
parent
commit
e85340ca5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      backend/init/db/db.go

13
backend/init/db/db.go

@ -2,9 +2,11 @@ package db
import (
"fmt"
"os"
"time"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"os"
"github.com/1Panel-dev/1Panel/backend/global"
)
@ -28,6 +30,15 @@ func Init() {
if err != nil {
panic(err)
}
_ = db.Exec("PRAGMA journal_mode = WAL;")
sqlDB, dbError := db.DB()
if dbError != nil {
panic(err)
}
sqlDB.SetConnMaxIdleTime(10)
sqlDB.SetMaxOpenConns(100)
sqlDB.SetConnMaxLifetime(time.Hour)
global.DB = db
global.LOG.Info("init db successfully")
}

Loading…
Cancel
Save