🐛 Fix database pool min-size falling back to max-size (#13052)

* 🐛 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 <usama7274@gmail.com>

* 📚 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 <usama7274@gmail.com>

---------

Signed-off-by: Usama Sadiq <usama7274@gmail.com>
This commit is contained in:
Usama Sadiq 2026-11-14 22:12:22 +05:00 committed by Andrey Antukh
parent f3c1230b79
commit 861bb5bb37
2 changed files with 24 additions and 7 deletions

View File

@ -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))

View File

@ -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,...).