Skip to content

Instantly share code, notes, and snippets.

@hosszukalman
Created April 28, 2020 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hosszukalman/bcc911c966f8789ad7d3a87a5e3ec218 to your computer and use it in GitHub Desktop.
Save hosszukalman/bcc911c966f8789ad7d3a87a5e3ec218 to your computer and use it in GitHub Desktop.
Default settings for SQL connections in golang.
// 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