Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultMaxOpenConns is the default maximum number of open connections. // Conservative default: 4 database pools × 5 = 20 total connections, // well under PostgreSQL's default max_connections of 100. DefaultMaxOpenConns = 5 // DefaultMaxIdleConns is the default maximum number of idle connections. // Set equal to MaxOpenConns to avoid connection churn. DefaultMaxIdleConns = 5 // DefaultConnMaxLifetime is the default maximum connection lifetime. // 30 minutes provides stability while still recycling stale connections. DefaultConnMaxLifetime = 30 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Options)
Option is a functional option for configuring PostgreSQL connections.
func OptionsFromConfig ¶
func OptionsFromConfig(cfg app.PostgresConfig) []Option
OptionsFromConfig creates functional options from app.PoolConfig. Returns nil if cfg is nil. Zero values in cfg use the defaults.
func WithConnMaxLifetime ¶
WithConnMaxLifetime sets the maximum connection lifetime.
func WithMaxIdleConns ¶
WithMaxIdleConns sets the maximum number of idle connections.
func WithMaxOpenConns ¶
WithMaxOpenConns sets the maximum number of open connections.
type Options ¶
type Options struct {
// MaxOpenConns is the maximum number of open connections to the database.
MaxOpenConns int
// MaxIdleConns is the maximum number of idle connections in the pool.
MaxIdleConns int
// ConnMaxLifetime is the maximum amount of time a connection may be reused.
ConnMaxLifetime time.Duration
}
Options configures a PostgreSQL connection.
Click to show internal directories.
Click to hide internal directories.