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
+4.7k Fix Google Analytics Redundant Hostnames problem
+8.4k Golang : Generate Datamatrix barcode
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+20.7k Golang : Read directory content with os.Open
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+19.3k Golang : Get RGBA values of each image pixel
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+6.6k Golang : Warp text string by number of characters or runes example
+8.2k Golang : Metaprogramming example of wrapping a function
+5.7k Fix yum-complete-transaction error
+8.1k Golang : HTTP Server Example
+5.6k Swift : Get substring with rangeOfString() function example