🔌 New pull request backend#199 Cap Prisma connection pool (PG1: shared CNPG capacity)
by: @bdtfs
## Summary
- The shared CNPG Postgres cluster (postgres-cnpg-1, max_connections=100) is running at 82-89/100 connections. compono-backend-prod alone holds 29 idle connections under role remnawave on compono_billing (verified live via pg_stat_activity, joined to pod IP 10.42.3.32).
- prisma.service.ts constructs PrismaClient with no connection_limit`/`pool_timeout override, so Prisma falls back to its default pool size formula num_physical_cpus*2+1 -- ~29 on the cluster's dedicated node, which matches the observed count exactly.
- Adds a pure buildDatabaseUrl(rawUrl, connectionLimit, poolTimeoutSeconds) helper that appends connection_limit`/`pool_timeout query params to the existing DATABASE_URL (preserving any params already present, e.g. schema=remnawave`/`sslmode, and never overriding an explicit connection_limit already in the URL) and passes the result via the constructor's datasourceUrl option.
- No change to the DATABASE_URL secret in Vault. Pool size is controlled by two new plain env vars: DATABASE_CONNECTION_LIMIT (default 10) and DATABASE_POOL_TIMEOUT (default 20). Companion ArgoCD chart PR sets DATABASE_CONNECTION_LIMIT=10 for prod, 5 for stage, via extraEnv.
## Test plan
- [x] Manually verified buildDatabaseUrl`'s query-string logic with a throwaway Node script (append when absent, preserve existing params, don't clobber an existing `connection_limit)
- [ ] This repo has no test harness at all (no test script in package.json, no jest/vitest config, zero *.spec.ts files) -- could not run this through an automated suite or CI-equivalent locally. Flagging for reviewer: please smoke-test on stage (DATABASE_CONNECTION_LIMIT=5 per the companion chart PR) and confirm `compono-backend-stage`'s live connection count drops before merging to main/prod.
Reply to this message to post a comment on GitHub.