pgtune

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1024
	MB = 1024 * KB
	GB = 1024 * MB
	TB = 1024 * GB
)

Constants for size calculations (in bytes)

Variables

This section is empty.

Functions

func ApplyPostProcessors

func ApplyPostProcessors(pgConf *pkg.PostgresConf, sysInfo *sysinfo.SystemInfo) error

ApplyPostProcessors applies all registered post-processors to the configuration

func GetPgTuneManagedParams

func GetPgTuneManagedParams() []string

GetPgTuneManagedParams returns the list of parameters managed by pg_tune

func GetRecommendedMaxConnections

func GetRecommendedMaxConnections(dbType sysinfo.DBType) int

GetRecommendedMaxConnections returns recommended max_connections based on DB type

func OptimizeAndSave

func OptimizeAndSave(opts OptimizeOptions) error

OptimizeAndSave calculates optimal PostgreSQL configuration and saves to postgresql.auto.conf

func RegisterPostProcessor

func RegisterPostProcessor(processor PostProcessor)

RegisterPostProcessor registers a new post-processor function

Types

type AutoConfFile

type AutoConfFile struct {
	Parameters map[string]*AutoConfParameter
	Comments   []string // standalone comments (not associated with parameters)
}

AutoConfFile represents the parsed postgres.auto.conf file

func ParseAutoConf

func ParseAutoConf(path string) (*AutoConfFile, error)

ParseAutoConf parses a postgres.auto.conf file

func (*AutoConfFile) MergeWithTunedParams

func (ac *AutoConfFile) MergeWithTunedParams(params *TunedParameters)

MergeWithTunedParams merges tuned parameters into the auto.conf, updating only pg_tune managed params

func (*AutoConfFile) WriteToFile

func (ac *AutoConfFile) WriteToFile(path string) error

WriteToFile writes the auto.conf to a file

type AutoConfParameter

type AutoConfParameter struct {
	Name    string
	Value   string
	Comment string // inline comment if any
}

AutoConfParameter represents a single parameter in postgres.auto.conf

type OptimizeOptions

type OptimizeOptions struct {
	DataDir        string
	DBType         sysinfo.DBType
	MaxConnections int
	SystemInfo     *sysinfo.SystemInfo
}

OptimizeOptions contains options for optimizing PostgreSQL configuration

type PostProcessor

type PostProcessor func(*pkg.PostgresConf, *sysinfo.SystemInfo) error

PostProcessor is a function type for processing PostgreSQL configuration

type TunedParameters

type TunedParameters struct {
	// Memory parameters (in KB unless noted)
	SharedBuffers      uint64 // shared_buffers
	EffectiveCacheSize uint64 // effective_cache_size
	MaintenanceWorkMem uint64 // maintenance_work_mem
	WorkMem            uint64 // work_mem

	// WAL parameters (in KB unless noted)
	WalBuffers                 uint64  // wal_buffers
	MinWalSize                 uint64  // min_wal_size
	MaxWalSize                 uint64  // max_wal_size
	CheckpointCompletionTarget float64 // checkpoint_completion_target

	// Performance parameters
	RandomPageCost          float64 // random_page_cost
	EffectiveIoConcurrency  *int    // effective_io_concurrency (nil if not applicable)
	DefaultStatisticsTarget int     // default_statistics_target

	// Parallel processing parameters
	MaxWorkerProcesses            int  // max_worker_processes
	MaxParallelWorkers            int  // max_parallel_workers (PG 10+)
	MaxParallelWorkersPerGather   int  // max_parallel_workers_per_gather
	MaxParallelMaintenanceWorkers *int // max_parallel_maintenance_workers (PG 11+)

	// WAL level settings
	WalLevel      string // wal_level
	MaxWalSenders *int   // max_wal_senders (set to 0 when wal_level=minimal)

	// Connection parameters
	MaxConnections int // max_connections

	// Huge pages setting
	HugePages string // huge_pages

	// Warning messages for memory constraints
	Warnings []string
}

TunedParameters contains the calculated PostgreSQL parameters

func CalculateOptimalConfig

func CalculateOptimalConfig(config *TuningConfig) (*TunedParameters, error)

CalculateOptimalConfig generates optimal PostgreSQL configuration based on system info

func (*TunedParameters) FormatAsKB

func (tp *TunedParameters) FormatAsKB(valueKB uint64) string

FormatAsKB formats a value in KB as a PostgreSQL configuration value

type TuningConfig

type TuningConfig struct {
	// SystemInfo contains detected system information
	SystemInfo *sysinfo.SystemInfo

	// MaxConnections is the maximum number of database connections
	MaxConnections int

	// DBType is the database workload type
	DBType sysinfo.DBType

	// DiskType overrides detected disk type if specified
	DiskType *sysinfo.DiskType
}

TuningConfig contains the input parameters for PostgreSQL tuning

Jump to

Keyboard shortcuts

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