Databases

Provision a PostgreSQL database

5 min readUpdated April 2026

StackBlaze managed PostgreSQL runs on a Kubernetes StatefulSet with a dedicated PersistentVolumeClaim. Unlike ephemeral pods, StatefulSets maintain a stable identity and storage across restarts, your data survives pod rescheduling, node failures, and cluster upgrades.

The database is never exposed to the public internet. A Kubernetes Service provides a stable internal DNS name (postgres.internal) that your application services resolve automatically within the project network.

Architecture

TCP:5432mount
App Service

DATABASE_URL

injected as secret

PostgreSQL

postgres.internal

StatefulSet

PVC Storage

/var/lib/postgresql

PersistentVolumeClaim

Auto-injected connection string

.env (injected)

# Automatically set when you attach the database

DATABASE_URL=postgresql://sb_user:s3cr3tP4ss!@postgres.internal:5432/mydb

# postgres.internal resolves via Kubernetes Service DNS

# Only accessible from within your project namespace

Running migrations

Prisma migration deploy

$ npx prisma migrate deploy

Prisma schema loaded from prisma/schema.prisma

Datasource "db": PostgreSQL database "mydb"

                        at postgres.internal:5432

3 migrations found in prisma/migrations

✔ 20240101000000_init

✔ 20240215000000_add_users_table

✔ 20240310000000_add_posts_index

✓ All migrations have been applied

Under the hood

  • StatefulSet — ensures the Postgres pod gets a stable hostname and retains its PVC across restarts. Kubernetes won't schedule a replacement pod until the original terminates cleanly, preventing split-brain.
  • PersistentVolumeClaim — backed by the cluster's default StorageClass (typically network block storage). The PVC outlives the pod — you can scale to zero and scale back without losing data.
  • Kubernetes Service: a ClusterIP Service named after your database creates the stable DNS entry (postgres.internal) that survives pod restarts and rescheduling.
  • Daily backups: StackBlaze takes automated daily snapshots and retains them for 7 days. Point-in-time recovery (PITR) is available on paid plans and captures WAL logs every 5 minutes.

Step by step

01

Create a database from the dashboard

Click "New service" → "Database" → "PostgreSQL". Choose a Postgres version (15 or 16), storage size (1 GB to 500 GB), and a plan. StackBlaze provisions a Kubernetes StatefulSet with a PersistentVolumeClaim in seconds.

02

Attach the database to a service

Navigate to your web service or worker, go to the "Environment" tab, and click "Attach database". Select the Postgres instance. StackBlaze automatically adds DATABASE_URL as an injected secret. The hostname, postgres.internal, resolves via Kubernetes Service DNS.

03

Run your migrations

Trigger a deploy and use a start command that runs migrations before starting the server, or run them manually via the StackBlaze CLI. For Prisma, use "npx prisma migrate deploy". For Django, "python manage.py migrate". Both connect using DATABASE_URL automatically.

04

Query in production

Your service connects to Postgres over the internal cluster network. No public internet exposure, no firewall rules to configure. The connection string includes a random password generated at provision time and rotated when you trigger a credential rotation from the dashboard.