postgres_exporter icon indicating copy to clipboard operation
postgres_exporter copied to clipboard

Error opening connection to database(could not parse DATA_SOURCE_NAME) - Using a password which contain special characters.

Open RushikeshChavan96 opened this issue 3 years ago • 3 comments

Getting below error in kubectl POD while connecting to prometheus-postgres-exporter, version 2.0.0 Config params: POSTGRES_EXPORTER_IMAGE_REPOSITORY=wrouesnel/postgres_exporter POSTGRES_EXPORTER_IMAGE_TAG=v0.8.0 POSTGRES_EXPORTER_IMAGE_PULL_POLICY=IfNotPresent

POSTGRES_EXPORTER_CHART=msa-upstream/prometheus-postgres-exporter POSTGRES_EXPORTER_VERSION=2.0.0

POSTGRES_EXPORTER_DATASOURCE_HOST=<host_name> POSTGRES_EXPORTER_DATASOURCE_USER= POSTGRES_EXPORTER_DATASOURCE_PASSWORD= POSTGRES_EXPORTER_DATASOURCE_DATABASE=<db_name> POSTGRES_EXPORTER_DATASOURCE_PORT=5432

Error: time="2022-07-20T11:54:50Z" level=error msg="Error opening connection to database (could not parse DATA_SOURCE_NAME): parse postgresql://pgadmin:@<db_url>:/postgres?sslmode=require: invalid URL escape "%!!(MISSING)s"" source="postgres_exporter.go:1474"

Note: Password has special characters, also tried providing password in double quotes: "" Eg: "ah!nasSasd!n987Dasdc"

Please let me know if you need more information.

RushikeshChavan96 avatar Jul 20 '22 12:07 RushikeshChavan96

I met the same problem. And I try to fix it by replacing the sepecial characters with its %+ascii format. Because special characters in url (eg: postgresql://user:passwd@localhost:5432/postgres?sslmode=disable) mean specially and can not directly be parsed, eg: ! -> %21 , # -> %23

Tiremisu avatar Aug 22 '22 06:08 Tiremisu

Currently DSNs that are of the form "postgresql://" are parsed by the URL library. This means that special characters must be valid URLs.

sysadmind avatar Aug 25 '22 02:08 sysadmind

I met the same problem. And I try to fix it by replacing the sepecial characters with its %+ascii format. Because special characters in url (eg: postgresql://user:passwd@localhost:5432/postgres?sslmode=disable) mean specially and can not directly be parsed, eg: ! -> %21 , # -> %23

Solved the problem! Thanks. Here is percent encoding characters table.

Parsa2820 avatar Aug 25 '22 06:08 Parsa2820