pg

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ActiveConnectionsQuery = `
/*dbtune*/
SELECT COUNT(*) AS active_connections
FROM pg_stat_activity
WHERE state = 'active'
`
View Source
const AlterDatabaseQuery = `
/*dbtune*/
ALTER DATABASE %s SET %s = %s;
`
View Source
const AlterSystemQuery = `
/*dbtune*/
ALTER SYSTEM SET %s = %s;
`
View Source
const AutovacuumQuery = `
/*dbtune*/
SELECT COUNT(*) FROM pg_stat_activity WHERE query LIKE 'autovacuum:%';
`

https://stackoverflow.com/a/25012622

View Source
const BufferCacheHitRatioQuery = `` /* 149-byte string literal not displayed */
View Source
const (
	DEFAULT_CONFIG_KEY = "postgresql"
)
View Source
const DataDirectoryQuery = `
/*dbtune*/
SHOW data_directory;
`
View Source
const DatabaseSizeQuery = `
/*dbtune*/
SELECT sum(pg_database_size(datname)) as total_size_bytes FROM pg_database;
`
View Source
const MaxConnectionsQuery = `
/*dbtune*/
SELECT setting::integer FROM pg_settings WHERE  name = 'max_connections';
`
View Source
const PGVersionQuery = `
/*dbtune*/
SELECT version();
`

PGVersion returns the version of the PostgreSQL instance

View Source
const PgStatStatementsQuery = `` /* 322-byte string literal not displayed */
View Source
const ReloadConfigQuery = `
/*dbtune*/
SELECT pg_reload_conf();
`
View Source
const SELECT_NON_NUMERIC_SETTINGS = `
	/*dbtune*/
	SELECT name, setting, unit, vartype, context 
	FROM pg_settings 
	WHERE vartype NOT IN ('real', 'integer');
`
View Source
const SELECT_NUMERIC_SETTINGS = `` /* 138-byte string literal not displayed */
View Source
const Select1Query = `
/*dbtune*/
SELECT 1;
`
View Source
const SleepQuery = `
/*dbtune*/
SELECT pg_sleep(1000000);
`
View Source
const TransactionsPerSecondQuery = `
/*dbtune*/
SELECT SUM(xact_commit)::bigint
AS server_xact_commits
FROM pg_stat_database;
`
View Source
const UptimeQuery = `
/*dbtune*/
SELECT EXTRACT(EPOCH FROM (current_timestamp - pg_postmaster_start_time())) / 60 as uptime_minutes;
`
View Source
const WaitEventsQuery = `` /* 690-byte string literal not displayed */

Variables

This section is empty.

Functions

func ActiveConnections

func ActiveConnections(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func AlterDatabase

func AlterDatabase(pgPool *pgxpool.Pool, dbname string, name string, value string) error

func AlterSystem

func AlterSystem(pgPool *pgxpool.Pool, name string, value string) error

func ArtificiallyFailingQueries

func ArtificiallyFailingQueries(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func Autovacuum

func Autovacuum(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func BufferCacheHitRatio

func BufferCacheHitRatio(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

BufferCacheHitRatio returns the buffer cache hit ratio. The current implementation gets only the hit ratio for the current database, we intentionally avoid aggregating the hit ratio for all databases, as this may add much noise from unused DBs.

func DataDirectory

func DataDirectory(pgPool *pgxpool.Pool) (string, error)

func DatabaseSize

func DatabaseSize(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

DatabaseSize returns the size of all the databases combined in bytes

func DetectConfigFromConfigFile

func DetectConfigFromConfigFile() bool

func DetectConfigFromEnv

func DetectConfigFromEnv() bool

func GetActiveConfig

func GetActiveConfig(
	pool *pgxpool.Pool,
	ctx context.Context,
	logger *logrus.Logger,
) (agent.ConfigArraySchema, error)

func MaxConnections

func MaxConnections(pgPool *pgxpool.Pool) (uint32, error)

func PGStatStatements

func PGStatStatements(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func PGVersion

func PGVersion(pgPool *pgxpool.Pool) (string, error)

Example: 16.4

func ReloadConfig

func ReloadConfig(pgPool *pgxpool.Pool) error

func Select1

func Select1(pgPool *pgxpool.Pool) error

func TransactionsPerSecond

func TransactionsPerSecond(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func Uptime

func Uptime(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func WaitEvents

func WaitEvents(pgPool *pgxpool.Pool) func(ctx context.Context, state *agent.MetricsState) error

func WaitPostgresReady

func WaitPostgresReady(pgPool *pgxpool.Pool) error

Types

type Config

type Config struct {
	ConnectionURL string `mapstructure:"connection_url" validate:"required"`
	ServiceName   string `mapstructure:"service_name"`
}

func ConfigFromViper

func ConfigFromViper(key *string) (Config, error)

Jump to

Keyboard shortcuts

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