Files
alpenwerk-hr/.env.example
Maximilian Stubhan 99e50fbbf9 Stop hoarding connections the provider will not give twice
The app died with "max clients reached in session mode - pool_size: 15".
Two causes, both real, neither visible without a live database.

The connection string pointed at the pooler's session mode, which pins one
backend per client and caps at 15 on Supabase. Every query here already runs
inside a transaction and the session context is set transaction-locally, so
transaction mode is not a workaround but the mode this design was written
for. Verified: 20 concurrent transactions, all 852 rows, 0.4s — and still
nothing without a session context.

The second cause was the dev server. Next.js re-evaluates changed modules,
so a module-local `let` was empty afterwards while the previous pool stayed
alive holding its connections. An afternoon of editing exhausted the quota.
The pool now hangs off globalThis, which is inert in production where
nothing reloads.

Documented in .env.example and DEPLOYMENT.md, because a deployment that
picks port 5432 fails this way under load and not before.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-03 10:28:36 +02:00

45 lines
2.2 KiB
Plaintext

# Direkter PostgreSQL-Zugang. Die Anwendung spricht künftig unmittelbar mit
# der Datenbank statt über eine API-Schicht — damit läuft sie auf jedem
# PostgreSQL ab 15 (Azure Flexible Server, RDS, Cloud SQL, eigenes Blech).
#
# Die Rolle in diesem String darf KEIN BYPASSRLS haben: fehlt der
# Sitzungskontext, sollen die Policies nichts zurückgeben statt alles.
#
# Hinter einem Verbindungspooler (Supabase Supavisor, PgBouncer) den
# TRANSAKTIONS-Modus nehmen, nicht den Sitzungs-Modus — bei Supabase Port
# 6543 statt 5432. Jede Abfrage dieser Anwendung läuft ohnehin in einer
# Transaktion, und der Sitzungskontext wird transaktionslokal gesetzt; beides
# passt genau dazu. Der Sitzungs-Modus belegt dagegen je Client eine feste
# Verbindung und ist bei Supabase auf 15 begrenzt — danach antwortet die
# Anwendung nur noch mit „max clients reached".
DATABASE_URL=
# Auf "false" setzen, wenn die Datenbank ohne TLS läuft (lokal, CI).
DATABASE_SSL=
# Verbindungen im Pool; Vorgabe 10.
DATABASE_POOL_MAX=
# ── Anmeldung (Auth.js + Microsoft Entra ID) ─────────────────────────
# Schlüssel, mit dem das Sitzungscookie signiert und verschlüsselt wird.
# Erzeugen mit `npx auth secret` oder `openssl rand -base64 32`. Ein Wechsel
# meldet alle ab — was im Ernstfall genau das gewünschte Mittel ist.
AUTH_SECRET=
# Aus der Anwendungsregistrierung im Entra-Portal: Anwendungs-ID (Client),
# ein Geheimnis daraus, und der Aussteller mit der Verzeichnis-ID (Mandant).
#
# Der Aussteller darf NICHT auf /common/ stehen bleiben — sonst könnte sich
# jedes Microsoft-Konto anmelden, auch ein privates.
AUTH_MICROSOFT_ENTRA_ID_ID=
AUTH_MICROSOFT_ENTRA_ID_SECRET=
AUTH_MICROSOFT_ENTRA_ID_ISSUER=https://login.microsoftonline.com/<verzeichnis-id>/v2.0
# Nur nötig, wenn die Anwendung hinter einem Reverse Proxy unter einer
# anderen Adresse erreichbar ist, als sie selbst sieht. Ohne diesen Wert baut
# Auth.js die Rückruf-Adresse aus den Request-Headern.
AUTH_URL=
# Shared secret Vercel Cron sends as `Authorization: Bearer <value>` when it
# calls /api/cron/apply-pending-changes (set the same value in the Vercel
# project's env vars). Generate with e.g. `openssl rand -hex 32`.
CRON_SECRET=