<p>Let's consider the following goroutine:</p>

<pre><code>func main(){
    ...
    go dbGoRoutine()
    ...
}
</code></pre>

<p>And the func:</p>

<pre><code>func dbGoRoutine() {
    db, err := sqlx.Connect("postgres", GetPSQLInfo())
    if err != nil {
        panic(err)
    }
    defer db.Close()

    ticker := time.NewTicker(10 * time.Second)
    for _ = range ticker.C {
        _, err := db.Queryx("SELECT * FROM table")
        if err != nil {
            // handle
        }
    }
}
</code></pre>

<p>Each time the function iterates on the ticker it opens a cloudSQL connection</p>

<pre><code>[service... cloudsql-proxy] 2019/11/08 17:05:05 New connection for "location:exemple-db"
</code></pre>

<p>I can't figure out why it opens a new connection each time, since the sqlx.Connect is not in the for loop.</p>

Pierre Le Guen
<p>This issue is due to how Query function in sql package, it returns Row which are:</p>

<blockquote>
  <p>Rows is the result of a query. Its cursor starts before the first row of the result set.</p>
</blockquote>

<p>Those cursor are stored using cache.</p>

<p>try using <a href="https://godoc.org/database/sql#DB.Exec" rel="nofollow noreferrer">Exec()</a>.</p>
