Created
April 28, 2020 05:02
-
-
Save hosszukalman/bcc911c966f8789ad7d3a87a5e3ec218 to your computer and use it in GitHub Desktop.
Default settings for SQL connections in golang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://golang.org/pkg/database/sql/#DB.SetMaxOpenConns | |
// Go's default setting is "unlimited" for SetMaxOpenConns() but PG's setting is 100. | |
// If you don't set a limit, go won't handle it in the application layer and never wait to open a new connection | |
// so it's possible to throw a "max connections" error. That's why you should set the limits, this can be a starting point | |
// for small and medium web applictions. | |
db.SetMaxOpenConns(25) | |
db.SetMaxIdleConns(25) | |
db.SetConnMaxLifetime(5*time.Minute) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment