mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-02 06:31:21 +08:00
🐛 fix(connection): 优化多数据源连接数占用
- 测试连接改为隔离连接,成功后立即关闭并避免写入全局缓存 - 新增通用 SQL 连接池配置,限制网络型数据源空闲连接长期占用 - Redis 测试连接改为临时客户端并立即释放 - MySQL 连接数超限时释放同实例缓存连接并重试 - 补充连接释放、缓存重试和连接池参数回归测试
This commit is contained in:
@@ -159,6 +159,7 @@ func (p *PostgresDB) Connect(config connection.ConnectionConfig) error {
|
||||
failures = append(failures, fmt.Sprintf("%s 数据库=%s 打开连接失败: %v", sslLabel, dbName, err))
|
||||
continue
|
||||
}
|
||||
configureSQLConnectionPool(dbConn, "postgres")
|
||||
p.conn = dbConn
|
||||
|
||||
// Force verification
|
||||
@@ -604,6 +605,7 @@ func (p *PostgresDB) ensureSearchPath(baseDSN string) {
|
||||
|
||||
newDB, err := sql.Open("postgres", newDSN)
|
||||
if err == nil {
|
||||
configureSQLConnectionPool(newDB, "postgres")
|
||||
newDB.SetConnMaxLifetime(5 * time.Minute)
|
||||
oldConn := p.conn
|
||||
p.conn = newDB
|
||||
|
||||
Reference in New Issue
Block a user