server

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseAlreadyExists added in v1.0.4

func DatabaseAlreadyExists(dataDir string) bool

DatabaseAlreadyExists checks if the database has already been initialized

func ValidateMinimumEnv added in v1.0.4

func ValidateMinimumEnv(env *DockerEnv, databaseExists bool) error

ValidateMinimumEnv validates that required environment variables are set

func WrappedError added in v1.0.4

func WrappedError(err error) exec.WrapperFunc

Types

type Checkpoint added in v1.0.4

type Checkpoint struct {
	Last         time.Time `json:"last"`
	RedoLSN      string    `json:"redo_lsn"`
	BytesWritten int64     `json:"bytes_written" pretty:"bytes"`
}

type DataDirFileInfo added in v1.0.4

type DataDirFileInfo struct {
	Name     string    `json:"name"`
	Path     string    `json:"path"`
	Size     int64     `json:"size"`
	MD5      string    `json:"md5"`
	Modified time.Time `json:"modified"`
}

func (*DataDirFileInfo) GetChildren added in v1.0.4

func (f *DataDirFileInfo) GetChildren() []api.TreeNode

GetChildren implements TreeNode interface for DataDirFileInfo

func (*DataDirFileInfo) Pretty added in v1.0.4

func (f *DataDirFileInfo) Pretty() api.Text

Pretty implements the api.Text formatting for DataDirFileInfo

type DataDirTree added in v1.0.4

type DataDirTree struct {
	Label string            `json:"label"`
	Path  string            `json:"path"`
	Files []DataDirFileInfo `json:"files"`
}

func (*DataDirTree) GetChildren added in v1.0.4

func (d *DataDirTree) GetChildren() []api.TreeNode

GetChildren implements TreeNode interface for DataDirTree

func (*DataDirTree) Pretty added in v1.0.4

func (d *DataDirTree) Pretty() api.Text

Pretty implements the api.Text formatting for DataDirTree

type DockerEnv added in v1.0.4

type DockerEnv struct {
	User           string
	Password       utils.SensitiveString
	Database       string
	InitDBArgs     string
	WALDir         string
	HostAuthMethod string
}

func SetupDockerEnv added in v1.0.4

func SetupDockerEnv() (*DockerEnv, error)

SetupDockerEnv loads Docker-compatible environment variables

type ExtensionInfo

type ExtensionInfo = pkg.ExtensionInfo

Use types from pkg package

type ExtensionStatus

type ExtensionStatus struct {
	Name      string `json:"name"`
	SQLName   string `json:"sql_name"`
	Installed bool   `json:"installed"`
	Version   string `json:"version,omitempty"`
	Required  bool   `json:"required"`
	Available bool   `json:"available"`
	Error     string `json:"error,omitempty"`
}

ExtensionStatus represents the status of a PostgreSQL extension

type HealthServer

type HealthServer struct {
	Port        int
	ConfigDir   string
	SystemInfo  *sysinfo.SystemInfo
	TunedParams *pgtune.TunedParameters
	DBType      string
	MaxConn     int

	// Service configurations
	PostgresConfig  *pkg.PostgresConf
	PgBouncerConfig *pkg.PgBouncerConf
	PostgRESTConfig *pkg.PostgrestConf
	WalgConfig      *pkg.WalgConf
	// contains filtered or unexported fields
}

HealthServer provides health check and configuration endpoints

func NewHealthServer

func NewHealthServer(port int, configDir string) *HealthServer

NewHealthServer creates a new health check server

func (*HealthServer) LoadServiceConfigs

func (s *HealthServer) LoadServiceConfigs()

LoadServiceConfigs loads and hydrates service configurations with defaults

func (*HealthServer) SaveConfigsToDir

func (s *HealthServer) SaveConfigsToDir(dir string) error

SaveConfigsToDir saves all configuration files to the specified directory

func (*HealthServer) SetConfiguration

func (s *HealthServer) SetConfiguration(maxConn int, dbType string, tunedParams *pgtune.TunedParameters)

SetConfiguration sets the tuning configuration for the server

func (*HealthServer) Start

func (s *HealthServer) Start() error

Start starts the health check server

func (*HealthServer) Stop

func (s *HealthServer) Stop(ctx context.Context) error

Stop stops the health check server

type InitDBOptions added in v1.0.4

type InitDBOptions struct {
	Username   string
	Password   utils.SensitiveString
	InitDBArgs string
	WALDir     string
	AuthMethod string
}

