pgsp

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 11 Imported by: 0

README

pgsp - PostgreSQL Stat Progress CLI Monitor

Go Reference

A CUI tool that monitors PostgreSQL's pg_stat_progress*.

Supported progress reports are ANALYZE, CLUSTER, CREATE INDEX, VACUUM, COPY, and BASE_BACKUP. See Progress Reporting for more information.

pgsp.png

Requires

go 1.18 or later

Install

Download binary

releases page.

Go install
go install github.com/noborus/pgsp/cmd/pgsp@latest

Usage

Shows a progress bar if pg_stat_progress* is updated while waiting while running.

$ pgsp --dsn 'host=/var/run/postgresql port=5432'
Using config file: /home/noborus/.pgsp.yaml
quit: q, ctrl+c, esc
pg_stat_progress_basebackup
 pid                  | 402006
 phase                | streaming database files
 backup_total         | 10976660480
 backup_streamed      | 6093522944
 tablespaces_total    | 1
 tablespaces_streamed | 0

█████████████████████████░░░░░░░░░░░░░░░░░░  56%

It is also possible to specify one of the analyze, basebackup, cluster, createindex, vacuums, copy for monitoring.

pgsp basebackup
Monitors PostgreSQL's pg_stat_progress_*.

Usage:
  pgsp [flags]
  pgsp [command]

Available Commands:
  analyze     analyze
  basebackup  basebackup
  cluster     cluster
  copy        copy
  createindex createindex
  help        Help about any command
  vacuum      vacuum

Flags:
  -a, --AfterCompletion int   Time to display after completion(Seconds) (default 10)
  -i, --Interval float        Update interval(Seconds) (default 0.5)
      --config string         config file (default is $HOME/.pgsp.yaml)
      --dsn string            PostgreSQL data source name
  -f, --fullscreen            Display in Full Screen
  -h, --help                  help for pgsp
  -t, --toggle                Help message for toggle
  -v, --version               display version information

Use "pgsp [command] --help" for more information about a command.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AnalyzeTableName = "pg_stat_progress_analyze"
	AnalyzeQuery     string
	AnalyzeColumns   []string
)
View Source
var (
	BaseBackupTableName = "pg_stat_progress_basebackup"
	BaseBackupQuery     string
	BaseBackupColumns   []string
)
View Source
var (
	ClusterTableName = "pg_stat_progress_cluster"
	ClusterQuery     string
	ClusterColumns   []string
)
View Source
var (
	CopyTableName = "pg_stat_progress_copy"
	CopyQuery     string
	CopyColumns   []string
)
View Source
var (
	CreateIndexQuery   string
	CreateIndexColumns []string
)
View Source
var (
	VacuumTableName = "pg_stat_progress_vacuum"
	VacuumQuery     string
	VacuumColumns   []string
)
View Source
var CreateIndexTableName = "pg_stat_progress_create_index"

Functions

func Connect

func Connect(dsn string) (*sqlx.DB, error)

Types

type Analyze

type Analyze struct {
	PID                    int    `db:"pid"`
	DATID                  int    `db:"datid"`
	DATNAME                string `db:"datname"`
	RELID                  int    `db:"relid"`
	PHASE                  string `db:"phase"`
	SampleBLKSTotal        int64  `db:"sample_blks_total"`
	SampleBLKSScanned      int64  `db:"sample_blks_scanned"`
	ExtStatsTotal          int64  `db:"ext_stats_total"`
	ExtStatsComputed       int64  `db:"ext_stats_computed"`
	ChildTablesTotal       int64  `db:"child_tables_total"`
	ChildTablesDone        int64  `db:"child_tables_done"`
	CurrentChildTableRelid int    `db:"current_child_table_relid"`
}

pg_stat_progress_analyze.

func (Analyze) Color added in v0.0.3

func (v Analyze) Color() (string, string)

func (Analyze) Name

func (v Analyze) Name() string

func (Analyze) Pid

func (v Analyze) Pid() int

func (Analyze) Progress

