pg_info

package module
v0.0.0-...-048639c Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: MIT Imports: 8 Imported by: 0

README

pg_info makes it a bit easier to access the various pg_stat_* informational tables in PostgreSQL for getting metrics and such.

This is really unfinished and very much work-in-progress. You almost certainly don't want to use this yet.

Usage

Compile from source with go get zgo.at/pg_info/cmd/pg_info; this will put the binary in ~/go/bin.

There are three ways to use this: as a web interface, a CLI program, or by plugging it in to an existing Go web app:

Run HTTP server

$ pg_info serve -db '...'

The -db flag:

-db "dbname=goatcounter_paths sslmode=disable"
-db "postgres://host/db"

See pg_info help serve for some more details and flags.

CLI

Note: this isn't really usable yet; most of the focus is on the web interface for now.

$ EXPORT PGINFO_DB='...'                # Set a default for the -db flag

$ pg_info tables                        # Table overview.
$ pg_info tables -table foo -detail     # List all columns for "foo".
$ pg_info activity                      # pg_stat_activity.

$ pg_info pev 'select 1'
$ pg_info pev < query.sql

See pg_info help for some more commands and options for various commands.

Add to Go app:

Right now it kind-of requires chi:

r := chi.NewRouter()
r.Mount("/admin/sql", pghandler.New(db))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity []struct {
	PID      int64  `db:"pid"`
	Duration string `db:"duration"`
	Query    string `db:"query"`
}

Activity lists the current query activity from pg_stat_activity.

func (*Activity) Data

func (a *Activity) Data(ctx context.Context) error

func (Activity) Name

func (Activity) Name() string

type Column

type Column struct {
	AttName     string  `db:"attname"`
	NullFrac    float64 `db:"null_frac"`
	AvgWidth    int     `db:"avg_width"`
	NDistinct   float64 `db:"n_distinct"`
	Correlation float64 `db:"correlation"`
}

Column statistics.

func (Column) String

func (c Column) String() string

type Columns

type Columns []Column

func (*Columns) List

func (c *Columns) List(ctx context.Context, table string) error

List all column statistics for a table.

func (Columns) String

func (c Columns) String() string

type Explain

type Explain struct{ Prefix string }

func (Explain) Data

func (Explain) Data(context.Context) error

func (Explain) Name

func (Explain) Name() string

type Indexes

type Indexes []struct {
	Table    string `db:"relname"`
	Size     int    `db:"size"`
	Index    string `db:"indexrelname"`
	Scan     int64  `db:"idx_scan"`
	TupRead  int64  `db:"idx_tup_read"`
	TupFetch int64  `db:"idx_tup_fetch"`
}

Indexes lists information about indexes from pg_stat_user_indexes.

func (*Indexes) Data

func (i *Indexes) Data(ctx context.Context) error

func (Indexes) Name

func (Indexes) Name() string

type Progress

type Progress []struct {
	Table   string `db:"relname"`
	Command string `db:"command"`
	Phase   string `db:"phase"`
	Status  string `db:"status"`
}

Progress lists the progress of VACUUM, CLUSTER, and CREATE INDEX commands.

func (*Progress) Data

func (p *Progress) Data(ctx context.Context) error

func (Progress) Name

func (Progress) Name() string

type Statement

type Statement struct {
	Total      float64 `db:"total"`
	MeanTime   float64 `db:"mean_time"`
	MinTime    float64 `db:"min_time"`
	MaxTime    float64 `db:"max_time"`
	StdDevTime float64 `db:"stddev_time"`
	Calls      int     `db:"calls"`
	HitPercent float64 `db:"hit_percent"`
	QueryID    int64   `db:"queryid"`
	Query      string  `db:"query"`
}

Statement from pg_stat_statements.

type Statements

type Statements struct {
	Statements []Statement
	Filter     string
	Order      string
	Asc        bool
}

func (*Statements) Data

func (s *Statements) Data(ctx context.Context) error

func (Statements) Name

func (Statements) Name() string

type System

type System struct {
	LoadAvg, Memory, Disk string
}

System information.

func (*System) Data

func (s *System) Data(ctx context.Context) error

func (System) Name

func (System) Name() string

type Tables

type Tables []struct {
	Table   string `db:"relname"`
	SeqScan int64  `db:"seq_scan"`
	IdxScan int64  `db:"idx_scan"`
	SeqRead int64  `db:"seq_tup_read"`
	IdxRead int64  `db:"idx_tup_fetch"`

	LastVacuum      time.Time `db:"last_vacuum"`
	LastAutoVacuum  time.Time `db:"last_autovacuum"`
	LastAnalyze     time.Time `db:"last_analyze"`
	LastAutoAnalyze time.Time `db:"last_autoanalyze"`

	VacuumCount  int `db:"vacuum_count"`
	AnalyzeCount int `db:"analyze_count"`

	LiveTup         int64 `db:"n_live_tup"`
	DeadTup         int64 `db:"n_dead_tup"`
	ModSinceAnalyze int64 `db:"n_mod_since_analyze"`

	TableSize   int `db:"table_size"`
	IndexesSize int `db:"indexes_size"`
}

Tables overview from pg_stat_user_tables.

func (*Tables) Data

func (t *Tables) Data(ctx context.Context) error

func (Tables) Name

func (Tables) Name() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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