diff --git a/cmd/postgres_exporter/datasource.go b/cmd/postgres_exporter/datasource.go index 3721e658c..c49f89bb5 100644 --- a/cmd/postgres_exporter/datasource.go +++ b/cmd/postgres_exporter/datasource.go @@ -75,7 +75,11 @@ func (e *Exporter) discoverDatabaseDSNs() []string { } if dsnURI != nil { - dsnURI.Path = databaseName + if dsnURI.Host == "" && strings.HasPrefix(dsnURI.Path, "/") { + dsnURI.Path = "/" + databaseName + } else { + dsnURI.Path = databaseName + } dsn = dsnURI.String() } else { // replacing one dbname with another is complicated.