Postgres Error running query on database: Could not detect default username
<p>Hi I am trying to monitor postgres SQL with Prometheus. For this purpose I am using this exporter <a href="https://github.com/wrouesnel/postgres_exporter" rel="nofollow">https://github.com/wrouesnel/postgres_exporter</a></p>

<p>I am starting the exporter in my <code>docker-compose.yml</code> like this:</p>

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

<p>When the exporter is trying to access the database errors like this are thrown:</p>

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

<p>and </p>

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

<p>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.</p>

<p>The lines which throw the error in the <code>postgres-exporter.go</code> are:</p>

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

var val interface{}
err := row.Scan(&amp;val)
if err != nil {
    log.Errorln("Error scanning runtime variable:", columnName, err)
    continue
}
</code></pre>

<p>and</p>

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

<p><a href="https://github.com/wrouesnel/postgres_exporter/blob/master/postgres_exporter.go" rel="nofollow">https://github.com/wrouesnel/postgres_exporter/blob/master/postgres_exporter.go</a></p>

<p>I am thankful for any help!</p>

<p>Edit:</p>

<p>Here is the connection to the database:</p>

<pre><code>db, err := sql.Open("postgres", e.dsn)
</code></pre>

<p>Whereas <code>e.dsn</code> is generated like this:</p>

<pre><code>dsn := os.Getenv("DATA_SOURCE_NAME")
</code></pre>

<p>The connection doesn't throw any error</p>