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
+9.6k Golang : Validate IPv6 example
+16.9k Golang : How to generate QR codes?
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+6k Javascript : Get operating system and browser information
+7.2k Golang : Use modern ciphers only in secure connection
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+3.7k Java : Random alphabets, alpha-numeric or numbers only string generator
+11.2k CodeIgniter : How to check if a session exist in PHP?
+7.1k Restart Apache or Nginx web server without password prompt
+6.6k Golang : How to validate ISBN?
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+5.6k Javascript : How to refresh page with JQuery ?