Skip to content

Add max, mean, and stddev timing metrics to stat_statements collector #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
- 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>
@irfanhabib irfanhabib marked this pull request as ready for review May 30, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant