Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit422f710

Browse files
committed
Merge branch 'fix/reports-db-discovery-and-bloat-filtering' into 'main'
reports: make DB discovery source-agnosticSee merge request postgres-ai/postgres_ai!70
2 parents38625a2 +103298d commit422f710

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

‎reporter/postgres_reports.py‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,36 +1722,41 @@ def get_all_databases(self, cluster: str = "local", node_name: str = "node-01")
17221722
Returns:
17231723
List of database names
17241724
"""
1725-
# Try to get databases from metrics that use 'dbname' label (custom metrics)
1726-
db_query=f'last_over_time(pgwatch_unused_indexes_index_size_bytes{{cluster="{cluster}", node_name="{node_name}"}}[10h])'
1727-
result=self.query_instant(db_query)
1728-
1729-
databases= []
1730-
ifresult.get('status')=='success'andresult.get('data', {}).get('result'):
1731-
foriteminresult['data']['result']:
1732-
db_name=item['metric'].get('dbname','')
1733-
ifdb_nameanddb_namenotindatabases:
1734-
databases.append(db_name)
1735-
1736-
# If no databases found using dbname, try using datname (catalog metrics)
1737-
ifnotdatabases:
1738-
db_query=f'pgwatch_pg_database_wraparound_age_datfrozenxid{{cluster="{cluster}", node_name="{node_name}", datname!="template1"}}'
1739-
result=self.query_instant(db_query)
1740-
ifresult.get('status')=='success'andresult.get('data', {}).get('result'):
1741-
foriteminresult['data']['result']:
1742-
db_name=item['metric'].get('datname','')
1743-
ifdb_nameanddb_namenotindatabases:
1744-
databases.append(db_name)
1745-
1746-
# If still no databases found, try another alternative query
1747-
ifnotdatabases:
1748-
db_query=f'pgwatch_pg_database_size_bytes{{cluster="{cluster}", node_name="{node_name}"}}'
1749-
result=self.query_instant(db_query)
1750-
ifresult.get('status')=='success'andresult.get('data', {}).get('result'):
1751-
foriteminresult['data']['result']:
1752-
db_name=item['metric'].get('datname','')
1753-
ifdb_nameanddb_namenotindatabases:
1754-
databases.append(db_name)
1725+
# Build a source-agnostic database list by unifying labels from:
1726+
# 1) Generic per-database metric (wraparound) → datname
1727+
# 2) Custom index reports (unused/redundant) → dbname
1728+
# 3) Btree bloat (for completeness) → datname
1729+
databases:List[str]= []
1730+
database_set=set()
1731+
1732+
# Helper to add a name safely
1733+
defadd_db(name:str)->None:
1734+
ifnameandnamenotin ('template0','template1')andnamenotindatabase_set:
1735+
database_set.add(name)
1736+
databases.append(name)
1737+
1738+
# 1) Generic per-database metric
1739+
wrap_q=f'pgwatch_pg_database_wraparound_age_datfrozenxid{{cluster="{cluster}", node_name="{node_name}"}}'
1740+
wrap_res=self.query_instant(wrap_q)
1741+
ifwrap_res.get('status')=='success'andwrap_res.get('data', {}).get('result'):
1742+
foriteminwrap_res['data']['result']:
1743+
add_db(item["metric"].get("datname",""))
1744+
1745+
# 2) Custom reports using dbname
1746+
unused_q=f'last_over_time(pgwatch_unused_indexes_index_size_bytes{{cluster="{cluster}", node_name="{node_name}"}}[10h])'
1747+
redun_q=f'last_over_time(pgwatch_redundant_indexes_index_size_bytes{{cluster="{cluster}", node_name="{node_name}"}}[10h])'
1748+
forqin (unused_q,redun_q):
1749+
res=self.query_instant(q)
1750+
ifres.get('status')=='success'andres.get('data', {}).get('result'):
1751+
foriteminres['data']['result']:
1752+
add_db(item["metric"].get("dbname",""))
1753+
1754+
# 3) Btree bloat family
1755+
bloat_q=f'last_over_time(pgwatch_pg_btree_bloat_bloat_pct{{cluster="{cluster}", node_name="{node_name}"}}[1d])'
1756+
bloat_res=self.query_instant(bloat_q)
1757+
ifbloat_res.get('status')=='success'andbloat_res.get('data', {}).get('result'):
1758+
foriteminbloat_res['data']['result']:
1759+
add_db(item["metric"].get("datname",""))
17551760

17561761
returndatabases
17571762

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp