fix(database): 数据库连接 - 消费 libpq keepalive 参数并默认限制闲置事务 (#737)

pgx 不识别 DSN 中 libpq 的 keepalives* 参数,会作为服务端运行参数发送导致连接被拒;改为在建连前消费并应用到 TCP 拨号器。
未显式配置时为每条连接默认设置 idle_in_transaction_session_timeout=5min,避免卡住的事务长期持锁;DSN 显式配置时以 DSN 为准。
建连钩子先复制共享的 RuntimeParams,避免多条连接之间累积修改。

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Catlaxy AIandClaude Opus 5.5 authored and GitHub committed 2026-10-11 22:04:27 +08:00
1 parent 28f2362e3e
commit 6dedc5973c
5 files changed
+334 -2

No files matched your search

+1 -1
View File
@@ -7,6 +7,7 @@ require (
github.com/gabriel-vasile/mimetype v1.4.13
github.com/gin-gonic/gin v1.12.0
github.com/google/uuid v1.5.0
github.com/jackc/pgx/v5 v5.10.0
github.com/qiniu/go-sdk/v7 v7.27.0
github.com/redis/go-redis/v9 v9.22.0
github.com/tencentyun/cos-go-sdk-v5 v0.7.75
@@ -44,7 +45,6 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.10.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect