feat: use hasql-pool-0.10, add db-pool-max-idletime (#2786)

- new option db-pool-max-idletime limits the maximal idle time of a
  postgresql connection, defaults to 30 seconds
- this essentially restores the db-pool-timeout option from versions
  <=10, with more specific name
This commit is contained in:
Robert
2023-05-16 23:00:40 +02:00
committed by GitHub
parent a867d79c42
commit f9f0f79fa9
20 changed files with 41 additions and 16 deletions
+1
View File
@@ -115,6 +115,7 @@ initPool AppConfig{..} =
configDbPoolSize
(fromIntegral configDbPoolAcquisitionTimeout)
(fromIntegral configDbPoolMaxLifetime)
(fromIntegral configDbPoolMaxIdletime)
(toUtf8 configDbUri)
-- | Run an action with a database connection.
+3
View File
@@ -154,6 +154,9 @@ exampleConfigFile =
|## Time in seconds after which to recycle pool connections
|# db-pool-max-lifetime = 1800
|
|## Time in seconds after which to recycle unused pool connections
|# db-pool-max-idletime = 30
|
|## Stored proc to exec immediately after auth
|# db-pre-request = "stored_proc_name"
|
+4 -1
View File
@@ -74,6 +74,7 @@ data AppConfig = AppConfig
, configDbPoolSize :: Int
, configDbPoolAcquisitionTimeout :: Int
, configDbPoolMaxLifetime :: Int
, configDbPoolMaxIdletime :: Int
, configDbPreRequest :: Maybe QualifiedIdentifier
, configDbPreparedStatements :: Bool
, configDbRootSpec :: Maybe QualifiedIdentifier
@@ -137,6 +138,7 @@ toText conf =
,("db-pool", show . configDbPoolSize)
,("db-pool-acquisition-timeout", show . configDbPoolAcquisitionTimeout)
,("db-pool-max-lifetime", show . configDbPoolMaxLifetime)
,("db-pool-max-idletime", show . configDbPoolMaxIdletime)
,("db-pre-request", q . maybe mempty dumpQi . configDbPreRequest)
,("db-prepared-statements", T.toLower . show . configDbPreparedStatements)
,("db-root-spec", q . maybe mempty dumpQi . configDbRootSpec)
@@ -228,6 +230,7 @@ parser optPath env dbSettings roleSettings =
<*> (fromMaybe 10 <$> optInt "db-pool")
<*> (fromMaybe 10 <$> optInt "db-pool-acquisition-timeout")
<*> (fromMaybe 1800 <$> optInt "db-pool-max-lifetime")
<*> (fromMaybe 30 <$> optInt "db-pool-max-idletime")
<*> (fmap toQi <$> optWithAlias (optString "db-pre-request")
(optString "pre-request"))
<*> (fromMaybe True <$> optBool "db-prepared-statements")
@@ -366,7 +369,7 @@ parser optPath env dbSettings roleSettings =
if dbSettingName `notElem` [
"server_host", "server_port", "server_unix_socket", "server_unix_socket_mode", "admin_server_port", "log_level",
"db_uri", "db_channel_enabled", "db_channel", "db_pool", "db_pool_acquisition_timeout",
"db_pool_max_lifetime", "db_config"]
"db_pool_max_lifetime", "db_pool_max_idletime", "db_config"]
then lookup dbSettingName dbSettings
else Nothing