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
+13.5k Golang : Count number of runes in string
+7.7k Golang : Command line ticker to show work in progress
+11.5k Golang : Change date format to yyyy-mm-dd
+43.3k Golang : Convert []byte to image
+7.1k Golang : Squaring elements in array
+9.7k Golang : Find correlation coefficient example
+5.6k Javascript : How to refresh page with JQuery ?
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+6.1k Golang : Missing Subversion command
+6.5k Golang : Convert an executable file into []byte example
+21.2k Golang : Clean up null characters from input data