DATABASE_URL
SensitiveA universal database connection string following the URI format protocol://user:password@host:port/database. Used by ORMs (Prisma, Sequelize, SQLAlchemy, ActiveRecord) and database drivers as the primary connection configuration. Supports PostgreSQL, MySQL, SQLite, and other databases.
Last updated:
DATABASE_URL packs an entire database connection into one URI: protocol://user:password@host:port/database?options. The Twelve-Factor App convention popularized it, and now Prisma, SQLAlchemy, Rails (via DATABASE_URL overriding database.yml), Django (with dj-database-url), and most PaaS providers read it directly. Heroku, Railway, Render, and Supabase inject it for you. The scheme matters: 'postgresql://' and 'postgres://' both work for Postgres, but Prisma and some libraries are picky, and 'mysql://' vs 'mysql2://' differ across Ruby and Node ecosystems.
- Provider
- Databases
- Category
- connection
- Set by
- Set manually in application configuration or provided by PaaS platforms (Heroku, Railway, Render)
- Example
- postgresql://user:password@localhost:5432/mydb?sslmode=require
How to set DATABASE_URL
bash (Postgres)
export DATABASE_URL='postgresql://user:pass@localhost:5432/mydb?sslmode=require'docker-compose
services:
app:
environment:
DATABASE_URL: postgresql://user:pass@db:5432/mydb
db:
image: postgres:17URL-encode a special character in the password
# password p@ss:word -> p%40ss%3Aword
postgresql://user:p%40ss%3Aword@host:5432/dbReferences
Frequently Asked Questions
My password has special characters and the connection fails. Why?
A DATABASE_URL is a URI, so characters like @ : / ? # in the password break parsing — a literal @ is read as the user/host separator. URL-encode them (@ → %40, : → %3A, / → %2F) or the driver connects to the wrong host or rejects the string.
Why do I get 'too many connections' on serverless?
Each serverless invocation can open its own database connection, blowing past Postgres's connection limit under load. Connect through a pooler (PgBouncer, Supabase pooled port, Prisma Accelerate) via DATABASE_URL, and use a separate direct connection only for migrations.
Stay up to date
Get notified about new guides, tools, and cheatsheets.