appdbops

package
v1.157.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package appdbops is maintenance of an application database (#2410): ANALYZE, VACUUM and REINDEX, run outside a transaction as the connection's own login under a lock timeout. The admin API and the platform.maintain script binding call it; creating or dropping an index is refused, naming manage_schema.

Index

Constants

View Source
const (
	CommandAnalyze    = "analyze"
	CommandVacuum     = "vacuum"
	CommandVacuumFull = "vacuum_full"
	CommandReindex    = "reindex"
)

The maintenance commands.

View Source
const DefaultLockTimeout = 5 * time.Second

DefaultLockTimeout is how long a maintenance statement waits for a lock before it gives up rather than queueing every statement behind it.

Variables

Commands are the maintenance commands, in the order they are documented.

View Source
var ErrSchemaChange = errors.New("the maintenance commands are analyze, vacuum, vacuum_full and reindex; " +
	"creating or dropping an index is a schema change: add it as a migration with manage_schema")

ErrSchemaChange refuses a command that would create or drop an index, or any other command: a change to the schema is a migration.

View Source
var ErrTableRequired = errors.New("vacuum_full and reindex act on one table; name it as table or schema.table")

ErrTableRequired refuses vacuum_full and reindex of a whole database.

Functions

func Statement

func Statement(command, table string) (string, error)

Statement is the statement a maintenance command runs: ANALYZE, VACUUM with ANALYZE, VACUUM FULL (which holds an ACCESS EXCLUSIVE lock on the table while it rewrites it), or REINDEX TABLE CONCURRENTLY. table is optional for analyze and vacuum, which then act on the whole database.

Types

type Maintainer

type Maintainer interface {
	RunMaintenance(ctx context.Context, connection, stmt string, lockTimeout, timeout time.Duration) error
}

Maintainer runs one maintenance statement outside a transaction: the postgres toolkit's RunMaintenance.

type Outcome

type Outcome struct {
	Connection string `json:"connection"`
	Command    string `json:"command"`
	Table      string `json:"table,omitempty"`
	// Statement is what ran.
	Statement  string `json:"statement"`
	DurationMS int64  `json:"duration_ms"`
}

Outcome is what a maintenance command did.

func Maintain

func Maintain(ctx context.Context, m Maintainer, req Request) (*Outcome, error)

Maintain runs a maintenance command.

type Request

type Request struct {
	Connection, Command string
	// Table is table or schema.table; analyze and vacuum act on the whole
	// database without one.
	Table string
	// LockTimeout is how long a lock is waited for (DefaultLockTimeout when
	// zero), Timeout how long the statement may run (the connection's
	// statement_timeout when zero).
	LockTimeout, Timeout time.Duration
}

Request is one maintenance command on one connection.

Jump to

Keyboard shortcuts

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