diff --git a/cmd/queries.go b/cmd/queries.go index 6e6e0c6b..bf2edc41 100644 --- a/cmd/queries.go +++ b/cmd/queries.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "time" "github.com/jmoiron/sqlx" "github.com/lib/pq" @@ -84,14 +85,15 @@ type Queries struct { // dbConf contains database config required for connecting to a DB. type dbConf struct { - Host string `koanf:"host"` - Port int `koanf:"port"` - User string `koanf:"user"` - Password string `koanf:"password"` - DBName string `koanf:"database"` - SSLMode string `koanf:"ssl_mode"` - MaxOpen int `koanf:"max_open"` - MaxIdle int `koanf:"max_idle"` + Host string `koanf:"host"` + Port int `koanf:"port"` + User string `koanf:"user"` + Password string `koanf:"password"` + DBName string `koanf:"database"` + SSLMode string `koanf:"ssl_mode"` + MaxOpen int `koanf:"max_open"` + MaxIdle int `koanf:"max_idle"` + MaxLifetime time.Duration `koanf:"max_lifetime"` } // connectDB initializes a database connection. @@ -104,6 +106,7 @@ func connectDB(c dbConf) (*sqlx.DB, error) { } db.SetMaxOpenConns(c.MaxOpen) db.SetMaxIdleConns(c.MaxIdle) + db.SetConnMaxLifetime(c.MaxLifetime) return db, nil } diff --git a/config-demo.toml b/config-demo.toml index 03a0eb08..7aff549c 100644 --- a/config-demo.toml +++ b/config-demo.toml @@ -10,3 +10,6 @@ password = "listmonk" database = "listmonk" ssl_mode = "disable" + max_open = 25 + max_idle = 25 + max_lifetime = "300s" diff --git a/config.toml.sample b/config.toml.sample index 7c0e3c6b..7b09b772 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -17,3 +17,6 @@ password = "listmonk" database = "listmonk" ssl_mode = "disable" + max_open = 25 + max_idle = 25 + max_lifetime = "300s"