PostgreSQL
Managed PostgreSQL 15 and 16 with automated backups, point-in-time recovery, and zero-config internal connectivity.
Creating a PostgreSQL instance
From the StackBlaze dashboard, click New service → Database → PostgreSQL. Choose your Postgres version (15 or 16), an initial storage size (1 GB to 500 GB), and a compute plan. StackBlaze provisions a Kubernetes StatefulSet backed by a PersistentVolumeClaim within seconds.
Once created, navigate to your web service or worker, go to the Environment tab, and click Attach database. StackBlaze automatically injects DATABASE_URL as a secret environment variable.
Connection strings
StackBlaze exposes two connection strings per database: an internal one for services in the same project, and an external one for local tooling like Postico or TablePlus.
Internal (recommended)
Services in the same project communicate over the cluster's private network using the service's internal hostname. No TLS configuration is required, traffic never leaves the cluster.
postgresql://user:password@[service-name].internal:5432/dbname
External (for local tools)
The external connection string is available in the dashboard under Settings → Connection. It uses SSL and routes traffic through our secure proxy. Use this for GUI clients like TablePlus, Postico, or DBeaver, not for production app connections.
postgresql://user:password@db.stackblaze.cloud:5432/dbname?sslmode=require
Running migrations
The safest pattern is to run migrations as a pre-deploy command so they complete before new traffic reaches your updated service. Configure this under Settings → Deploy → Pre-deploy command.
Prisma
npx prisma migrate deploy
Node.js / npm script
npm run migrate
Django
python manage.py migrate
Manual via CLI
stackblaze run --service my-api "npx prisma migrate deploy"
Tip
DATABASE_URL.Point-in-time recovery (PITR)
On Pro and Enterprise plans, StackBlaze streams WAL (Write-Ahead Log) segments to object storage every 5 minutes. This lets you restore your database to any point within the last 7 days with 5-minute granularity.
To initiate a PITR restore, navigate to your database in the dashboard, click Backups → Restore to point in time, select a timestamp, and choose whether to restore in-place or to a new instance.
| Plan | PITR | Retention window | WAL interval |
|---|---|---|---|
| Free | No | - | - |
| Starter | No | 3 days (snapshots) | - |
| Pro | Yes | 7 days | 5 minutes |
| Enterprise | Yes | 30 days | 5 minutes |
Automated backups
All plans include automated daily snapshots taken during off-peak hours (typically 02:00“04:00 UTC). Backups are encrypted with AES-256 before leaving the host and stored in a separate availability zone.
To restore from a snapshot, go to Backups in the database dashboard, select the snapshot, and click Restore. You can restore to a new instance without affecting the running database.
Supported extensions
The following popular extensions are available on all plans and can be enabled without any configuration:
| 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
Vertical scaling
To increase CPU or memory, upgrade the database plan from the dashboard under Settings → Plan. StackBlaze performs a rolling StatefulSet update with a brief connection interruption (typically < 30 seconds). Schedule vertical scaling during off-peak hours.
Read replicas
Read replicas are available on Enterprise plans. They use PostgreSQL streaming replication and are typically < 1 second behind the primary. Connect read-heavy workloads (analytics queries, reporting) to the replica connection string to reduce load on the primary.
Under the hood
[service-name].internal) that survives pod restarts and rescheduling. Connection pooling via PgBouncer is available as an add-on on Pro and Enterprise plans.Connecting with common ORMs
Prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}Drizzle ORM
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
const client = postgres(process.env.DATABASE_URL!)
export const db = drizzle(client)SQLAlchemy (Python)
from sqlalchemy import create_engine
engine = create_engine(
os.environ["DATABASE_URL"],
pool_size=5,
max_overflow=10,
pool_pre_ping=True,
)