PostgreSQL
DocsDatabasesPostgreSQL

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

Connection string (internal)
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.

Connection string (external, SSL required)
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

Pre-deploy command
npx prisma migrate deploy

Node.js / npm script

Pre-deploy command
npm run migrate

Django

Pre-deploy command
python manage.py migrate

Manual via CLI

Terminal
stackblaze run --service my-api "npx prisma migrate deploy"

Tip

Always run migrations before the new version of your code starts serving traffic. StackBlaze's pre-deploy command runs inside an ephemeral container with the same environment variables as your service, including 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.

PlanPITRRetention windowWAL interval
FreeNo - -
StarterNo3 days (snapshots) -
ProYes7 days5 minutes
EnterpriseYes30 days5 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:

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

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

PostgreSQL runs as a Kubernetes StatefulSet with a dedicated PersistentVolumeClaim backed by SSD storage. A ClusterIP Service provides a stable internal DNS name ([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

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 client = postgres(process.env.DATABASE_URL!)
export const db = drizzle(client)

SQLAlchemy (Python)

database.py
from sqlalchemy import create_engine

engine = create_engine(
    os.environ["DATABASE_URL"],
    pool_size=5,
    max_overflow=10,
    pool_pre_ping=True,
)