Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/db/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ function createPrismaClient() {
throw new Error("DATABASE_URL environment variable is required");
}

// Without an explicit cap, pg.Pool opens up to 10 connections per process and
// the adapter was only given the connection string. On serverless every warm
// instance builds its own pool, so two of them already exceeded the 15
// connections of Supabase's free session pooler — surfacing as Prisma's
// "Can't reach database server", which reads like an outage rather than an
// exhausted pool. The cap is per-environment: small on Vercel, a bit higher
// on the worker, which is a single long-lived process.
return new PrismaClient({
adapter: new PrismaPg(databaseUrl),
adapter: new PrismaPg({
connectionString: databaseUrl,
max: Number(process.env.DB_POOL_MAX ?? 3),
idleTimeoutMillis: 10_000,
}),
});
}

Expand Down