prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.82k stars 743 forks source link

Error while connecting - pq: Could not detect default username #1026

Closed lui3533 closed 6 months ago

lui3533 commented 6 months ago

Describe the bug a clear and concise description of what the bug is.

Hi,

we are trying to set up the postgres-exporter for the first time and are facing the following issue

The pod is spinning up and starts correctly but the logs show the following error messages

│ ts=2024-04-24T11:35:35.638Z caller=proc.go:267 msg="Excluded databases" databases=[] │
│ ts=2024-04-24T11:35:35.643Z caller=tls_config.go:274 level=info msg="Listening on" address=:9187 │
│ ts=2024-04-24T11:35:35.643Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=:9187 │
│ ts=2024-04-24T11:35:52.398Z caller=server.go:74 level=info msg="Established new database connection" fingerprint=<XXXXXXXXXXXdb-connection-stringXXXXXXXXXXX>:5432│
│ ts=2024-04-24T11:35:55.754Z caller=probe.go:41 level=info msg="no auth_module specified, using default"│
│ ts=2024-04-24T11:35:55.754Z caller=server.go:74 level=info msg="Established new database connection" fingerprint=*:5432│
│ ts=2024-04-24T11:35:55.755Z caller=probe.go:81 level=error target=* msg="Error opening connection to database" err="error querying postgresql version: pq: Could not detect default username. Please provide one explicitly" │
│ ts=2024-04-24T11:35:56.755Z caller=postgres_exporter.go:682 level=error err="Error opening connection to database (postgresql://*): pq: Could not detect default username. Please provide one explicitly"

What's your helm version?

v3.14.3

What's your kubectl version?

v1.29.2

Which chart?

prometheus-postgres-exporter

What's the chart version?

6.0.0

What happened?

So the exporter is trying to establish a new connection to the postgres database. Now we are unsure about to aspects in the logs.

  1. no auth_module specified, using default - do we need the auth_module for one single db connection?
  2. Error opening connection to database (postgresql://*): pq: Could not detect default username. Please provide one explicitly

We connected to the pod and checked if the env variables DATA_SOURCE_URI, DATA_SOURCE_USER, DATA_SOURCE_PASS do contain the correct values - and they do. So from our point of view the connection should be possible.

What you expected to happen?

The connection to the postgres can be established with the provided data.

How to reproduce it?

use the datasourceSecret option and provide a single connectionstring (in format postgresql://login:password@hostname:port/dbname?sslmode=disable) as a secret

Enter the changed values of values.yaml?

config:
  ## The datasource properties on config are passed through helm tpl function.
  ## ref: https://helm.sh/docs/developing_charts/#using-the-tpl-function
  datasourceSecret:
    # Specifies if datasource should be sourced from secret value in format: postgresql://login:password@hostname:port/dbname?sslmode=disable
    # Multiple Postgres databases can be configured by comma separated postgres connection strings
    # Secret name
      name: postgres-secret
    # Connection string key inside secret
      key: connectionstring

  # possible values debug, info, warn, error, fatal
  logLevel: "debug"

Enter the command that you execute and failing/misfunctioning.

helm upgrade -i postgres-exporter prometheus-community/prometheus-postgres-exporter -f values.yaml

Anything else we need to know?

No response

lui3533 commented 6 months ago

Hi, any updates?