Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make max number of idle connections configurable. #4527

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions internal/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ import (

// DatabaseConfig is the configuration for the database
type DatabaseConfig struct {
Host string `mapstructure:"dbhost" default:"localhost"`
Port int `mapstructure:"dbport" default:"5432"`
User string `mapstructure:"dbuser" default:"postgres"`
Password string `mapstructure:"dbpass" default:"postgres"`
Name string `mapstructure:"dbname" default:"minder"`
SSLMode string `mapstructure:"sslmode" default:"disable"`
Host string `mapstructure:"dbhost" default:"localhost"`
Port int `mapstructure:"dbport" default:"5432"`
User string `mapstructure:"dbuser" default:"postgres"`
Password string `mapstructure:"dbpass" default:"postgres"`
Name string `mapstructure:"dbname" default:"minder"`
SSLMode string `mapstructure:"sslmode" default:"disable"`
IdleConnections int `mapstructure:"idle_connections" default:"0"`
}

// GetDBConnection returns a connection to the database
Expand All @@ -54,6 +55,10 @@ func (c *DatabaseConfig) GetDBConnection(ctx context.Context) (*sql.DB, string,
return nil, "", err
}

if c.IdleConnections != 0 {
conn.SetMaxIdleConns(c.IdleConnections)
}

for i := 0; i < 8; i++ {
zerolog.Ctx(ctx).Info().Int("try number", i).Msg("Trying to connect to DB")
// we don't defer canceling the context because we want to cancel it as soon as we're done
Expand Down