mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
Set MaxIdleConns to reduce connection churn (postgresql physical) (#6967)
* Set MaxIdleConns to reduce connection churn (postgresql physical) * Make new "max_idle_connection" config option for physical postgresql * Add docs for "max_idle_connections" for postgresql storage * Add minimum version to docs for max_idle_connections
This commit is contained in:
@@ -114,6 +114,18 @@ func NewPostgreSQLBackend(conf map[string]string, logger log.Logger) (physical.B
|
||||
maxParInt = physical.DefaultParallelOperations
|
||||
}
|
||||
|
||||
maxIdleConnsStr, maxIdleConnsIsSet := conf["max_idle_connections"]
|
||||
var maxIdleConns int
|
||||
if maxIdleConnsIsSet {
|
||||
maxIdleConns, err = strconv.Atoi(maxIdleConnsStr)
|
||||
if err != nil {
|
||||
return nil, errwrap.Wrapf("failed parsing max_idle_connections parameter: {{err}}", err)
|
||||
}
|
||||
if logger.IsDebug() {
|
||||
logger.Debug("max_idle_connections set", "max_idle_connections", maxIdleConnsStr)
|
||||
}
|
||||
}
|
||||
|
||||
// Create PostgreSQL handle for the database.
|
||||
db, err := sql.Open("postgres", connURL)
|
||||
if err != nil {
|
||||
@@ -121,6 +133,10 @@ func NewPostgreSQLBackend(conf map[string]string, logger log.Logger) (physical.B
|
||||
}
|
||||
db.SetMaxOpenConns(maxParInt)
|
||||
|
||||
if maxIdleConnsIsSet {
|
||||
db.SetMaxIdleConns(maxIdleConns)
|
||||
}
|
||||
|
||||
// Determine if we should use a function to work around lack of upsert (versions < 9.5)
|
||||
var upsertAvailable bool
|
||||
upsertAvailableQuery := "SELECT current_setting('server_version_num')::int >= 90500"
|
||||
|
||||
Reference in New Issue
Block a user