Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql Postgres在数据库上运行查询时出错:无法检测默认用户名_Postgresql_Go_Docker_Docker Compose - Fatal编程技术网

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

Postgresql Postgres在数据库上运行查询时出错:无法检测默认用户名,postgresql,go,docker,docker-compose,Postgresql,Go,Docker,Docker Compose,嗨,我正试图用普罗米修斯监控PostgresSQL。为此,我使用此导出器 我在我的docker compose.yml中启动导出程序,如下所示: exporter-postgres: image: wrouesnel/postgres_exporter ports: - 9113:9113 environment: - DATA_SOURCE_NAME="postgresql://user:pass@localhost:5432/?sslmod

嗨,我正试图用普罗米修斯监控PostgresSQL。为此,我使用此导出器

我在我的
docker compose.yml中启动导出程序,如下所示:

  exporter-postgres:
    image: wrouesnel/postgres_exporter
    ports:
      - 9113:9113
    environment:
      - DATA_SOURCE_NAME="postgresql://user:pass@localhost:5432/?sslmode=disable" 
dsn := os.Getenv("DATA_SOURCE_NAME")
当导出器尝试访问数据库时,会引发如下错误:

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

我真的不确定这条信息是什么意思。此外,我也不确定这些问题是源于我的docker compose文件,还是源于导出器

postgres exporter.go中抛出错误的行是:

// 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
}

我感谢你的帮助

编辑:

以下是与数据库的连接:

db, err := sql.Open("postgres", e.dsn)
e.dsn
是这样生成的:

  exporter-postgres:
    image: wrouesnel/postgres_exporter
    ports:
      - 9113:9113
    environment:
      - DATA_SOURCE_NAME="postgresql://user:pass@localhost:5432/?sslmode=disable" 
dsn := os.Getenv("DATA_SOURCE_NAME")

连接不会引发任何错误

嘿,对于将来有类似问题的人:

问题是docker-compose.yml中的这一行

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

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

(不带引号)一切正常:)

你能显示连接
db
的线路吗?我假设你使用的用户名与“user”不同。可能您正在使用,而您的连接字符串没有正确生成?还有,这个答案救了我一天。谢谢