Fix

"too many connections" with Go Database Pools

Fix 'too many connections' in Go by setting MaxOpenConns, MaxIdleConns, and ConnMaxLifetime on your sql.DB instance.

The error occurs because your application is creating more database connections than the pool allows or the database can handle. Increase the maximum open connections and set a timeout for idle connections to prevent leaks.

db.SetMaxOpenConns(25)
db.SetMaxIdleConns(10)
db.SetConnMaxLifetime(time.Hour)

If the error persists, ensure you are reusing the same *sql.DB instance across your application instead of creating a new one for every request.