Skip to content

pg_stat_statements collectors should support disabling query-text retrieval #489

Description

@maltere

Describe the issue:

The postgres_exporter pg_stat_statements query files read the standard pg_stat_statements view in five separate collectors.

Four collectors export left(s.query, 40). The aggregate collector does not use s.query, but still reads the text-enabled view.

PostgreSQL must load the complete retained query-text storage before applying left(). If pg_stat_statements contains large utility statements - such as COPY commands with large literal VALUES lists—the query-text file can grow to hundreds of MiB. Each scrape can then read and materialize that data five times.

This can make exporter scrapes exceed their timeout and consume significant database and exporter resources. Limiting the output to 40 characters does not avoid the underlying query-text read.

PostgreSQL provides pg_stat_statements(false) specifically for collecting statistics without loading query text.

Describe the expected behavior:

pgMonitor should provide an option to collect these metrics without retrieving query text.

One compatibility-preserving approach would be separate no-query-text collector files for each supported PostgreSQL version. These could:

  • query public.pg_stat_statements(false);
  • retain the existing metric names and labels;
  • emit an empty query label;
  • continue exporting queryid, role, database, timing, row and WAL metrics.

Existing collector files could remain unchanged so current dashboards continue displaying query prefixes. Documentation should explain the observability and performance trade-off.

Tell us about your environment:

  • pgMonitor version: current development branch query definitions
  • Container or non-container: applicable to both
  • PostgreSQL version: 13–17
  • Exporter: postgres_exporter with custom query files

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions