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.6k Linux : sudo yum updates not working
+13.9k Golang : How to check if a file is hidden?
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+41.9k Golang : How do I convert int to uint8?
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+5.7k Golang : Struct field tags and what is their purpose?
+6.3k Golang : Calculate US Dollar Index (DXY)
+5.1k Linux : How to set root password in Linux Mint
+15.9k Golang : Get file permission
+8.9k Golang : Sort lines of text example
+15.3k nginx: [emerg] unknown directive "ssl"