From 5d4f1ea0ad8cbcfac0285659d6e60fd2dec4064c Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 25 Dec 2022 16:28:19 +0530 Subject: [PATCH] Add optional `params` in DB config to accept arbitrary Postgres params. Closes #1016. --- cmd/init.go | 3 ++- config.toml.sample | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/init.go b/cmd/init.go index 8d38a28..0cb4e14 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -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"` @@ -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) } diff --git a/config.toml.sample b/config.toml.sample index bf157e3..89e0f09 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -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 = ""