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
+11.5k CodeIgniter : Import Linkedin data
+7.3k Golang : Not able to grep log.Println() output
+14.5k Golang : Rename directory
+7.1k Restart Apache or Nginx web server without password prompt
+37.7k Golang : Comparing date or timestamp
+9.4k Android Studio : Indicate progression with ProgressBar example
+10.1k Golang : Test a slice of integers for odd and even numbers
+11k How to test Facebook App on localhost ?
+6.7k Golang : Check if password length meet the requirement
+6.3k Javascript : Generate random key with specific length
+9.9k Golang : Translate language with language package example
+9.1k Golang : Gonum standard normal random numbers example