duanditang2916 2016-06-10 16:27
浏览 161

Postgres错误在数据库上运行查询:无法检测默认用户名

Hi I am trying to monitor postgres SQL with Prometheus. For this purpose I am using this exporter https://github.com/wrouesnel/postgres_exporter

I am starting the exporter in my docker-compose.yml like this:

  exporter-postgres:
    image: wrouesnel/postgres_exporter
    ports:
      - 9113:9113
    environment:
      - DATA_SOURCE_NAME="postgresql://user:pass@localhost:5432/?sslmode=disable" 

When the exporter is trying to access the database errors like this are thrown:

Error running query on database: pg_stat_database pg: Could not detect default username. Please provide one explicitly. file="postgres-exporter.go" line=490

and

Error scanning runtime variable: pg_stat_database pg: Could not detect default username. Please provide one explicitly. file="postgres-exporter.go" line=464

I am not really sure what this message could mean. Also I am not really sure if the issues originates in my docker-compose file, or the exporter.

The lines which throw the error in the postgres-exporter.go are:

// Use SHOW to get the value
row := db.QueryRow(fmt.Sprintf("SHOW %s;", columnName))

var val interface{}
err := row.Scan(&val)
if err != nil {
    log.Errorln("Error scanning runtime variable:", columnName, err)
    continue
}

and

query, er := queryOverrides[namespace]
if er == false {
    query = fmt.Sprintf("SELECT * FROM %s;", namespace)
}

// Don't fail on a bad scrape of one metric
rows, err := db.Query(query)
if err != nil {
    log.Println("Error running query on database: ", namespace, err)
    e.error.Set(1)
    return
}

https://github.com/wrouesnel/postgres_exporter/blob/master/postgres_exporter.go

I am thankful for any help!

Edit:

Here is the connection to the database:

db, err := sql.Open("postgres", e.dsn)

Whereas e.dsn is generated like this:

dsn := os.Getenv("DATA_SOURCE_NAME")

The connection doesn't throw any error

  • 写回答

1条回答 默认 最新

  • dongxun6458 2016-06-11 13:17
    关注

    Hey for anyone having a similiar issue in the future:

    The problem was this line in the docker-compose.yml

     - DATA_SOURCE_NAME="postgresql://user:pass@localhost:5432/?sslmode=disable" 
    

    Changing it to

     - DATA_SOURCE_NAME=postgresql://user:pass@localhost:5432/?sslmode=disable
    

    (Without the quotes) made everything work :)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起