Documentation
¶
Index ¶
- func ResolveSchemas(schemas []string) []string
- type ColumnInfo
- type Config
- type ConstraintInfo
- type IndexInfo
- type Inspector
- func (i *Inspector) Close()
- func (i *Inspector) GetColumns(ctx context.Context) ([]ColumnInfo, error)
- func (i *Inspector) GetConstraints(ctx context.Context) ([]ConstraintInfo, error)
- func (i *Inspector) GetIndexes(ctx context.Context) ([]IndexInfo, error)
- func (i *Inspector) GetTableStats(ctx context.Context) ([]TableStats, error)
- func (i *Inspector) GetTables(ctx context.Context) ([]TableInfo, error)
- func (i *Inspector) Inspect(ctx context.Context) (*Snapshot, error)
- func (i *Inspector) ServerVersion(ctx context.Context) (string, error)
- type Snapshot
- type TableInfo
- type TableStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveSchemas ¶
ResolveSchemas normalizes and expands schema filter values. Empty input means "all non-system schemas" (no filtering). "all" or "*" means the same. Otherwise returns the provided schemas.
Types ¶
type ColumnInfo ¶
type ColumnInfo struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
OrdinalPosition int `json:"ordinalPosition"`
DataType string `json:"dataType"`
IsNullable bool `json:"isNullable"`
ColumnDefault *string `json:"columnDefault,omitempty"`
}
ColumnInfo describes a table column.
type ConstraintInfo ¶
type ConstraintInfo struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
Type string `json:"type"` // p=primary key, u=unique, f=foreign key, c=check
Columns []string `json:"columns"`
RefTable *string `json:"refTable,omitempty"`
RefColumns []string `json:"refColumns,omitempty"`
}
ConstraintInfo describes a table constraint.
type IndexInfo ¶
type IndexInfo struct {
Schema string `json:"schema"`
Table string `json:"table"`
Name string `json:"name"`
Definition string `json:"definition"`
SizeBytes int64 `json:"sizeBytes"`
IndexScans int64 `json:"indexScans"`
TupRead int64 `json:"tupRead"`
TupFetch int64 `json:"tupFetch"`
}
IndexInfo describes an index with definition and usage stats.
type Inspector ¶
type Inspector struct {
// contains filtered or unexported fields
}
Inspector reads PostgreSQL catalog metadata and statistics.
func NewInspector ¶
NewInspector connects to PostgreSQL with retry on transient errors.
func (*Inspector) GetColumns ¶
func (i *Inspector) GetColumns(ctx context.Context) ([]ColumnInfo, error)
GetColumns fetches all user table columns.
func (*Inspector) GetConstraints ¶
func (i *Inspector) GetConstraints(ctx context.Context) ([]ConstraintInfo, error)
GetConstraints fetches all user table constraints with column names.
func (*Inspector) GetIndexes ¶
GetIndexes fetches all user indexes with definitions and usage stats.
func (*Inspector) GetTableStats ¶
func (i *Inspector) GetTableStats(ctx context.Context) ([]TableStats, error)
GetTableStats fetches usage statistics for all user tables.
type Snapshot ¶
type Snapshot struct {
Tables []TableInfo `json:"tables"`
Columns []ColumnInfo `json:"columns"`
Indexes []IndexInfo `json:"indexes"`
Stats []TableStats `json:"stats"`
Constraints []ConstraintInfo `json:"constraints"`
}
Snapshot holds the complete catalog metadata for a database.
func FilterSnapshot ¶
FilterSnapshot returns a new snapshot containing only objects in the given schemas. If schemas is nil or empty, the original snapshot is returned unmodified.
type TableInfo ¶
type TableInfo struct {
Schema string `json:"schema"`
Name string `json:"name"`
Type string `json:"type"` // BASE TABLE, VIEW, etc.
EstimatedRows int64 `json:"estimatedRows"` // from pg_class.reltuples
SizeBytes int64 `json:"sizeBytes"` // from pg_total_relation_size
}
TableInfo describes a table from information_schema + pg_class.
type TableStats ¶
type TableStats struct {
Schema string `json:"schema"`
Name string `json:"name"`
SeqScan int64 `json:"seqScan"`
SeqTupRead int64 `json:"seqTupRead"`
IdxScan int64 `json:"idxScan"`
IdxTupFetch int64 `json:"idxTupFetch"`
LiveTuples int64 `json:"liveTuples"`
DeadTuples int64 `json:"deadTuples"`
LastVacuum *time.Time `json:"lastVacuum,omitempty"`
LastAutovacuum *time.Time `json:"lastAutovacuum,omitempty"`
LastAnalyze *time.Time `json:"lastAnalyze,omitempty"`
LastAutoanalyze *time.Time `json:"lastAutoanalyze,omitempty"`
VacuumCount int64 `json:"vacuumCount"`
AutovacuumCount int64 `json:"autovacuumCount"`
AnalyzeCount int64 `json:"analyzeCount"`
AutoanalyzeCount int64 `json:"autoanalyzeCount"`
}
TableStats holds usage statistics from pg_stat_user_tables.