fix inputs.postgresql panic in posgres 12 (#7151)

This commit is contained in:
Steven Soroka 2020-03-10 17:06:29 -04:00 committed by GitHub
parent 3bc53558a4
commit 64fecfa19e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -155,7 +155,12 @@ func (p *Postgresql) accRow(row scanner, acc telegraf.Accumulator, columns []str
} }
if columnMap["datname"] != nil { if columnMap["datname"] != nil {
// extract the database name from the column map // extract the database name from the column map
dbname.WriteString((*columnMap["datname"]).(string)) if dbNameStr, ok := (*columnMap["datname"]).(string); ok {
dbname.WriteString(dbNameStr)
} else {
// PG 12 adds tracking of global objects to pg_stat_database
dbname.WriteString("postgres_global")
}
} else { } else {
dbname.WriteString("postgres") dbname.WriteString("postgres")
} }