Skip to content

Commit 782c076

Browse files
authored
[-] fix connection issues for discovered quoted db names, fixes #675 (#676)
1 parent 96df6d4 commit 782c076

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

internal/reaper/reaper.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,9 @@ func SyncMonitoredDBsToDatastore(ctx context.Context, monitoredDbs []*sources.So
435435

436436
for _, mdb := range monitoredDbs {
437437
db := metrics.Measurement{
438-
"tag_group": mdb.Group,
439-
"master_only": mdb.OnlyIfMaster,
440-
"epoch_ns": now.UnixNano(),
441-
"continuous_discovery_prefix": mdb.GetDatabaseName(),
438+
"tag_group": mdb.Group,
439+
"master_only": mdb.OnlyIfMaster,
440+
"epoch_ns": now.UnixNano(),
442441
}
443442
for k, v := range mdb.CustomTags {
444443
db[tagPrefix+k] = v

internal/sources/resolver.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ func ResolveDatabasesFromPatroni(ce Source) ([]*SourceConn, error) {
344344
return mds, err
345345
}
346346

347-
// "resolving" reads all the DB names from the given host/port, additionally matching/not matching specified regex patterns
347+
// ResolveDatabasesFromPostgres reads all the databases from the given cluster,
348+
// additionally matching/not matching specified regex patterns
348349
func ResolveDatabasesFromPostgres(s Source) (resolvedDbs SourceConns, err error) {
349350
var (
350351
c db.PgxPoolIface
@@ -358,13 +359,13 @@ func ResolveDatabasesFromPostgres(s Source) (resolvedDbs SourceConns, err error)
358359
defer c.Close()
359360

360361
sql := `select /* pgwatch_generated */
361-
quote_ident(datname)::text as datname_escaped
362-
from pg_database
363-
where not datistemplate
364-
and datallowconn
365-
and has_database_privilege (datname, 'CONNECT')
366-
and case when length(trim($1)) > 0 then datname ~ $1 else true end
367-
and case when length(trim($2)) > 0 then not datname ~ $2 else true end`
362+
datname
363+
from pg_database
364+
where not datistemplate
365+
and datallowconn
366+
and has_database_privilege (datname, 'CONNECT')
367+
and case when length(trim($1)) > 0 then datname ~ $1 else true end
368+
and case when length(trim($2)) > 0 then not datname ~ $2 else true end`
368369

369370
if rows, err = c.Query(context.TODO(), sql, s.IncludePattern, s.ExcludePattern); err != nil {
370371
return nil, err

0 commit comments

Comments
 (0)