Golang database/sql.DB.SetMaxOpenConns function examples
package database/sql
SetMaxOpenConns sets the maximum number of open connections to the database.
If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit
If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).
Golang database/sql.DB.SetMaxOpenConns function usage examples
Example 1:
const defaultMaxIdleConns = 2
// Start by opening defaultMaxIdleConns
rows := make([]*Rows, defaultMaxIdleConns)
// We need to SetMaxOpenConns > MaxIdleConns, so the DB can open
// a new connection and we can fill the idle queue with the released
// connections.
db.SetMaxOpenConns(len(rows) + 1) // <-- here
Example 2:
db.SetMaxIdleConns(1)
db.SetMaxOpenConns(2)
Reference :
Advertisement
Something interesting
Tutorials
+15.3k nginx: [emerg] unknown directive "ssl"
+5.4k Golang *File points to a file or directory ?
+8.5k Golang : How to check variable or object type during runtime?
+9.4k Golang : Apply Histogram Equalization to color images
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+5.4k Python : Delay with time.sleep() function example
+14.6k Golang : Execute function at intervals or after some delay
+5.6k Golang : Shortening import identifier
+8.8k Golang : Executing and evaluating nested loop in html template
+13k Golang : Calculate elapsed years or months since a date
+3.6k Java : Get FX sentiment from website example
+13.2k Golang : Convert(cast) int to int64