Prisma
databasesprismaGuideBeginner
Prisma Environment Variables & Connection URLs
Configuring DATABASE_URL, connection pooling parameters, SSL modes, and secret handling across development and production environments.
Verified: 2026-10-01
Tested on:prisma 6.x
Platforms:
node
#prisma#environment-variables#database-url#postgresql#security
Prisma Environment Variables & Connection URLs
Prisma automatically loads environment variables from a .env file in the project root or prisma/ folder.
1. Anatomy of a PostgreSQL Connection URL
postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMA&connection_limit=10&sslmode=preferUSER: Database username (e.g.postgres).PASSWORD: Password (percent-encode special characters like@or:).HOST: Hostname or IP address (e.g.localhost,db.example.com).PORT: Database port (default5432).DATABASE: Database name (e.g.myapp_production).schema: PostgreSQL schema namespace (defaultpublic).connection_limit: Maximum connections in the client pool.
2. Separate URLs for Direct Connections vs Pooled Connections
When deploying behind connection poolers (like AWS RDS Proxy, PgBouncer, Supabase, Neon), configure two URLs in schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL") // Pooled connection URL (For app queries)
directUrl = env("DIRECT_URL") // Direct connection URL (For prisma migrate)
}# .env (Production Example)
DATABASE_URL="postgresql://user:pass@ep-cool-pooler.us-east-1.neon.tech/neondb?sslmode=require&pgbouncer=true"
DIRECT_URL="postgresql://user:pass@ep-cool-direct.us-east-1.neon.tech/neondb?sslmode=require"3. Best Practices for Secret Handling
Related Topics
Prisma Database Transactions ($transaction)
Executing atomic operations in Prisma: sequential batch transactions and interactive callback transactions with ACID guarantees.
Using PostgreSQL with Prisma
Native PostgreSQL features in Prisma: @db attributes, UUID generation, native JSONB, native Enums, and full-text search.