Documentationpg_stat_insights Documentation
Troubleshooting
Fast Triage Checklist
Use these guided diagnostics to fix preload errors, missing metrics, excessive overhead, and reset issues. Each section provides ready-to-run SQL or configuration commands.
- Verify
shared_preload_librariesincludes pg_stat_insights and PostgreSQL was restarted - Run
SELECT * FROM pg_extension WHERE extname = 'pg_stat_insights';to confirm the installed version - Check
log_min_messages = debug1temporarily if extension loading fails - Collect
EXPLAIN (ANALYZE, BUFFERS)plans before tuning query-level metrics
Run remediation in staging first. Revert temporary settings (e.g. debug logging) after successful validation.
Extension Load & Setup
Solve common installation and configuration errors that prevent pg_stat_insights from loading.
Check shared_preload_libraries
Confirm preload
SHOW shared_preload_libraries;Install or update extension
Install commands
CREATE EXTENSION IF NOT EXISTS pg_stat_insights;
ALTER EXTENSION pg_stat_insights UPDATE;Capture load errors
PostgreSQL logs
journalctl -u postgresql -n 100 | grep pg_stat_insightsMissing or Incomplete Metrics
Ensure collections are running and view-specific tables are populated.
Check primary view
Verify rows
SELECT COUNT(*) AS fingerprints
FROM pg_stat_insights;Increase retention & max fingerprints
Adjust GUCs
ALTER SYSTEM SET pg_stat_insights.max = 10000;
ALTER SYSTEM SET pg_stat_insights.save = true;
SELECT pg_reload_conf();Reset safely
Reset command
SELECT pg_stat_insights_reset();High Overhead or Bloat
Reduce collection overhead when pg_stat_insights impacts latency or memory.
Disable planning metrics temporarily
Toggle planning
ALTER SYSTEM SET pg_stat_insights.track_planning = false;
SELECT pg_reload_conf();Filter utility commands
Utility filter
ALTER SYSTEM SET pg_stat_insights.track_utility = false;
SELECT pg_reload_conf();Archive snapshots & vacuum stats schema
Maintenance
VACUUM ANALYZE pg_stat_insights;
VACUUM ANALYZE pg_stat_insights_plan;Export & Alerting
Wire pg_stat_insights metrics into Prometheus/Grafana and alert on regressions.
Prometheus scrape excerpt
queries.yml
pg_stat_insights:
query: |
SELECT queryid,
calls,
total_exec_time,
mean_exec_time
FROM pg_stat_insights
WHERE calls > 100;
metrics:
- queryid:
usage: "LABEL"
- calls:
usage: "COUNTER"
- total_exec_time:
usage: "COUNTER"
- mean_exec_time:
usage: "GAUGE"Example alert rule
Alertmanager rule
- alert: SlowQueriesSpike
expr: topk(1, increase(pg_stat_insights_total_exec_time[10m])) > 1.5e05
for: 5m
labels:
severity: warning