Skip to content

Conversation

@irfanhabib
Copy link

Motivation

The current pg_stat_statements collector only exports total execution time, which makes it difficult to understand query performance patterns. These new metrics allow users to:

  • Identify queries with high execution time variance
  • Detect performance regressions in individual query runs
  • Better understand query performance distribution beyond just totals
  • Set more informed alerting thresholds based on typical vs. maximum execution times

Changes

  • Added three new Prometheus metric descriptors for max, mean, and standard deviation timing
  • Updated all SQL query templates to include the appropriate columns for different PostgreSQL versions:
    • PostgreSQL < 13: max_time, mean_time, stddev_time
    • PostgreSQL 13+: max_exec_time, mean_exec_time, stddev_exec_time
  • Modified the Update function to scan and emit the new metrics as gauge values
  • Updated test cases to handle the additional columns

Compatibility

  • Maintains backward compatibility with existing metrics
  • Supports all PostgreSQL versions currently supported by the exporter
  • Uses appropriate column names based on PostgreSQL version detection
@irfanhabib irfanhabib force-pushed the master branch 2 times, most recently from 3825f65 to 1aa3613 Compare May 29, 2025 16:37
@irfanhabib irfanhabib marked this pull request as draft May 30, 2025 08:25
@irfanhabib irfanhabib marked this pull request as ready for review May 30, 2025 09:57
- Add postgres_stat_statements_max_seconds metric for maximum execution time - Add postgres_stat_statements_mean_seconds metric for average execution time - Add postgres_stat_statements_stddev_seconds metric for execution time variance - Support all PostgreSQL versions with appropriate column names - Update test cases to include new metrics Signed-off-by: Irfan Habib <irfan@irfanhabib.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant