Open eriktelepovsky opened 10 months ago
I am having almost the same issue.
An error has occurred while serving metrics:
5 error(s) occurred:
* collected metric "pg_stat_statements_calls_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"996906246641985132"} label:{name:"user" value:"mydbuser"} counter:{value:1}} was collected before with the same name and label values
* collected metric "pg_stat_statements_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"996906246641985132"} label:{name:"user" value:"mydbuser"} counter:{value:0.00079746}} was collected before with the same name and label values
* collected metric "pg_stat_statements_rows_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"996906246641985132"} label:{name:"user" value:"mydbuser"} counter:{value:74}} was collected before with the same name and label values
* collected metric "pg_stat_statements_block_read_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"996906246641985132"} label:{name:"user" value:"mydbuser"} counter:{value:0}} was collected before with the same name and label values
* collected metric "pg_stat_statements_block_write_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"996906246641985132"} label:{name:"user" value:"mydbuser"} counter:{value:0}} was collected before with the same name and label values
Mine has a value in the label queryid
.
I am running the exporter with Docker Compose;
version: '3'
services:
postgres-exporter:
image: quay.io/prometheuscommunity/postgres-exporter
ports:
- "9187:9187"
environment:
DATA_SOURCE_NAME: "postgresql://postgres_exporter:mypass@postgres:5432/mydb?sslmode=disable"
command: --web.listen-address=:9187 --web.telemetry-path=/metrics --collector.database_wraparound --collector.long_running_transactions --collector.postmaster --collector.process_idle --collector.stat_activity_autovacuum --collector.stat_statements --collector.stat_wal_receiver --collector.statio_user_indexes
same issue here -
curl localhost:26058/metrics
* collected metric "pg_stat_statements_calls_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-2355316157827874919"} label:{name:"user" value:"mydb_so"} counter:{value:2}} was collected before with the same name and label values
* collected metric "pg_stat_statements_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-2355316157827874919"} label:{name:"user" value:"mydb_so"} counter:{value:5.981075956000001}} was collected before with the same name and label values
* collected metric "pg_stat_statements_rows_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-2355316157827874919"} label:{name:"user" value:"mydb_so"} counter:{value:8}} was collected before with the same name and label values
* collected metric "pg_stat_statements_block_read_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-2355316157827874919"} label:{name:"user" value:"mydb_so"} counter:{value:0}} was collected before with the same name and label values
* collected metric "pg_stat_statements_block_write_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-2355316157827874919"} label:{name:"user" value:"mydb_so"} counter:{value:0}} was collected before with the same name and label values
* collected metric "pg_stat_statements_calls_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-3686023444609730445"} label:{name:"user" value:"mydb_so"} counter:{value:2}} was collected before with the same name and label values
* collected metric "pg_stat_statements_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-3686023444609730445"} label:{name:"user" value:"mydb_so"} counter:{value:5.831786688}} was collected before with the same name and label values
* collected metric "pg_stat_statements_rows_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-3686023444609730445"} label:{name:"user" value:"mydb_so"} counter:{value:8}} was collected before with the same name and label values
* collected metric "pg_stat_statements_block_read_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-3686023444609730445"} label:{name:"user" value:"mydb_so"} counter:{value:0}} was collected before with the same name and label values
* collected metric "pg_stat_statements_block_write_seconds_total" { label:{name:"datname" value:"mydb"} label:{name:"queryid" value:"-3686023444609730445"} label:{name:"user" value:"mydb_so"} counter:{value:0}} was collected before with the same name and label values
Let me explain the potential root cause for this problem.
pg_stat_statements: doesnt hold the unique key constraint on the queryid column. however the pg_stat_statements is designed in such a way that the query and the underlying subquery on a nested query will have the same query id (or) transactions that are nested on same block will have the same query id. This is basically a computed hash identifier generated by postgres pg_stat_statements that are fetched from the query sent to planner and executor.
postgres exporter: So now the exporter is collecting the metrics. say when you simulate running a nested queries which has joins, cross joins, lateral joins and so on.
Labels: Since the metrics are scrapped with labels ( user, databasename, queryid ). It is expected to have this error.
How, ever there is a fix which can be implemented. i have submitted a PR which holds the change CLICK HERE FOR PR.
Hope this explains the situation dealing with the problem.
Note: if you are using custom prometheus code with customized labels.. then you need to change the labels accordingly in the PSQL queries.
I had the same issue when I defined 2 connection strings in DATA_SOURCE_NAME. Helm chart values states that I can do that. I removed 1 string and everything became fine.
What did you do?
I started postgres-exporter using following docker-compose file:
What did you expect to see?
Opening http://127.0.0.1:9187/metrics I expected to see all metrics including statements.
What did you see instead? Under which circumstances?
I see 120 errors instead, but only when using --collector.stat_statements:
Environment
I tried on 2 systems:
postgres_exporter, version 0.15.0 (branch: HEAD, revision: 68c176b8833b7580bf847cecf60f8e0ad5923f9a) build user: root@7c5a76bc737a build date: 20231027-14:38:04 go version: go1.21.3 platform: linux/arm64 tags: unknown
14.10.0
(I changed host and port for issue purpose)