From 861bb5bb371dc42146c019b41bfd0666db9f5cea Mon Sep 17 00:00:00 2001 From: Usama Sadiq Date: Sat, 14 Nov 2026 22:12:22 +0500 Subject: [PATCH] :bug: Fix database pool min-size falling back to max-size (#13052) * :bug: Fix database pool min-size falling back to max-size Since 2.16 the pool minimum defaults to the maximum (60), so an idle backend opens and holds 60 connections at startup. Restore the pre-2.16 default of 0 so the pool grows with load and idle connections expire. Closes #12622 Signed-off-by: Usama Sadiq * :books: Document database connection pool settings Describe PENPOT_DATABASE_MIN_POOL_SIZE and PENPOT_DATABASE_MAX_POOL_SIZE, their defaults, and sizing on a PostgreSQL shared with other apps. Signed-off-by: Usama Sadiq --------- Signed-off-by: Usama Sadiq --- backend/src/app/db.clj | 12 +++++------- docs/technical-guide/configuration.md | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index d34911ff32..e3fde46fb0 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -70,6 +70,7 @@ (def defaults {::name :main + ::min-size 0 ::max-size 60 ::connection-timeout 30000 ::validation-timeout 10000 @@ -92,8 +93,7 @@ :read-only read-only :credentials (and (contains? cfg ::username) (contains? cfg ::password)) - :min-size (or (::min-size cfg) - (::max-size cfg)) + :min-size (::min-size cfg) :max-size (::max-size cfg)) (create-pool cfg)))) @@ -114,9 +114,7 @@ [{:keys [::uri] :as cfg}] ;; (app.common.pprint/pprint cfg) - (let [config (HikariConfig.) - max-size (::max-size cfg) - min-size (or (::min-size cfg) max-size)] + (let [config (HikariConfig.)] (doto config (.setJdbcUrl (str "jdbc:" uri)) (.setPoolName (d/name (::name cfg))) @@ -126,8 +124,8 @@ (.setValidationTimeout (::validation-timeout cfg)) (.setIdleTimeout (::idle-timeout cfg)) (.setMaxLifetime (::max-lifetime cfg)) - (.setMinimumIdle min-size) - (.setMaximumPoolSize max-size) + (.setMinimumIdle (::min-size cfg)) + (.setMaximumPoolSize (::max-size cfg)) (.setConnectionInitSql initsql) (.setInitializationFailTimeout -1)) diff --git a/docs/technical-guide/configuration.md b/docs/technical-guide/configuration.md index 9715bc2ce3..37ea377bec 100644 --- a/docs/technical-guide/configuration.md +++ b/docs/technical-guide/configuration.md @@ -723,6 +723,25 @@ POSTGRES_USER: penpot POSTGRES_PASSWORD: penpot ``` +#### Connection pool + +The backend keeps a pool of database connections. Its size can be tuned with: + +```bash +# Backend +PENPOT_DATABASE_MIN_POOL_SIZE: 0 +PENPOT_DATABASE_MAX_POOL_SIZE: 60 +``` + +The values above are the defaults. The pool keeps at least `MIN_POOL_SIZE` idle +connections open and never opens more than `MAX_POOL_SIZE`, growing only under load +and closing idle connections after two minutes. A minimum larger than the maximum is +capped at the maximum. + +If the PostgreSQL server is shared with other applications, make sure +`PENPOT_DATABASE_MAX_POOL_SIZE` plus the connections used by everything else stays below +the server's `max_connections` (100 by default). + ### Storage Storage refers to storing the user uploaded different objects in Penpot (assets, file data,...).