feat: a database connection pool behind DB_POOL (off in production)

Every db.connect() opened a new Postgres connection; with DB_POOL=on each
process keeps a psycopg_pool pool (DB_POOL_SIZE, default 20, 10 s
acquisition timeout, dropped connections replaced) with the same
commit/rollback contract. Production stays off until switched in Portainer;
the local stack and CI run with it on. Two nested acquisitions that ran on
every board load and in audits now reuse the caller's connection.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 17:57:42 -03:00
parent 085c2d0009
commit 5b7e95ad86
17 changed files with 190 additions and 16 deletions

View File

@@ -235,6 +235,14 @@ only process; the API's `/tmp` is sized for two such checks at once. It applies
to the API only, never to the worker. Set it in the stack's environment and
redeploy.
## 10. Database connection pool
`DB_POOL` reuses database connections inside each API process and the worker
instead of opening one per `with` block (default `off`, the previous
behaviour). Set it to `on` in the stack's environment and redeploy to keep
between 1 and `DB_POOL_SIZE` connections per process (`DB_POOL_SIZE` defaults
to 20); set it back to `off` to return to one connection per block.
## Current blocker
This is the final deployment shape, but it is not authorized for production