Skip to content

[+] add btree_bloat metric#1208

Open
0xgouda wants to merge 9 commits intomasterfrom
monitor-btree-bloat
Open

[+] add btree_bloat metric#1208
0xgouda wants to merge 9 commits intomasterfrom
monitor-btree-bloat

Conversation

@0xgouda
Copy link
Collaborator

@0xgouda 0xgouda commented Feb 16, 2026

  • Use the btree bloat estimation query from https://github.com/ioguix/pgsql-bloat-estimation (cited as the source in the metric description)
  • Add btree_bloat metric to presets with interval 7200
  • Add Top $n indexes by estimated bloat % to panel pg index overview dashboard
  • Add Top $n indexes by estimated bloat % to panel prom index overview dashboard
  • Add Top $n indexes by estimated bloat size to panel pg index overview dashboard

pg dashboard:
image

prom dashboard:
image

Closes: #1166

@0xgouda 0xgouda self-assigned this Feb 16, 2026
@0xgouda 0xgouda added dashboards Grafana dashboards related metrics Metrics related issues labels Feb 16, 2026
@coveralls
Copy link

coveralls commented Feb 16, 2026

Pull Request Test Coverage Report for Build 22101850630

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 77.445%

Totals Coverage Status
Change from base Build 22095272180: 0.04%
Covered Lines: 4268
Relevant Lines: 5511

💛 - Coveralls

Comment on lines +4194 to +4195
Based on the bloat estimation queries from https://github.com/ioguix/pgsql-bloat-estimation.
**Note - The query filters to bloated indexes over 1 MiB; for large databases, you might only care about indexes over 100 MiB or so**
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I already cited the query source (I modified it a little) in the metric description, but I am not sure if any additional thing is required by their BSD-2 license

@0xgouda 0xgouda force-pushed the monitor-btree-bloat branch from c878d1a to c91c75f Compare February 17, 2026 13:28
@0xgouda 0xgouda marked this pull request as ready for review February 17, 2026 13:28
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new btree_bloat metric to pgwatch for monitoring B-tree index bloat in PostgreSQL databases. The metric estimates index bloat by comparing actual index sizes against expected sizes derived from pg_stats and pg_class catalog metadata. The implementation includes:

Changes:

  • Added btree_bloat metric definition with bloat estimation query from https://github.com/ioguix/pgsql-bloat-estimation
  • Added the metric to 8 relevant presets (aiven, azure, exhaustive, full, gce, rds, exhaustive_no_python, debug) with interval 7200 seconds (30 seconds for debug)
  • Added visualization panels to both PostgreSQL and Prometheus Grafana dashboards showing top indexes by bloat percentage and size

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
internal/metrics/metrics.yaml Added btree_bloat metric definition with SQL query and added to all relevant presets
grafana/postgres/v12/index-overview.json Added new panel showing top indexes by estimated bloat %, minor column reordering in existing panel
grafana/prometheus/v12/index-overview-prometheus.json Added two new panels showing top 10 indexes by bloat % and bloat size

0xgouda and others added 2 commits February 17, 2026 15:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboards Grafana dashboards related metrics Metrics related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monitor indexes bloat

2 participants