Skip to main content
View rawEdit

Metrics reference

Reference documentation for all metrics collected by PostgresAI monitoring.

Metric sources​

PostgresAI monitoring collects metrics from multiple PostgreSQL sources:

SourceDescriptionDashboard usage
pg_stat_statementsQuery-level performance metrics02, 03
pg_stat_activitySession and wait event data01, 04
pg_stat_user_tablesTable-level statistics07, 08, 09
pg_stat_user_indexesIndex usage statistics10, 11
pg_stat_replicationReplication metrics06
pg_stat_bgwriterBackground writer stats01
pg_stat_databaseDatabase-level aggregates01

Metric naming convention​

All metrics follow the pattern:

pg_{source}_{metric_name}

Examples:

  • pg_stat_statements_calls_total — Total query calls
  • pg_stat_activity_count — Active session count
  • pg_stat_user_tables_seq_scan_total — Sequential scans

Collection intervals​

Metric typeDefault intervalConfigurable
Session metrics10sYes
Query metrics60sYes
Table/index metrics60sYes
Replication metrics10sYes

Metric categories​

pg_stat_statements metrics​

Query performance metrics including:

  • Execution counts and timing
  • Row counts
  • Buffer usage
  • Planning time

Wait event metrics​

Active session history data:

  • Wait event types and categories
  • Session state distribution
  • Lock wait analysis

Table metrics​

Table-level statistics:

  • Sequential vs index scans
  • Dead tuple counts
  • HOT update ratios
  • Table sizes

Index metrics​

Index usage and health:

  • Scan counts
  • Tuple reads
  • Index sizes
  • Bloat estimates

System metrics​

PostgreSQL system-level metrics:

  • Connection counts
  • Transaction rates
  • Checkpoint activity
  • Buffer cache statistics

Prometheus/VictoriaMetrics queries​

All metrics are stored in VictoriaMetrics (Prometheus-compatible). Example queries:

Rate calculations​

# Queries per second
rate(pg_stat_statements_calls_total[5m])

# Transactions per second
rate(pg_stat_database_xact_commit_total[5m])

Aggregations​

# Total active sessions across all databases
sum(pg_stat_activity_count{state="active"})

# Average query time by database
avg by (datname) (pg_stat_statements_mean_exec_time_seconds)