prometheus-community / prometheus-community/postgres_exporter
pg_stat_statements metrics collection issue with postgres-exporter
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 835
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 10
Description
I am encountering an issue with postgres-exporter where it fails to collect metrics from the pg_stat_statements extension in my PostgreSQL database. Here are the details of my setup and the problem:
Setup Details:
Docker Compose Configuration:
services:
grafana:
image: grafana/grafana:latest
volumes:
- grafana-storage:/var/lib/grafana
ports:
- 3000:3000
prometheus:
image: prom/prometheus:latest
ports:
- 9090:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
postgres-exporter:
image: quay.io/prometheuscommunity/postgres-exporter
ports:
- 9187:9187
environment:
DATA_SOURCE_NAME: "postgresql://postgres:passsword@database-endpoint:5432/db-name?sslmode=disable"
volumes:
- ./queries.yml:/etc/queries.yml
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'
- '--extend.query-path=/etc/queries.yml'
volumes:
grafana-storage:
and
queries.yml Configuration for pg_stat_statements:
pg_stat_statements:
query: |
SELECT
queryid,
query,
calls
FROM
pg_stat_statements;
metrics:
- queryid:
usage: "LABEL"
description: "Query ID"
- query:
usage: "LABEL"
description: "SQL query text"
- calls:
usage: "GAUGE"
description: "Number of times executed"
Issue Details:
Expected Behavior:
postgres-exporter should collect metrics from pg_stat_statements and expose them at http://localhost:9187/metrics.
Actual Behavior:
The exporter returns HTTP status 500 Internal Server Error when querying http://postgres-exporter:9187/metrics.
Additional Information:
I have verified that the pg_stat_statements extension is installed and enabled in my PostgreSQL database.
The SELECT query from pg_stat_statements works correctly when executed directly in the database.
Error logs from postgres-exporter show no specific errors related to the pg_stat_statements query itself.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Docker Compose setup with pg_stat_statements enabled, then query the postgres-exporter /metrics endpoint and inspect its logs for the HTTP 500 cause. Compare the built-in stat_statements collector and the queries.yml configuration. Done means the exporter exposes the pg_stat_statements metrics successfully without returning a 500 response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, postgresql
- Domain
- databases, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100