postgres

package
v0.92.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package postgres implements the PostgreSQL storage adapter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDefaults

func ApplyDefaults(db *sql.DB)

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.

func Init

func Init()

Init registers the postgres adapter with the store layer.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL