Documentation
¶
Index ¶
- type BrokenIndexesRow
- type ConnectionStatsRow
- type DBTX
- type DatabaseCacheEfficiencyRow
- type DatabaseFreezeAgeRow
- type DuplicateIndexesRow
- type HighSeqScanTablesRow
- type IdleInTransactionRow
- type IndexBloatRow
- type IndexUsageStatsRow
- type InvalidPrimaryKeyTypesRow
- type LargeTablesRow
- type LongIdleConnectionsRow
- type MissingProviderIdTablesRow
- type PGVersionRow
- type PartitionedTablesWithKeysRow
- type Queries
- func (q *Queries) BrokenIndexes(ctx context.Context) ([]BrokenIndexesRow, error)
- func (q *Queries) ConnectionStats(ctx context.Context) (ConnectionStatsRow, error)
- func (q *Queries) DatabaseCacheEfficiency(ctx context.Context) (DatabaseCacheEfficiencyRow, error)
- func (q *Queries) DatabaseFreezeAge(ctx context.Context) ([]DatabaseFreezeAgeRow, error)
- func (q *Queries) DuplicateIndexes(ctx context.Context) ([]DuplicateIndexesRow, error)
- func (q *Queries) HasPgStatStatements(ctx context.Context) (bool, error)
- func (q *Queries) HighSeqScanTables(ctx context.Context) ([]HighSeqScanTablesRow, error)
- func (q *Queries) IdleInTransaction(ctx context.Context) ([]IdleInTransactionRow, error)
- func (q *Queries) IndexBloat(ctx context.Context) ([]IndexBloatRow, error)
- func (q *Queries) IndexUsageStats(ctx context.Context) ([]IndexUsageStatsRow, error)
- func (q *Queries) InvalidPrimaryKeyTypes(ctx context.Context) ([]InvalidPrimaryKeyTypesRow, error)
- func (q *Queries) LargeTables(ctx context.Context) ([]LargeTablesRow, error)
- func (q *Queries) LongIdleConnections(ctx context.Context) ([]LongIdleConnectionsRow, error)
- func (q *Queries) MissingProviderIdTables(ctx context.Context) ([]MissingProviderIdTablesRow, error)
- func (q *Queries) PGVersion(ctx context.Context) (PGVersionRow, error)
- func (q *Queries) PartitionedTablesWithKeys(ctx context.Context) ([]PartitionedTablesWithKeysRow, error)
- func (q *Queries) QueryStatsFromStatStatements(ctx context.Context) ([]QueryStatsFromStatStatementsRow, error)
- func (q *Queries) ReplicationLag(ctx context.Context) ([]ReplicationLagRow, error)
- func (q *Queries) ReplicationSlots(ctx context.Context) ([]ReplicationSlotsRow, error)
- func (q *Queries) ReplicationSlotsPG15(ctx context.Context) ([]ReplicationSlotsPG15Row, error)
- func (q *Queries) SequenceHealth(ctx context.Context) ([]SequenceHealthRow, error)
- func (q *Queries) SessionSettings(ctx context.Context) ([]SessionSettingsRow, error)
- func (q *Queries) SessionStatistics(ctx context.Context) (SessionStatisticsRow, error)
- func (q *Queries) StatisticsFreshness(ctx context.Context) (StatisticsFreshnessRow, error)
- func (q *Queries) TableActivity(ctx context.Context) ([]TableActivityRow, error)
- func (q *Queries) TableBloat(ctx context.Context) ([]TableBloatRow, error)
- func (q *Queries) TableFreezeAge(ctx context.Context) ([]TableFreezeAgeRow, error)
- func (q *Queries) TableVacuumHealth(ctx context.Context) ([]TableVacuumHealthRow, error)
- func (q *Queries) TempUsage(ctx context.Context) (TempUsageRow, error)
- func (q *Queries) ToastStorage(ctx context.Context) ([]ToastStorageRow, error)
- func (q *Queries) UuidColumnDefaults(ctx context.Context) ([]UuidColumnDefaultsRow, error)
- func (q *Queries) UuidColumnsAsString(ctx context.Context) ([]UuidColumnsAsStringRow, error)
- func (q *Queries) VacuumSettings(ctx context.Context) ([]VacuumSettingsRow, error)
- func (q *Queries) WithTx(tx pgx.Tx) *Queries
- type QueryStatsFromStatStatementsRow
- type ReplicationLagRow
- type ReplicationSlotsPG15Row
- type ReplicationSlotsRow
- type SequenceHealthRow
- type SessionSettingsRow
- type SessionStatisticsRow
- type StatisticsFreshnessRow
- type TableActivityRow
- type TableBloatRow
- type TableFreezeAgeRow
- type TableVacuumHealthRow
- type TempUsageRow
- type ToastStorageRow
- type UuidColumnDefaultsRow
- type UuidColumnsAsStringRow
- type VacuumSettingsRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BrokenIndexesRow ¶
type ConnectionStatsRow ¶
type DatabaseFreezeAgeRow ¶
type DuplicateIndexesRow ¶
type HighSeqScanTablesRow ¶
type IdleInTransactionRow ¶
type IndexBloatRow ¶
type IndexUsageStatsRow ¶
type IndexUsageStatsRow struct {
TableName pgtype.Text
IndexName pgtype.Text
NumRows pgtype.Int8
IsPrimary bool
IsUnique bool
IndexSizeBytes pgtype.Int8
IdxScan pgtype.Int8
IdxTupRead pgtype.Int8
IdxTupFetch pgtype.Int8
TableWrites pgtype.Int8
IdxBlksHit pgtype.Int8
IdxBlksRead pgtype.Int8
CacheHitRatio pgtype.Numeric
Indexdef pgtype.Text
}
type LargeTablesRow ¶
type LongIdleConnectionsRow ¶
type PGVersionRow ¶
type PartitionedTablesWithKeysRow ¶
type PartitionedTablesWithKeysRow struct {
SchemaName pgtype.Text
TableName pgtype.Text
PartitionStrategy pgtype.Text
PartitionKeyColumns pgtype.Text
HasExpressionKey pgtype.Bool
PartitionCount pgtype.Int8
TotalSizeBytes pgtype.Int8
EstimatedRows pgtype.Int8
TotalSeqScans pgtype.Int8
TotalIdxScans pgtype.Int8
}
type Queries ¶
type Queries struct {
// contains filtered or unexported fields
}
func (*Queries) BrokenIndexes ¶
func (q *Queries) BrokenIndexes(ctx context.Context) ([]BrokenIndexesRow, error)
func (*Queries) ConnectionStats ¶
func (q *Queries) ConnectionStats(ctx context.Context) (ConnectionStatsRow, error)
Gets overall connection statistics including pool sizing metrics.
func (*Queries) DatabaseCacheEfficiency ¶
func (q *Queries) DatabaseCacheEfficiency(ctx context.Context) (DatabaseCacheEfficiencyRow, error)
Returns database-wide buffer cache hit ratio. Low ratios indicate shared_buffers too small or working set exceeds memory.
func (*Queries) DatabaseFreezeAge ¶
func (q *Queries) DatabaseFreezeAge(ctx context.Context) ([]DatabaseFreezeAgeRow, error)
Gets transaction ID age for all databases.
func (*Queries) DuplicateIndexes ¶
func (q *Queries) DuplicateIndexes(ctx context.Context) ([]DuplicateIndexesRow, error)
Identifies exact and prefix duplicate indexes on the same table. Uses index column positions (indkey) for prefix detection. Excludes: system schemas, invalid indexes, expression/partial indexes for prefix check.
func (*Queries) HasPgStatStatements ¶
Checks if pg_stat_statements extension is installed.
func (*Queries) HighSeqScanTables ¶
func (q *Queries) HighSeqScanTables(ctx context.Context) ([]HighSeqScanTablesRow, error)
Identifies tables with excessive sequential scans relative to index scans. Excludes: small tables, system schemas, tables with no indexes.
func (*Queries) IdleInTransaction ¶
func (q *Queries) IdleInTransaction(ctx context.Context) ([]IdleInTransactionRow, error)
Identifies connections stuck in 'idle in transaction' state. Includes the timeout setting (in ms) for threshold calculation in Go.
func (*Queries) IndexBloat ¶
func (q *Queries) IndexBloat(ctx context.Context) ([]IndexBloatRow, error)
Balanced B-tree index bloat estimation using pg_stats column widths Accuracy: ±15% (good enough for health checks, not precision measurement)
func (*Queries) IndexUsageStats ¶
func (q *Queries) IndexUsageStats(ctx context.Context) ([]IndexUsageStatsRow, error)
Identifies indexes with usage statistics for health analysis. Excludes: system schemas. Returns data for subchecks: unused-indexes, low-usage-indexes, index-cache-ratio.
func (*Queries) InvalidPrimaryKeyTypes ¶
func (q *Queries) InvalidPrimaryKeyTypes(ctx context.Context) ([]InvalidPrimaryKeyTypesRow, error)
Identifies tables with integer primary keys (int2/int4) that should use bigint.
func (*Queries) LargeTables ¶
func (q *Queries) LargeTables(ctx context.Context) ([]LargeTablesRow, error)
Identifies all large tables (>= 10M rows) with partitioning and transient status. Returns both regular and partitioned tables for unified analysis. Includes activity metrics (inserts/updates/deletes) for activity-aware thresholds.
func (*Queries) LongIdleConnections ¶
func (q *Queries) LongIdleConnections(ctx context.Context) ([]LongIdleConnectionsRow, error)
Identifies connections that have been idle for too long (potential pool leak).
func (*Queries) MissingProviderIdTables ¶
func (q *Queries) MissingProviderIdTables(ctx context.Context) ([]MissingProviderIdTablesRow, error)
Identifies tables without provider_id column for multi-tenancy support.
func (*Queries) PartitionedTablesWithKeys ¶
func (q *Queries) PartitionedTablesWithKeys(ctx context.Context) ([]PartitionedTablesWithKeysRow, error)
Gets partitioned tables and their partition key column(s). Pre-aggregates all partition statistics in a single CTE for better performance compared to multiple correlated subqueries.
func (*Queries) QueryStatsFromStatStatements ¶
func (q *Queries) QueryStatsFromStatStatements(ctx context.Context) ([]QueryStatsFromStatStatementsRow, error)
Gets query statistics from pg_stat_statements for partition key analysis. Returns queries with significant usage to check against partitioned tables.
func (*Queries) ReplicationLag ¶
func (q *Queries) ReplicationLag(ctx context.Context) ([]ReplicationLagRow, error)
Monitors replication lag for both physical and logical replication streams. Joins with pg_replication_slots to get authoritative replication type and slot information.
func (*Queries) ReplicationSlots ¶
func (q *Queries) ReplicationSlots(ctx context.Context) ([]ReplicationSlotsRow, error)
For PostgreSQL 17+: includes inactive_since, conflicting, invalidation_reason
func (*Queries) ReplicationSlotsPG15 ¶
func (q *Queries) ReplicationSlotsPG15(ctx context.Context) ([]ReplicationSlotsPG15Row, error)
For PostgreSQL 15/16: columns conflicting, invalidation_reason, inactive_since don't exist
func (*Queries) SequenceHealth ¶
func (q *Queries) SequenceHealth(ctx context.Context) ([]SequenceHealthRow, error)
Identifies sequences approaching their maximum values and integer columns that should be bigint Find columns that own sequences (SERIAL/BIGSERIAL columns) Check if columns are primary keys Count foreign keys referencing each column (as the referenced/target column)
func (*Queries) SessionSettings ¶
func (q *Queries) SessionSettings(ctx context.Context) ([]SessionSettingsRow, error)
func (*Queries) SessionStatistics ¶
func (q *Queries) SessionStatistics(ctx context.Context) (SessionStatisticsRow, error)
Gets session time statistics from pg_stat_database (PostgreSQL 14+). These stats help analyze connection pool efficiency. Returns zero values for PostgreSQL versions < 14 (columns don't exist).
func (*Queries) StatisticsFreshness ¶
func (q *Queries) StatisticsFreshness(ctx context.Context) (StatisticsFreshnessRow, error)
Returns statistics age for the current database. Use to validate stats are meaningful before relying on usage-based checks.
func (*Queries) TableActivity ¶
func (q *Queries) TableActivity(ctx context.Context) ([]TableActivityRow, error)
Retrieves table write activity metrics from pg_stat_user_tables Used to identify high-churn tables and HOT update efficiency issues
func (*Queries) TableBloat ¶
func (q *Queries) TableBloat(ctx context.Context) ([]TableBloatRow, error)
Identifies tables with high dead tuple percentages indicating vacuum issues
func (*Queries) TableFreezeAge ¶
func (q *Queries) TableFreezeAge(ctx context.Context) ([]TableFreezeAgeRow, error)
Gets transaction ID age for tables with oldest frozen XIDs.
func (*Queries) TableVacuumHealth ¶
func (q *Queries) TableVacuumHealth(ctx context.Context) ([]TableVacuumHealthRow, error)
Returns all tables with vacuum-related health metrics. Used by multiple subchecks: autovacuum-disabled, large-table-defaults, vacuum-stale, analyze-needed.
func (*Queries) TempUsage ¶
func (q *Queries) TempUsage(ctx context.Context) (TempUsageRow, error)
Monitors temporary file creation indicating work_mem exhaustion
func (*Queries) ToastStorage ¶
func (q *Queries) ToastStorage(ctx context.Context) ([]ToastStorageRow, error)
Analyzes TOAST storage usage and identifies tables with large value storage
func (*Queries) UuidColumnDefaults ¶
func (q *Queries) UuidColumnDefaults(ctx context.Context) ([]UuidColumnDefaultsRow, error)
Find UUID columns with their DEFAULT expressions to detect random UUID usage.
func (*Queries) UuidColumnsAsString ¶
func (q *Queries) UuidColumnsAsString(ctx context.Context) ([]UuidColumnsAsStringRow, error)
Identifies columns that appear to store UUIDs but use string types.
func (*Queries) VacuumSettings ¶
func (q *Queries) VacuumSettings(ctx context.Context) ([]VacuumSettingsRow, error)
noqa: disable=RF04
type ReplicationLagRow ¶
type ReplicationSlotsPG15Row ¶
type ReplicationSlotsPG15Row struct {
SlotName pgtype.Text
SlotType pgtype.Text
Plugin pgtype.Text
Database pgtype.Text
Active pgtype.Bool
ActivePid pgtype.Int4
WalStatus pgtype.Text
SafeWalSize pgtype.Int8
Temporary pgtype.Bool
Conflicting pgtype.Bool
InvalidationReason pgtype.Text
RestartLsnLagBytes pgtype.Int8
ConfirmedFlushLsnLagBytes pgtype.Int8
InactiveSeconds pgtype.Int8
}
type ReplicationSlotsRow ¶
type ReplicationSlotsRow struct {
SlotName pgtype.Text
SlotType pgtype.Text
Plugin pgtype.Text
Database pgtype.Text
Active pgtype.Bool
ActivePid pgtype.Int4
WalStatus pgtype.Text
SafeWalSize pgtype.Int8
Temporary pgtype.Bool
Conflicting pgtype.Bool
InvalidationReason pgtype.Text
RestartLsnLagBytes pgtype.Int8
ConfirmedFlushLsnLagBytes pgtype.Int8
InactiveSeconds pgtype.Int8
}
type SequenceHealthRow ¶
type SequenceHealthRow struct {
SchemaName pgtype.Text
SequenceName pgtype.Text
SeqDataType pgtype.Text
CurrentValue pgtype.Int8
MaxValue pgtype.Int8
IncrementBy pgtype.Int8
IsCyclic pgtype.Bool
RemainingValues pgtype.Int8
UsagePercent pgtype.Numeric
TableName pgtype.Text
ColumnName pgtype.Text
ColumnType pgtype.Text
ColumnMaxValue pgtype.Int8
SequenceExceedsColumn pgtype.Bool
ShouldBeBigint pgtype.Bool
IsPrimaryKey pgtype.Bool
FkReferenceCount pgtype.Int8
}
type SessionSettingsRow ¶
type SessionStatisticsRow ¶
type StatisticsFreshnessRow ¶
type TableActivityRow ¶
type TableBloatRow ¶
type TableBloatRow struct {
TableName pgtype.Text
LiveTuples pgtype.Int8
DeadTuples pgtype.Int8
LastAutovacuum pgtype.Timestamptz
LastVacuum pgtype.Timestamptz
LastAutoanalyze pgtype.Timestamptz
LastAnalyze pgtype.Timestamptz
AutovacuumCount pgtype.Int8
VacuumCount pgtype.Int8
ModificationsSinceAnalyze pgtype.Int8
DeadTuplePercent pgtype.Numeric
TotalSizeBytes pgtype.Int8
}
type TableFreezeAgeRow ¶
type TableVacuumHealthRow ¶
type TableVacuumHealthRow struct {
TableName pgtype.Text
LastAutovacuum pgtype.Timestamptz
EstimatedRows pgtype.Int8
TableSizeBytes pgtype.Int8
NDeadTup pgtype.Int8
AutovacuumCount pgtype.Int8
Reloptions pgtype.Text
LastVacuumAny pgtype.Timestamptz
LastAnalyzeAny pgtype.Timestamptz
NModSinceAnalyze pgtype.Int8
AutoanalyzeCount pgtype.Int8
NInsSinceVacuum pgtype.Int8
}
type TempUsageRow ¶
type TempUsageRow struct {
DatabaseName pgtype.Text
TempFiles pgtype.Int8
TempBytes pgtype.Int8
StatsReset pgtype.Timestamptz
SecondsSinceReset pgtype.Numeric
WorkMem pgtype.Text
TempFileLimit pgtype.Text
LogTempFiles pgtype.Text
MaxConnections pgtype.Text
TempFilesPerHour pgtype.Numeric
TempBytesPerHour pgtype.Numeric
}
type ToastStorageRow ¶
type ToastStorageRow struct {
SchemaName pgtype.Text
TableName pgtype.Text
ToastTableName pgtype.Text
MainTableSize pgtype.Int8
ToastSize pgtype.Int8
TotalSize pgtype.Int8
IndexesSize pgtype.Int8
ToastPercent pgtype.Numeric
ToastLiveTuples pgtype.Int8
ToastDeadTuples pgtype.Int8
WideColumns []string
ColumnCompressionInfo []string
}