From 75c01645913f6dcb56b9e221654be584dbf59455 Mon Sep 17 00:00:00 2001 From: Oleksii Kysil Date: Tue, 25 Apr 2023 16:17:47 +0300 Subject: [PATCH] PMM-9541 Fix database discover when using socket When discovering databases and using local socket connection add trailing "/" to the database name to omit using it as a host for the connection. --- cmd/postgres_exporter/datasource.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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.