PostgreSQL
DocsDatabasesPostgreSQL

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.

This demo adds PostgreSQL from the catalog, attaches it to the app, and shows PGHOST, PGUSER, and DATABASE_URL injected on the Variables tab.

Creating a PostgreSQL instance

From the project canvas, click + ServiceDatabasesPostgreSQL. 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.

VariableRole
PGHOSTInstance hostname
PGPORT5432
PGUSERDatabase user
PGDATABASEDatabase name
PGPASSWORDPassword

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:

Construct a URL from PG*
postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASE

Browse 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.

Open with DB Beaver launches a scoped CloudBeaver session where the users table is browsed, a query runs, and the results appear.

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

Migrate
npx prisma migrate deploy

Node.js / npm script

Migrate
npm run migrate

Django

Migrate
python manage.py migrate

Tip

libpq-based clients pick up 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:

ExtensionUse case
postgisGeospatial data and queries
pgvectorVector similarity search for AI/ML workloads
pg_trgmFuzzy text search using trigrams
uuid-osspUUID generation functions
pg_stat_statementsQuery performance tracking
btree_ginGIN indexes for B-tree operators
hstoreKey-value store within a column
citextCase-insensitive text type
Enable an extension
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

PostgreSQL is provisioned as a CloudNativePG cluster. Attached apps reach it over the project's private network using the injected 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.

prisma/schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Drizzle ORM

db.ts
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)

database.py
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,
)