diff --git a/plugins/inputs/postgresql/service.go b/plugins/inputs/postgresql/service.go index 0dadaabc2..6c76d76f3 100644 --- a/plugins/inputs/postgresql/service.go +++ b/plugins/inputs/postgresql/service.go @@ -177,16 +177,8 @@ func (p *Service) SanitizedAddress() (sanitizedAddress string, err error) { // GetConnectDatabase utility function for getting the database to which the connection was made // If the user set the output address use that before parsing anything else. func (p *Service) GetConnectDatabase(connectionString string) (string, error) { - if p.OutputAddress != "" { - return p.OutputAddress, nil - } - connConfig, err := pgx.ParseConfig(connectionString) - if err != nil { - return "", fmt.Errorf("connection string parsing failed: %w", err) - } - - if len(connConfig.Database) != 0 { + if err == nil && len(connConfig.Database) != 0 { return connConfig.Database, nil } diff --git a/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go b/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go index 48fd9115e..0d67522e7 100644 --- a/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go +++ b/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go @@ -311,14 +311,14 @@ func TestAccRow(t *testing.T) { fields: fakeRow{ fields: []interface{}{1, "gato"}, }, - dbName: "server", + dbName: "postgres", server: "server", }, { fields: fakeRow{ fields: []interface{}{nil, "gato"}, }, - dbName: "server", + dbName: "postgres", server: "server", }, {