Skip to content

Netlify

Tested with: Netlify CLI 17 · Netlify Functions (Node 20) · PostgreSQL 17

  1. Set the connection string for the site (scope it to production and deploy previews as needed).

    shell
    netlify env:set DATABASE_URL "postgresql://app:<password>@pg-7f3k-pool.us-east.databasezy.com:5432/app?sslmode=verify-full" --context production
  2. Allow-list: Netlify Functions run on AWS Lambda without static IPs. Allow all and rely on TLS plus credentials, or route through your own NAT with a Netlify Enterprise static-IP add-on.

  3. Use the pooled endpoint and a tiny pool per function:

    netlify/functions/health.ts
    import { Pool } from "pg";
    const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 2, ssl: true });
    export default async () => {
    const { rows } = await pool.query("select now()");
    return Response.json(rows[0]);
    };

Netlify Edge Functions run on Deno at the edge without TCP. Use libSQL over HTTP (@libsql/client/web) or call a Netlify Function for database work.

Run migrations in the build command against the direct endpoint, with DIRECT_URL set as a build-scoped variable: npx prisma migrate deploy && npm run build.