From 5f8e191e2b5bf4c76c15b53bf9eff81d32cdf36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 2 Jun 2026 16:06:55 +0200 Subject: [PATCH] fix(compose): set an explicit, tunable database connection_limit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The app pins DATABASE_URL in the compose environment block, which shadows any connection_limit an operator sets in .env, so Prisma fell back to its default pool (cpu_count*2+1 — 9 on a 4-core host). A combined web+worker process starves that pool under background AI and rollup load, leaving HTTP requests waiting on the pool until they time out. Set connection_limit explicitly (default 20, override via DB_CONNECTION_LIMIT) plus a pool_timeout override, so the pool can be sized to the host and its database. Co-Authored-By: Claude Opus 4.8 (1M context) --- docker-compose.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index edcfaa8b6..3d621b511 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,14 @@ services: ports: - "3000:3000" environment: - DATABASE_URL: "postgresql://healthlog:${POSTGRES_PASSWORD}@db:5432/healthlog?schema=public" + # connection_limit is set explicitly: Prisma's own default is + # cpu_count*2+1, which starves the combined web+worker process + # (HEALTHLOG_PROCESS_TYPE=all) under background AI/rollup load. Default + # 20 suits a small host; raise DB_CONNECTION_LIMIT on a busy one (keep it + # below the database's max_connections, leaving headroom for pg-boss, + # migrations, and backups). pool_timeout is the seconds a query waits for + # a free connection before erroring. + DATABASE_URL: "postgresql://healthlog:${POSTGRES_PASSWORD}@db:5432/healthlog?schema=public&connection_limit=${DB_CONNECTION_LIMIT:-20}&pool_timeout=${DB_POOL_TIMEOUT:-20}" NODE_ENV: production ENCRYPTION_KEY: "${ENCRYPTION_KEY}" ENCRYPTION_KEYS: "${ENCRYPTION_KEYS:-}"