I have created an Api with golang and postgresql as database.
after several requests, the API crashes with an error 500 and a log that displays
pq : sorry , too many customers already
At first it was because I did not close rows when i select, so i have rows.close() all.
But it's not that because i have already this error.
Then saw the launch of the database takes only 3ms, I thought I should start and close the database on every request to reset all connections, but thinking about it a little more, this is nonsense.
So I ask you, how this error works , is that the client connections are reset after a certain time or connection is cut off until a server reboot for client?
If it resets after a certain time , what are the disadvantages of increasing the maximum number of client connection?
My code:
I open my db like this at start of program :
var gest Gestion
type Gestion struct {
Db *sql.DB
DbLog *sql.DB
}
func InitDbUser() *sql.DB {
dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", DB_USER, DB_PASSWORD, DB_NAME)
db, err := sql.Open("postgres", dbinfo)
LogFatalError(err)
err2 := db.Ping()
LogFatalError(err2)
return db
}
func main() {
gest.Db = InitDbUser()
defer gest.Db.Close()
//routing is here
}
And when i use this request in my psql :
select min_val,max_val from pg_settings where name='max_connections';
I get hat :
min_val | max_val
---------+---------
1 | 8388607
Sorry for my english, i hope you understand what I ask :)