prometheus-community / prometheus-community/postgres_exporter

`pg_stat_*` metrics are reported for all databases on the server, regardless of how they're included / excluded

Open
#994 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
3.6k
Forks
835
Avg merge
2d 4h
Merged PRs (30d)
10

Description

What did you do?

When listing data sources to scrape only specific databases on a single postgres server (I'd use autodiscovery, but that looks deprecated), the pg_stat_* metrics include all databases, with no way to exclude them besides modifying any relevant alerts etc.

What did you expect to see?

For pg_stat_* metrics, only metrics for databases we're explicitly scraping are considered

What did you see instead? Under which circumstances?

All databases are scraped. This is clearly visible from the code - there's no filtering being done:

https://github.com/prometheus-community/postgres_exporter/blob/9cfa1321158af0eb9f6b11d06eebd064e57c697b/collector/pg_stat_database.go#L219-L242

Environment

  • System information:

    N/A

  • postgres_exporter version:

    used via Grafana Agent, which seems to be v0.11.1

  • postgres_exporter flags:

    N/A

  • PostgreSQL version:

    15.5.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in collector/pg_stat_database.go at lines 219-242, where the issue identifies that database metrics are collected without filtering. Trace how included and excluded data sources are represented, then determine how the collector should apply that selection. Done means pg_stat_* metrics are emitted only for explicitly scraped databases, with behavior checked against the reported scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases, observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.