type PGVersion

type PGVersion = pkg.PgVersion

type Postgres

type Postgres struct {
	Config   *pkg.PostgresConf
	DataDir  string
	BinDir   string // Auto-resolved based on detected version
	Locale   string
	Encoding string

	Host     string
	Port     int
	Username string
	Password utils.SensitiveString
	Database string
	DryRun   bool
	// contains filtered or unexported fields
}

func NewPostgres

func NewPostgres(config *pkg.PostgresConf, dataDir string) *Postgres

NewPostgres creates a new PostgreSQL service instance

func NewRemotePostgres added in v1.0.4

func NewRemotePostgres(host string, port int, username, password, database string) *Postgres

func (*Postgres) Backup

func (p *Postgres) Backup() error

func (*Postgres) CreateDatabase added in v1.0.4

func (p *Postgres) CreateDatabase(name string) error

func (*Postgres) DescribeConfig

func (p *Postgres) DescribeConfig() ([]schemas.Param, error)

DescribeConfig executes `postgres --describe-config` and returns parsed parameters

func (*Postgres) DetectVersion

func (p *Postgres) DetectVersion() (int, error)

DetectVersion reads the PostgreSQL version from the data directory

func (*Postgres) Exists

func (p *Postgres) Exists() bool

func (*Postgres) GetConnection added in v1.0.4

func (p *Postgres) GetConnection() (*sql.DB, error)

func (*Postgres) GetConnectionString added in v1.0.4

func (p *Postgres) GetConnectionString() string

func (*Postgres) GetControlData added in v1.0.4

func (p *Postgres) GetControlData() (*config.ControlData, error)

GetControlData executes `pg_controldata` and returns parsed control data

func (*Postgres) GetCurrentConf added in v1.0.4

func (p *Postgres) GetCurrentConf() (config.ConfSettings, error)

GetCurrentConf queries the running PostgreSQL instance for current configuration

func (*Postgres) GetFullVersion added in v1.0.4

func (p *Postgres) GetFullVersion() string

GetFullVersion returns the full PostgreSQL version string Example: "PostgreSQL 17.5 (Debian 17.5-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by..."

func (*Postgres) GetStderr

func (p *Postgres) GetStderr() string

func (*Postgres) GetStdout

func (p *Postgres) GetStdout() string

func (*Postgres) GetSupportedExtensions

func (p *Postgres) GetSupportedExtensions() []string

GetSupportedExtensions returns the list of well-known supported extensions

func (*Postgres) GetVersion

func (p *Postgres) GetVersion() PGVersion

func (*Postgres) Health

func (p *Postgres) Health() error

Health performs a comprehensive health check of the PostgreSQL service

func (*Postgres) Info added in v1.0.4

func (p *Postgres) Info() (*PostgresInfo, error)

func (*Postgres) InitDB

func (p *Postgres) InitDB() error

func (*Postgres) InitDBWithOptions added in v1.0.4

func (p *Postgres) InitDBWithOptions(opts InitDBOptions) error

func (*Postgres) InstallExtensions

func (p *Postgres) InstallExtensions(extensions []string) error

InstallExtensions installs the specified PostgreSQL extensions

func (*Postgres) IsRemote added in v1.0.4

func (p *Postgres) IsRemote() bool

func (*Postgres) IsRunning

func (p *Postgres) IsRunning() bool

func (*Postgres) ListAvailableExtensions

func (p *Postgres) ListAvailableExtensions() ([]ExtensionInfo, error)

ListAvailableExtensions returns a list of available PostgreSQL extensions

func (*Postgres) ListInstalledExtensions

func (p *Postgres) ListInstalledExtensions() ([]ExtensionInfo, error)

ListInstalledExtensions returns a list of installed PostgreSQL extensions

func (*Postgres) Pg_ctl added in v1.0.4

func (p *Postgres) Pg_ctl(args ...string) *exec.Process

func (*Postgres) Ping added in v1.0.4

func (p *Postgres) Ping() error

func (*Postgres) ProcessInitScripts added in v1.0.4

func (p *Postgres) ProcessInitScripts(initDir string) error

ProcessInitScripts processes initialization scripts from /docker-entrypoint-initdb.d/ Supports .sh, .sql, .sql.gz, .sql.xz, .sql.zst files

func (*Postgres) Psql added in v1.0.4