func (v Analyze) Progress() float64

func (Analyze) Table

func (v Analyze) Table() string

func (Analyze) Vertical

func (v Analyze) Vertical() string

type BaseBackup

type BaseBackup struct {
	PID                 int           `db:"pid"`
	PHASE               string        `db:"phase"`
	BackupTotal         sql.NullInt64 `db:"backup_total"`
	BackupStreamed      int64         `db:"backup_streamed"`
	TablespacesTotal    int64         `db:"tablespaces_total"`
	TablespacesStreamed int64         `db:"tablespaces_streamed"`
}

pg_stat_progress_basebackup.

func (BaseBackup) Color added in v0.0.3

func (v BaseBackup) Color() (string, string)

func (BaseBackup) Name

func (v BaseBackup) Name() string

func (BaseBackup) Pid

func (v BaseBackup) Pid() int

func (BaseBackup) Progress

func (v BaseBackup) Progress() float64

func (BaseBackup) Table

func (v BaseBackup) Table() string

func (BaseBackup) Vertical

func (v BaseBackup) Vertical() string

type Cluster

type Cluster struct {
	PID               int    `db:"pid"`
	DATID             int    `db:"datid"`
	DATNAME           string `db:"datname"`
	RELID             int    `db:"relid"`
	Command           string `db:"command"`
	PHASE             string `db:"phase"`
	ClusterIndexRelid int64  `db:"cluster_index_relid"`
	HeapTuplesScanned int64  `db:"heap_tuples_scanned"`
	HeapTuplesWritten int64  `db:"heap_tuples_written"`
	HeapBlksTotal     int64  `db:"heap_blks_total"`
	HeapBlksScanned   int64  `db:"heap_blks_scanned"`
	IndexRebuildCount int64  `db:"index_rebuild_count"`
}

pg_stat_progress_Cluster.

func (Cluster) Color added in v0.0.3

func (v Cluster) Color() (string, string)

func (Cluster) Name

func (v Cluster) Name() string

func (Cluster) Pid

func (v Cluster) Pid() int

func (Cluster) Progress

func (v Cluster) Progress() float64

func (Cluster) Table

func (v Cluster) Table() string

func (Cluster) Vertical

func (v Cluster) Vertical() string

type Copy added in v0.0.2

type Copy struct {
	PID             int    `db:"pid"`
	DATID           int    `db:"datid"`
	DATNAME         string `db:"datname"`
	RELID           int    `db:"relid"`
	COMMAND         string `db:"command"`
	CTYPE           string `db:"type"`
	BYTESProcessed  int64  `db:"bytes_processed"`
	BYTESTotal      int64  `db:"bytes_total"`
	TUPLESProcessed int64  `db:"tuples_processed"`
	TUPLESExcluded  int64  `db:"tuples_excluded"`
}

pg_stat_progress_copy

func (Copy) Color added in v0.0.3

func (v Copy) Color() (string, string)

func (Copy) Name added in v0.0.2

func (v Copy) Name() string

func (Copy) Pid added in v0.0.2

func (v Copy) Pid() int

func (Copy) Progress added in v0.0.2

func (v Copy) Progress() float64

func (Copy) Table added in v0.0.2

func (v Copy) Table() string

func (Copy) Vertical added in v0.0.2

func (v Copy) Vertical() string

type CreateIndex

type CreateIndex struct {
	PID             int    `db:"pid"`
	DATID           int    `db:"datid"`
	DATNAME         string `db:"datname"`
	RELID           int    `db:"relid"`
	IndexRelid      int    `db:"index_relid"`
	Command         string `db:"command"`
	PHASE           string `db:"phase"`
	LockersTotal    int64  `db:"lockers_total"`
	LockersDone     int64  `db:"lockers_done"`
	LockersPid      int64  `db:"current_locker_pid"`
	BlocksTotal     int64  `db:"blocks_total"`
	BlocksDone      int64  `db:"blocks_done"`
	TuplesTotal     int64  `db:"tuples_total"`
	TuplesDone      int64  `db:"tuples_done"`
	PartitionsTotal int64  `db:"partitions_total"`
	PartitionsDone  int64  `db:"partitions_done"`
}

