Documentationpg_stat_insights Documentation

Metrics Reference Guide

Workflow Overview

View metrics via pg_stat_insights or specialised views such as pg_stat_insights_plan, pg_stat_insights_io, and pg_stat_insights_waits. Combine identifiers with execution/caching metrics for a holistic profile of each statement.

Sample metric projection

SELECT queryid,
       calls,
       total_exec_time,
       shared_blks_hit,
       shared_blks_read,
       wal_bytes,
       parallel_workers_launched,
       jit_generation_time
  FROM pg_stat_insights
 ORDER BY total_exec_time DESC
 LIMIT 20;

Identity & Classification

userid, dbid, queryid

Identifiers for role, database, and fingerprint. Join with pg_roles and pg_database for human-readable names.

query

Normalized text of the statement. Use alongside queryid to fetch the canonical SQL.

calls, rows

Execution count and rows returned. Combine to compute throughput and efficiency.

Execution & Timing

total_exec_time, mean_exec_time, min/max/stddev_exec_time

Aggregate, average, and variability of execution time. Use stddev to detect jitter.

total_plan_time, mean_plan_time

Time spent planning statements (requires track_planning).

blk_read_time, blk_write_time

Block-level read/write timings (requires track_io_timing).

Cache, IO & WAL

shared_blks_hit / read / dirtied / written

Shared buffer interaction. Combine to compute cache hit ratio and flush pressure.

temp_blks_read / written

Temporary file usage signalling sorts or hash spills.

wal_bytes, wal_fpi_bytes, wal_records

WAL generation cost. Useful for analysing write amplification.

Advanced (Parallel & JIT)

parallel_workers_planned / launched / rejected

Parallel executor information for speedup analysis.

jit_functions, jit_generation_time, jit_emission_time…

LLVM compilation metrics indicating JIT overhead (track_planning required).

plans_since_last_reset, plans_with_leader_participation

Planner statistics for monitoring resets and leader activity.

Reset & Retention

Metrics accumulate until reset. Schedule resets post-maintenance or collect deltas into historical tables for trend analysis.

Reset command

SELECT pg_stat_insights_reset();

Resets also clear derived views such as pg_stat_insights_plan. Capture baselines prior to reset if you rely on historical comparisons.