Skip to content

Commit b858689

Browse files
committed
fix: limit queryid cardinality in postgres sink and query-info scrape
The pg_stat_statements WHERE filter was applied only on the Prometheus sink path. The postgres sink (pgss_queryid_queries) had NO LIMIT, dumping all queryids into the sink table every 30s. The flask backend then exported them all as pgwatch_query_info Prometheus metrics — and the query-info scrape job had no sample_limit safety net. This was the second, unfiltered path feeding 100K queryids into VictoriaMetrics. Changes: - Add LIMIT 100 to pgss_queryid_queries (postgres sink), matching the prometheus sink's top-100-by-exec-time cap - Add sample_limit: 500 to the query-info scrape job in prometheus.yml https://claude.ai/code/session_01SzJxzZNQjDQphaHyaX3RU7
1 parent d59cfef commit b858689

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

config/pgwatch-postgres/metrics.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ metrics:
1212
queryid is not null
1313
and dbid = (select oid from pg_database where datname = current_database())
1414
order by total_exec_time desc
15+
limit 100
1516
gauges:
1617
- '*'
1718

config/prometheus/prometheus.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ scrape_configs:
4949
- targets: ['monitoring_flask_backend:8000']
5050
scrape_interval: 300s # 5 minutes - query texts rarely change
5151
scrape_timeout: 30s
52-
metrics_path: /query_info_metrics
52+
metrics_path: /query_info_metrics
53+
sample_limit: 500 # Safety net: reject if flask exports too many queryids

0 commit comments

Comments
 (0)