Every App Platform plan includes a managed PostgreSQL 16 database. Your app receives the database's connection address in the DATABASE_URL environment variable, so there is no host, user or password to configure by hand. This guide shows how to connect from common frameworks, how backups and restores work, and how to run migrations.
Read the connection string from DATABASE_URL in your code; the platform sets it for you and it can't be edited or deleted. Backups run automatically overnight with about a week of history kept, and you can take one yourself at any time in the Backups tab. Restoring a backup replaces your current database. The database is reachable only from your app, not from your own computer.
1. How your app connects
The platform sets DATABASE_URL on your app. It is a standard PostgreSQL connection string in this form:
postgresql://user:password@host:5432/dbnameRead it from the environment rather than copying the value into your code or a config file. The Overview tab shows your database's name.
Node.js with Prisma
// prisma/schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}Node.js with node-postgres
const { Pool } = require('pg');
const pool = new Pool({ connectionString: process.env.DATABASE_URL });Python with SQLAlchemy
import os
from sqlalchemy import create_engine
engine = create_engine(os.environ['DATABASE_URL'])Go
import (
"database/sql"
"os"
_ "github.com/lib/pq"
)
db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))Python, Go and other non-Node.js apps are built from a Dockerfile in your project; only Node.js is detected automatically. See the App Platform overview.
2. DATABASE_URL is a system variable
DATABASE_URL appears in the Env Vars tab as a system variable. You can't change or delete it; trying gives "Cannot modify system variable". That protects your app from losing its database connection.
To use a database you host elsewhere, add your own variable under a different name, for example EXTERNAL_DATABASE_URL, and read that in your code. See Environment variables.
3. Backups
Your database is backed up automatically every night, and about a week of backups is kept. You can also take a backup yourself at any time.
- Open your appand go to Data › Backups.
- Click Create Backup.The new backup appears in the list with its file name and size.
Take a manual backup immediately before a schema migration, a bulk delete or a major release. That way your recovery point is exactly where you want it, not last night.
4. Restoring a backup
- In Data › Backups, find the backup you want.
- Click Restore on its row and confirm.
A restore replaces everything in the database with the contents of the backup. Anything written since that backup is lost. If the current data may still matter, click Create Backup first so you can go back to it.
5. Running migrations
Run your migrations as part of the app's start command, so each new version brings the schema up to date before it serves traffic. With Prisma, in a Procfile:
web: npx prisma migrate deploy && node server.jsOr in package.json:
{
"scripts": {
"start": "prisma migrate deploy && node server.js"
}
}For a Dockerfile app, put the same two steps in the CMD. Use migrations that are safe to run more than once: most migration tools, including Prisma, skip anything already applied.
6. Limits and what isn't included
- No direct connection from your own computer. Your app reaches its database internally; tools like pgAdmin or
psqlon your laptop can't connect. To inspect data, add a small admin route or a scheduled job to your app. - The managed database is PostgreSQL. To use a different database engine, host it elsewhere and connect through your own environment variable.
- Files aren't in the database backup. Files your app writes to a persistent folder (Data › Storage) are separate from database backups.
7. If your app can't reach its database
Don't change DATABASE_URL; the value the platform sets is the right one. Check the Logs tab for the exact error. Common causes on your side are a library expecting a different variable name, or code that reads the address before the environment is loaded.
If the logs show a connection failure while your code reads DATABASE_URL correctly, open a ticket with your app name. That is something for us to fix, not you.
Is a PostgreSQL database included with App Platform plans?
Yes. Every App Platform plan includes a managed PostgreSQL 16 database. Your app receives its connection string in the DATABASE_URL environment variable.
Can I change DATABASE_URL?
No. DATABASE_URL is a system variable, so it can't be edited or deleted. To use another database, add your own variable under a different name and read that instead.
Is my App Platform database backed up?
Yes. It is backed up automatically every night, with about a week of backups kept, and you can create a backup yourself at any time in the Backups tab.
What happens when I restore a backup?
The restore replaces your current database with the contents of the backup, and anything written since that backup is lost. Create a fresh backup first if the current data may matter.
Can I connect to the database from my own computer?
No. The database is reachable only from your app. To inspect data, add an admin route or a scheduled job to your app.
Ready to build on PostgreSQL? Open your App Platform apps, compare App Platform plans, or ask us in a support ticket.
Every App Platform plan includes a managed PostgreSQL database with nightly backups and one-click restore.
See App Platform plans