Documentation
¶
Overview ¶
Package postgres implements the PostgreSQL storage adapter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyDefaults ¶
ApplyDefaults applies conservative pool limits to an *sql.DB. Intended for test paths and CLI tools where full pool configuration is unnecessary. Settings: MaxOpenConns=10, MaxIdleConns=2, Lifetime=120s, IdleTime=30s.
Types ¶
type PoolConfig ¶
type PoolConfig struct {
MaxOpenConns int `json:"max_open_conns,omitempty"`
MaxIdleConns int `json:"max_idle_conns,omitempty"`
ConnMaxLifetime int `json:"conn_max_lifetime,omitempty"`
ConnMaxIdleTime int `json:"conn_max_idle_time,omitempty"`
HealthCheckInterval int `json:"pool_health_check_interval,omitempty"`
HealthCheckTimeout int `json:"pool_health_check_timeout,omitempty"`
}
PoolConfig holds all tunable connection pool parameters. Zero or negative values are replaced by defaults in applyDefaults(), except HealthCheckInterval where zero means the pinger is disabled.
type PoolManager ¶
type PoolManager struct {
// contains filtered or unexported fields
}
PoolManager wraps an *sql.DB and manages pool configuration, health checking, and Prometheus metric collection.
func NewPoolManager ¶
func NewPoolManager(db *sql.DB, cfg PoolConfig) *PoolManager
NewPoolManager creates a PoolManager, applies pool settings to db, and registers Prometheus metrics. The returned PoolManager is not started; call Start() to begin background health checking.
func (*PoolManager) Start ¶
func (pm *PoolManager) Start(ctx context.Context)
Start begins the background health check pinger. When HealthCheckInterval is 0, the pinger is disabled and Start returns immediately.
func (*PoolManager) Stop ¶
func (pm *PoolManager) Stop()
Stop cancels the background pinger and waits up to 5 seconds for it to exit. Safe to call on a PoolManager that was never started or already stopped.