pg_stat_progress_create_index

func (CreateIndex) Color added in v0.0.3

func (v CreateIndex) Color() (string, string)

func (CreateIndex) Name

func (v CreateIndex) Name() string

func (CreateIndex) Pid

func (v CreateIndex) Pid() int

func (CreateIndex) Progress

func (v CreateIndex) Progress() float64

func (CreateIndex) Table

func (v CreateIndex) Table() string

func (CreateIndex) Vertical

func (v CreateIndex) Vertical() string

type Pgsp added in v0.0.3

type Pgsp struct {
	DB           *sqlx.DB
	StatProgress StatProgress
}

func New added in v0.0.3

func New(dsn string) (*Pgsp, error)

func (*Pgsp) DisConnect added in v0.0.3

func (p *Pgsp) DisConnect() error

func (*Pgsp) TargetString added in v0.0.3

func (p *Pgsp) TargetString() string

func (*Pgsp) Targets added in v0.0.3

func (p *Pgsp) Targets(target []string)

type Progress added in v0.0.3

type Progress interface {
	Name() string
	Pid() int
	Color() (string, string)
	Table() string
	Vertical() string
	Progress() float64
}

func GetAnalyze

func GetAnalyze(ctx context.Context, db *sqlx.DB) ([]Progress, error)

func GetBaseBackup

func GetBaseBackup(ctx context.Context, db *sqlx.DB) ([]Progress, error)

func GetCluster

func GetCluster(ctx context.Context, db *sqlx.DB) ([]Progress, error)

func GetCopy added in v0.0.2

func GetCopy(ctx context.Context, db *sqlx.DB) ([]Progress, error)

func GetCreateIndex

func GetCreateIndex(ctx context.Context, db *sqlx.DB) ([]Progress, error)

func GetVacuum

func GetVacuum(ctx context.Context, db *sqlx.DB) ([]Progress, error)

type SPTable added in v0.0.3

type SPTable struct {
	Enable bool
	Get    func(ctx context.Context, db *sqlx.DB) ([]Progress, error)
}

type SPTaget added in v0.0.3

type SPTaget string
const (
	SPAnalyze     SPTaget = "Analyze"
	SPCreateIndex SPTaget = "CreateIndex"
	SPVacuum      SPTaget = "Vacuum"
	SPCluster     SPTaget = "Cluster"
	SPBaseBackup  SPTaget = "BaseBackup"
	SPCopy        SPTaget = "Copy"
)

type StatProgress added in v0.0.3

type StatProgress map[SPTaget]*SPTable

func NewMonitor added in v0.0.3

func NewMonitor() StatProgress

type Vacuum

type Vacuum struct {
	PID              int    `db:"pid"`
	DATID            int    `db:"datid"`
	DATNAME          string `db:"datname"`
	RELID            int    `db:"relid"`
	PHASE            string `db:"phase"`
	HeapBLKSTotal    int64  `db:"heap_blks_total"`
	HeapBLKSScanned  int64  `db:"heap_blks_scanned"`
	HeapBLKSVacuumed int64  `db:"heap_blks_vacuumed"`
	IndexVacuumCount int64  `db:"index_vacuum_count"`
	MaxDeadTuples    int64  `db:"max_dead_tuples"`
	NumDeadTuples    int64  `db:"num_dead_tuples"`
}

pg_stat_progress_vacuum

func (Vacuum) Color added in v0.0.3

func (v Vacuum) Color() (string, string)

func (Vacuum) Name

func (v Vacuum) Name() string

func (Vacuum) Pid

func (v Vacuum) Pid() int

func (Vacuum) Progress

func (v Vacuum) Progress() float64

func (Vacuum) Table

func (v Vacuum) Table() string

func (Vacuum) Vertical

func (v Vacuum) Vertical() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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