Vercel
Tested with: Vercel CLI 39 · Next.js 15 · @vercel/functions 1.5 · PostgreSQL 17
-
Add the connection string as an environment variable. Use the pooled endpoint for serverless functions (
-poolhost, see Connection pooling) and the direct endpoint forprisma migratein CI.shell vercel env add DATABASE_URL production# postgresql://app:<password>@pg-7f3k-pool.us-east.databasezy.com:5432/app?sslmode=verify-fullvercel env add DIRECT_URL production# postgresql://app:<password>@pg-7f3k.us-east.databasezy.com:5432/app?sslmode=verify-fullNode drivers on Vercel use the OS trust store, so no CA file is needed;
sslmode=verify-fullstill verifies the hostname. -
Allow Vercel’s egress. Functions have no fixed IP by default; enable Secure Compute (Enterprise) for static IPs, or allow all and rely on TLS plus credentials, which the portal flags.
shell zb api PUT /v1/orgs/{org}/instances/pg-7f3k/network -d '{"allow_cidrs": ["0.0.0.0/0", "::/0"]}' # everyone; flagged in the portal -
Connect with a small pool per function instance.
lib/db.ts import { Pool } from "pg";const globalForPg = globalThis as unknown as { pool?: Pool };export const pool =globalForPg.pool ?? new Pool({ connectionString: process.env.DATABASE_URL, max: 3, ssl: true });if (process.env.NODE_ENV !== "production") globalForPg.pool = pool;
Edge runtime
Section titled “Edge runtime”The Edge runtime has no TCP sockets. Use libSQL (HTTP) directly, or PostgreSQL through an HTTP-capable driver such
as @neondatabase/serverless-style fetch drivers pointed at a Node function, or simply run the route on the Node
runtime (export const runtime = "nodejs"). Valkey has no HTTP interface; keep cache access in Node functions.
Preview deployments
Section titled “Preview deployments”Create one instance per preview branch from a GitHub Action (see Argo CD and Helm patterns
for the CLI steps) and set DATABASE_URL on the preview environment with vercel env add DATABASE_URL preview <branch>.