Prisma DATABASE_URL Connection String

Configure the DATABASE_URL environment variable for Prisma ORM. Covers PostgreSQL, MySQL, SQLite, MongoDB, and SQL Server connection string formats.

Best Practices

Detailed Explanation

Prisma's DATABASE_URL

Prisma ORM reads its database connection from the DATABASE_URL environment variable, which is referenced in schema.prisma:

datasource db {
  provider = "postgresql"  // or mysql, sqlite, mongodb, sqlserver
  url      = env("DATABASE_URL")
}

Format by Provider

PostgreSQL

DATABASE_URL="postgresql://user:password@host:5432/database?schema=public"

The schema parameter sets the default PostgreSQL search path. Prisma defaults to public if omitted.

MySQL

DATABASE_URL="mysql://user:password@host:3306/database"

SQLite

DATABASE_URL="file:./dev.db"

The path is relative to the prisma/ directory (where schema.prisma lives), not the project root.

MongoDB

DATABASE_URL="mongodb://user:password@host:27017/database?authSource=admin"

Or for MongoDB Atlas:

DATABASE_URL="mongodb+srv://user:password@cluster.example.mongodb.net/database?retryWrites=true&w=majority"

SQL Server

DATABASE_URL="sqlserver://host:1433;database=mydb;user=sa;password=secret;encrypt=true"

Connection Pooling with Prisma

Prisma manages its own connection pool. Configure it via the connection_limit parameter:

DATABASE_URL="postgresql://user:pass@host:5432/db?connection_limit=10"

For serverless environments (Vercel, AWS Lambda), keep the pool small (1-5) to avoid exhausting connections across multiple function instances.

PgBouncer

When using PgBouncer with Prisma, add pgbouncer=true:

DATABASE_URL="postgresql://user:pass@pgbouncer:6432/db?pgbouncer=true&connection_limit=5"

This disables prepared statements and adjusts connection handling for PgBouncer compatibility.

Shadow Database

For prisma migrate dev, Prisma needs a shadow database. Configure it separately:

SHADOW_DATABASE_URL="postgresql://user:pass@host:5432/shadow_db"

This is not needed in production — only for development migrations.

Use Case

Configuring a Prisma-based TypeScript or Node.js project to connect to a database in local development, staging, and production environments with proper connection pooling.

Try It — Connection String Builder

Open full tool