Reputation: 442
I am using the pq
driver (http://github.com/lib/pq) in go for writing into a postgres database, but when a lot of transactions happen at once, the driver panics and does the following:
pq: sorry, too many clients already
To prevent this behavior I wanted to use SetMaxOpenConns
(as documented in http://golang.org/pkg/database/sql/), but the compiler says:
db.SetMaxOpenConns undefined (type *sql.DB has no field or method SetMaxOpenConns)
I thought the functions from sql
would also be available in pq
, but apparently they aren't.
My code:
package main
import (
"database/sql"
_ "github.com/lib/pq"
)
func Main() {
var db, _ = sql.Open("postgres", "user=user dbname=db")
db.SetMaxOpenConns(10)
}
Is there any other possibility to limit the amount of open connections?
Upvotes: 2
Views: 1752
Reputation: 442
As James pointed out, I referred to a function that is only available on Go 1.2, while I had still installed 1.1.
In short the Solution is: Update to Go 1.2
Upvotes: 3