postgres_exporter
postgres_exporter copied to clipboard
database must exist to run exporter with specific user
We run postgres_exporter
using the helm-chart on version 4.4.3
We created a designated postgres user for it and gave it the role pgmonitor
. Once everything was setup we had the following errors.
2023-05-23 12:34:08.136 | ts=2023-05-23T10:34:08.135Z caller=collector.go:196 level=error msg="collector failed" name=bgwriter duration_seconds=0.008667515 err="pq: database \"pgexporter\" does not exist"
-- | --
After CREATE DATABASE pgexporter
and adding all mandatory roles, it did work without errors.
Is that the expected behavior? I wouldn't use this database and use existing ones.
I saw the values parameter config.datasource.database
but as I use several databases, is there a wildcard? Is this even the place where I can handle this behavior?
Thanks for clarification!
Environment
-
System information:
x86
-
postgres_exporter version:
4.4.3
-
postgres_exporter values.yaml:
pgExporter:
enabled: true
monitorUser: pgexporter
monitorCred: testpwforghissue
---
prometheus-postgres-exporter:
# it is always enabled, to disbable the exporter, see .Values.global.pgExporter
enabled: true
fullnameOverride: prometheus-postgres-exporter
config:
datasource:
host: postgresql-primary
name: pgExporter
passwordSecret:
name: prometheus-postgres-exporter-secret
key: password
externalQueries:
enabled: true
configmap: pgexporter-monitor-queries
serviceMonitor:
enabled: true
-
PostgreSQL version:
PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
-
Logs:
2023-05-23 12:34:08.136 | ts=2023-05-23T10:34:08.135Z caller=collector.go:196 level=error msg="collector failed" name=bgwriter duration_seconds=0.008667515 err="pq: database \"pgexporter\" does not exist"
-- | --
I don't know much about that Helm chart but this error occurs when you don't set any database name in the DSN. By default, pq
takes the username as the database name if the latter is not set.
-
postresql://user:password@host
-->database name = user
-
postresql://user:password@host/database
-->database name = database
I think if you modify the DSN to include the database name your error will be gone. Regarding which DB you should set, I think postgres
could be good but if you have just one DB set that to be able to get table metrics.
I think that a new ENV to set the DB Name will be good but I'm not sure what is the path to follow because they want to focus this exporter on the server metrics not at DB level.