feat: sqlite模式改为wal支持并发写入临时日志
This commit is contained in:
9
build/database/lite/install/ainstall.sql
Normal file
9
build/database/lite/install/ainstall.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
-- ----------------------------
|
||||
-- Configuration
|
||||
-- ----------------------------
|
||||
|
||||
-- 启用完整的自动空间回收
|
||||
PRAGMA auto_vacuum = FULL;
|
||||
-- 日志模式设置为 WAL 并发写入
|
||||
PRAGMA journal_mode = WAL;
|
||||
PRAGMA synchronous = NORMAL;
|
||||
@@ -36,7 +36,7 @@ func loadDialect() map[string]dialectInfo {
|
||||
// 数据库类型对应的数据库连接
|
||||
switch item["type"] {
|
||||
case "sqlite":
|
||||
dsn := fmt.Sprint(item["database"])
|
||||
dsn := fmt.Sprintf("%s", item["database"])
|
||||
dialects[key] = dialectInfo{
|
||||
dialectic: sqlite.Open(dsn),
|
||||
logging: parse.Boolean(item["logging"]),
|
||||
@@ -108,6 +108,15 @@ func Connect() {
|
||||
sqlDB.SetMaxOpenConns(100)
|
||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||
sqlDB.SetConnMaxLifetime(time.Hour)
|
||||
// 执行初始连接配置
|
||||
if db.Name() == "sqlite" {
|
||||
// -- 设置较大的自动检查点阈值
|
||||
sqlDB.Exec("PRAGMA wal_autocheckpoint = 5000;")
|
||||
// -- 内存映射 I/O 最大字节数为 64MB
|
||||
sqlDB.Exec("PRAGMA mmap_size = 67108864;")
|
||||
// 抛出 SQLITE_BUSY 错误 默认0立即,设置等待 5 秒(5000 毫秒)
|
||||
sqlDB.Exec("PRAGMA busy_timeout = 5000;")
|
||||
}
|
||||
logger.Infof("database %s connection is successful.", key)
|
||||
dbMap[key] = db
|
||||
}
|
||||
|
||||
@@ -14,12 +14,12 @@ import (
|
||||
|
||||
// ImportSQL 导入SQL
|
||||
func ImportSQL() {
|
||||
sqlPath := config.Get("sqlPath").(string)
|
||||
if sqlPath == "" {
|
||||
sqlPath, sqlPathOk := config.Get("sqlPath").(string)
|
||||
if !sqlPathOk || sqlPath == "" {
|
||||
return
|
||||
}
|
||||
sqlSource := config.Get("sqlSource").(string)
|
||||
if sqlSource == "" {
|
||||
sqlSource, sqlSourceOk := config.Get("sqlSource").(string)
|
||||
if !sqlSourceOk || sqlSource == "" {
|
||||
sqlSource = config.Get("database.defaultDataSourceName").(string)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ func ImportSQL() {
|
||||
}
|
||||
|
||||
// log.Println("process success")
|
||||
Close()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user