From d1bee925632b3872b4dae500e9f1c8fdfb55dc91 Mon Sep 17 00:00:00 2001 From: vipg Date: Tue, 18 Nov 2025 12:11:27 +0800 Subject: [PATCH] add --- backend/src/db/postgres.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/db/postgres.go b/backend/src/db/postgres.go index 40681a3..aba5033 100644 --- a/backend/src/db/postgres.go +++ b/backend/src/db/postgres.go @@ -5,7 +5,7 @@ import ( "fmt" "os" "time" - + _ "github.com/lib/pq" "go.uber.org/zap" ) @@ -39,11 +39,11 @@ func Init() { if err != nil { zap.L().Panic("❌ 无法连接数据库", zap.Error(err)) } - + // 设置连接池参数 - DB.SetMaxOpenConns(100) // 最大打开连接数 - DB.SetMaxIdleConns(20) // 最大空闲连接数 - DB.SetConnMaxLifetime(time.Hour) // 连接最大存活时间 + DB.SetMaxOpenConns(100) // 最大打开连接数 + DB.SetMaxIdleConns(20) // 最大空闲连接数 + DB.SetConnMaxLifetime(time.Hour) // 连接最大存活时间 // 验证数据库连接 if err := DB.Ping(); err != nil { @@ -51,4 +51,4 @@ func Init() { } zap.L().Info("✅ 数据库连接验证成功") -} \ No newline at end of file +}