Add pg pool tuning options from kit v0.10.0

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-05-12 09:39:39 +02:00
parent 51a8380475
commit d88ae3288b
6 changed files with 69 additions and 28 deletions

View File

@@ -23,16 +23,18 @@ import (
)
type PgConfig struct {
Addr string `json:"addr"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
PoolSize int32 `json:"pool-size"`
MinPoolSize int32 `json:"min-pool-size"`
MaxConnIdleTimeSeconds int `json:"max-conn-idle-time-seconds"`
MaxConnLifetimeSeconds int `json:"max-conn-lifetime-seconds"`
CACertBundle string `json:"ca-cert-bundle"`
Debug bool `json:"debug"`
Addr string `json:"addr"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
PoolSize int32 `json:"pool-size"`
MinPoolSize int32 `json:"min-pool-size"`
MaxConnIdleTimeSeconds int `json:"max-conn-idle-time-seconds"`
MaxConnLifetimeSeconds int `json:"max-conn-lifetime-seconds"`
MaxConnLifetimeJitterSeconds int `json:"max-conn-lifetime-jitter-seconds"`
HealthCheckPeriodSeconds int `json:"health-check-period-seconds"`
CACertBundle string `json:"ca-cert-bundle"`
Debug bool `json:"debug"`
}
func (cfg PgConfig) Options(options ...pg.Option) []pg.Option {
@@ -66,6 +68,24 @@ func (cfg PgConfig) Options(options ...pg.Option) []pg.Option {
)
}
if cfg.MaxConnLifetimeJitterSeconds > 0 {
opts = append(
opts,
pg.WithMaxConnLifetimeJitter(
time.Duration(cfg.MaxConnLifetimeJitterSeconds)*time.Second,
),
)
}
if cfg.HealthCheckPeriodSeconds > 0 {
opts = append(
opts,
pg.WithHealthCheckPeriod(
time.Duration(cfg.HealthCheckPeriodSeconds)*time.Second,
),
)
}
if cfg.Debug {
opts = append(opts, pg.WithDebug())
}