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 +}