func (p *Postgres) Psql(args ...string) *exec.Process

func (*Postgres) ResetPassword

func (p *Postgres) ResetPassword(newPassword utils.SensitiveString) error

ResetPassword resets the PostgreSQL superuser password using a temporary server instance

func (*Postgres) SQL

func (p *Postgres) SQL(sqlQuery string, args ...any) ([]map[string]interface{}, error)

func (*Postgres) SetupPgHBA added in v1.0.4

func (p *Postgres) SetupPgHBA(method string) error

SetupPgHBA configures pg_hba.conf for host authentication Allows trust authentication from localhost and password authentication from external hosts

func (*Postgres) Start

func (p *Postgres) Start() error

func (*Postgres) StartTempServer added in v1.0.4

func (p *Postgres) StartTempServer(opts TempServerOptions) (*exec.Process, error)

StartTempServer starts a temporary PostgreSQL server for initialization tasks If UnixSocketOnly is true, uses listen_addresses=” for Unix socket-only mode

func (*Postgres) Stop

func (p *Postgres) Stop() error

func (*Postgres) StopTempServer added in v1.0.4

func (p *Postgres) StopTempServer() error

StopTempServer stops a temporary PostgreSQL server

func (*Postgres) Upgrade

func (p *Postgres) Upgrade(targetVersion int) error

func (*Postgres) Validate

func (p *Postgres) Validate() error

func (*Postgres) ValidateConfig added in v1.0.4

func (p *Postgres) ValidateConfig(config []byte) error

Validate validates a PostgreSQL configuration file using the postgres binary

func (*Postgres) WithConnection added in v1.0.4

func (p *Postgres) WithConnection(fn func(db *sql.DB) error) error

func (*Postgres) WithoutAuth added in v1.0.4

func (p *Postgres) WithoutAuth() *Postgres

type PostgresInfo added in v1.0.4

type PostgresInfo struct {
	// e.g. 16 or 17
	VersionNumber int                `json:"version"`
	VersionInfo   string             `json:"version_info"`
	Running       bool               `json:"running"`
	DataDirectory string             `json:"data_dir"`
	BinDir        string             `json:"bin_dir"`
	ListenAddress string             `json:"listen_address"`
	Port          int                `json:"port"`
	System        sysinfo.SystemInfo `json:"system,omitempty"`

	// Configuration from disk (postgresql.conf + postgres.auto.conf)
	Files map[string]config.Conf `json:"conf_files,omitempty"`

	MergedConf config.Conf `json:"merged_conf,omitempty"`

	// Runtime configuration from running instance (only populated if running)
	RuntimeConf config.Conf `json:"runtime_conf,omitempty"`

	// Size of folders on disk
	DataSize int64 `json:"data_size" pretty:"format=bytes"`
	// Size of all DBs combined
	DBSize int64 `json:"db_size" pretty:"format=bytes"`

	// Data directory files tree
	DataDir string `json:"data_dir_tree,omitempty" `

	// pg_controldata
	ClusterState     string     `json:"cluster_state"`
	SystemIdentifier string     `json:"system_identifier"`
	FullVersion      string     `json:"full_version"`
	WalInfo          WalInfo    `json:"wal_info,omitempty"`
	Checkpoint       Checkpoint `json:"checkpoint,omitempty"`
}

type ServiceStatus

type ServiceStatus struct {
	Name         string `json:"name"`
	Status       string `json:"status"` // "running", "stopped", "unknown"
	Port         int    `json:"port,omitempty"`
	PortOpen     bool   `json:"port_open"`
	Enabled      bool   `json:"enabled"`
	Uptime       string `json:"uptime,omitempty"`
	RestartCount int    `json:"restart_count,omitempty"`
	Details      string `json:"details,omitempty"`
}

ServiceStatus represents the status of a service

type TempServerOptions added in v1.0.4

type TempServerOptions struct {
	UnixSocketOnly bool
	Port           int
}

type ValidationError

type ValidationError = pkg.ValidationError

type WalInfo added in v1.0.4

type WalInfo struct {
	LSN           string `json:"lsn"`
	LastFile      string `json:"last_file"`
	Size          int64  `json:"size" pretty:"format=bytes"`
	ArchivedCount int    `json:"archived_count"`
	ArchivedSize  int64  `json:"archived_size" pretty:"format=bytes"`
}

Jump to

Keyboard shortcuts

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