Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ PBW_PATH_PREFIX=""
# Your timezone, this impacts logging, backup filenames and default timezone
# in the web interface.
TZ=""

# Maximum number of open database connections. Default is 10.
PBW_DB_MAX_CONNS=""

# Maximum number of idle database connections. Default is 5.
# Should be <= PBW_DB_MAX_CONNS.
PBW_DB_MAX_IDLE_CONNS=""
2 changes: 2 additions & 0 deletions internal/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Env struct {
PBW_LISTEN_HOST string `env:"PBW_LISTEN_HOST" envDefault:"0.0.0.0"`
PBW_LISTEN_PORT string `env:"PBW_LISTEN_PORT" envDefault:"8085"`
PBW_PATH_PREFIX string `env:"PBW_PATH_PREFIX" envDefault:""`
PBW_DB_MAX_CONNS int `env:"PBW_DB_MAX_CONNS" envDefault:"10"`
PBW_DB_MAX_IDLE_CONNS int `env:"PBW_DB_MAX_IDLE_CONNS" envDefault:"5"`
}

var (
Expand Down
10 changes: 8 additions & 2 deletions internal/database/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ func Connect(env config.Env) *sql.DB {
)
}

db.SetMaxOpenConns(10)
logger.Info("connected to DB")
// Configure connection pool from environment variables
db.SetMaxOpenConns(env.PBW_DB_MAX_CONNS)
db.SetMaxIdleConns(env.PBW_DB_MAX_IDLE_CONNS)

logger.Info("connected to DB", logger.KV{
"maxOpenConns": env.PBW_DB_MAX_CONNS,
"maxIdleConns": env.PBW_DB_MAX_IDLE_CONNS,
})

return db
}