Skip to content

add pg_stat_statements plans#1315

Open
jfcoz wants to merge 1 commit into
prometheus-community:masterfrom
jfcoz:feat/pg_statements_plans
Open

add pg_stat_statements plans#1315
jfcoz wants to merge 1 commit into
prometheus-community:masterfrom
jfcoz:feat/pg_statements_plans

Conversation

@jfcoz

@jfcoz jfcoz commented May 21, 2026

Copy link
Copy Markdown

Add pg_stat_statements metrics:
plans_total: Number of times planned
plans_seconds_total: Total time spent in planning the statement

It needs the PostgreSQL setting: pg_stat_statements.track_planning

Add pg_stat_statements metrics:
plans_total: Number of times planned
plans_seconds_total: Total time spent in planning the statement

It needs the PostgreSQL setting: pg_stat_statements.track_planning

Signed-off-by: Julien Francoz <julien@les-tilleuls.coop>
statStatementsPlansSecondsTotal = prometheus.NewDesc(
prometheus.BuildFQName(namespace, statStatementsSubsystem, "plans_seconds_total"),
"Total time spent in planning the statement, in seconds",
[]string{"user", "datname", "queryid"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queryID looks like a label with unbounded cardinality. Could we drop it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it, for example to get the ratio of calls by plan and find queries which are badly used (for example prepare + bind inside a loop)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work well with Prometheus though 😅.

Maybe that could become an exemplar label in the histogram?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t understand the problem. It’s already the same in all the other metrics from pg_stat_statements.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I probably should have said this from the beginning. I'm not a maintainer for this repository! If the maintainers are ok with it, that's what counts

@ArthurSens ArthurSens Jun 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant by "this doesn't work well with Prometheus" is that a single query will have a single ID and generate a single timeseries; another query will get a different ID and therefore become a brand-new timeseries.

All those unique IDs will become an entry in Prometheus's Posting index (good blog in case you'd like to read more). A gigantic posting index will make PromQL queries slower and increase resource usage

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.

2 participants