Vercel builds exhuasted my connection pool on supabase
March 31, 2026
i was building a starter with payloadcms , using supabase for postgres. there was a seed script running at build time, RSCs for every page that were using db queries under the hood.
after every build, the admin panel crashed with a connection pool error .
reason: vercel spins up multiple workers to build the app, and each worker acquires a connection from the pool . so all the workers were trying to get connections at the same time, and the pool got exhausted after the build.
so i used:
// payload.config.ts
db: postgresAdapter({
pool: {
connectionString: process.env.DATABASE_URL || "",
max: process.env.IS_PROD_BUILD === "true" ? 2 : 10,
idleTimeoutMillis: 30_000,
connectionTimeoutMillis: 10_000,
},
migrationDir: path.resolve(dirname, "migrations"),
push: false,
}),
// next.config.ts
export default (phase: string) => {
const isBuildingForProduction = phase === PHASE_PRODUCTION_BUILD;
const nextConfig: NextConfig = {
env: {
IS_PROD_BUILD: String(isBuildingForProduction),
},
images: {
remotePatterns: [{ hostname: "images.unsplash.com" }],
},
};
return withPayload(nextConfig);
};