Skip to content

Commit

Permalink
Add optional params in DB config to accept arbitrary Postgres params.
Browse files Browse the repository at this point in the history
Closes #1016.
  • Loading branch information
knadh committed Dec 25, 2022
1 parent 1f693b8 commit 5d4f1ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func initDB() *sqlx.DB {
Password string `koanf:"password"`
DBName string `koanf:"database"`
SSLMode string `koanf:"ssl_mode"`
Params string `koanf:"params"`
MaxOpen int `koanf:"max_open"`
MaxIdle int `koanf:"max_idle"`
MaxLifetime time.Duration `koanf:"max_lifetime"`
Expand All @@ -258,7 +259,7 @@ func initDB() *sqlx.DB {

lo.Printf("connecting to db: %s:%d/%s", c.Host, c.Port, c.DBName)
db, err := sqlx.Connect("postgres",
fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", c.Host, c.Port, c.User, c.Password, c.DBName, c.SSLMode))
fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s %s", c.Host, c.Port, c.User, c.Password, c.DBName, c.SSLMode, c.Params))
if err != nil {
lo.Fatalf("error connecting to DB: %v", err)
}
Expand Down
3 changes: 3 additions & 0 deletions config.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ ssl_mode = "disable"
max_open = 25
max_idle = 25
max_lifetime = "300s"

# Optional space separated Postgres DSN params. eg: "application_name=listmonk gssencmode=disable"
params = ""

0 comments on commit 5d4f1ea

Please sign in to comment.