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 ¶
const ( CommandAnalyze = "analyze" CommandVacuum = "vacuum" CommandVacuumFull = "vacuum_full" CommandReindex = "reindex" )
The maintenance commands.
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 ¶
var Commands = []string{CommandAnalyze, CommandVacuum, CommandVacuumFull, CommandReindex}
Commands are the maintenance commands, in the order they are documented.
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.
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 ¶
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.
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.