PostgreSQL
Managed PostgreSQL with private in-project connectivity. Enable backups and point-in-time recovery from the add-on Backups tab when you need them.
Creating a PostgreSQL instance
From the project canvas, click + Service → Databases → PostgreSQL. Stage the add-on, then click Commit.
To attach it to an app, use the add-on's Connections list or the app's Add-ons tab. StackBlaze injects connection environment variables into the app. There is no Environment tab → Attach database flow. To inspect or add your own variables, use the app's Variables tab.
Injected environment variables
Every attached app receives the discrete PG* variables. libpq and most Postgres drivers honor these automatically, so you do not need a URL.
| Variable | Role |
|---|---|
| PGHOST | Instance hostname |
| PGPORT | 5432 |
| PGUSER | Database user |
| PGDATABASE | Database name |
| PGPASSWORD | Password |
DATABASE_URL is injected only if you supplied a password literal when you created the instance. Treat the PG* set as the reliable contract. If a tool requires a URL, build one from those variables:
postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASEBrowse and query with CloudBeaver
Every database add-on ships with CloudBeaver. Open with DB Beaver on the add-on's Overview starts a scoped session where you can browse tables, run SQL, and edit data in the browser.
Running migrations
Run migrations as part of your app's deploy or startup so they finish before the new version serves traffic. The same injected variables are available in the app environment.
Prisma
npx prisma migrate deployNode.js / npm script
npm run migrateDjango
python manage.py migrateTip
PGHOST, PGPORT, PGUSER, PGDATABASE, and PGPASSWORD without extra configuration. Tools that only accept a URL should read DATABASE_URL when present, or build the URL from the PG* variables.Backups and point-in-time recovery
Backups are not enabled automatically. Open the PostgreSQL add-on, go to the Backups tab, and click Enable backups. From there you can use Backup now, Restore, and Schedule.
PostgreSQL supports point-in-time recovery once backups are enabled. Restore always creates a new instance — there is no in-place restore. After the new instance is ready, switch the app connection to it from the add-on Connections list or the app Add-ons tab.
For the full backup workflow, see Backups & recovery.
Supported extensions
The following popular extensions can be enabled with SQL:
| Extension | Use case |
|---|---|
| postgis | Geospatial data and queries |
| pgvector | Vector similarity search for AI/ML workloads |
| pg_trgm | Fuzzy text search using trigrams |
| uuid-ossp | UUID generation functions |
| pg_stat_statements | Query performance tracking |
| btree_gin | GIN indexes for B-tree operators |
| hstore | Key-value store within a column |
| citext | Case-insensitive text type |
CREATE EXTENSION IF NOT EXISTS pgvector;
CREATE EXTENSION IF NOT EXISTS postgis;Scaling
Manage storage and high availability from the PostgreSQL add-on on the project canvas. After you stage a change, click Commit.
Under the hood
PG* variables.Connecting with common ORMs
Prisma
Prisma requires a URL. Use DATABASE_URL when it was injected, or set it from the PG* variables in your app.
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}Drizzle ORM
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
const url =
process.env.DATABASE_URL ??
`postgres://${process.env.PGUSER}:${process.env.PGPASSWORD}@${process.env.PGHOST}:${process.env.PGPORT}/${process.env.PGDATABASE}`
const client = postgres(url)
export const db = drizzle(client)SQLAlchemy (Python)
import os
from sqlalchemy import create_engine
url = os.environ.get("DATABASE_URL") or (
f"postgresql://{os.environ['PGUSER']}:{os.environ['PGPASSWORD']}"
f"@{os.environ['PGHOST']}:{os.environ['PGPORT']}/{os.environ['PGDATABASE']}"
)
engine = create_engine(
url,
pool_size=5,
max_overflow=10,
pool_pre_ping=True,
)