Skip to content

Multi-Tenancy

Build SaaS applications with built-in tenant isolation, quotas, and change data capture.

Tenant Management

Create Tenant

Terminal window
\tenant create acme_corp enterprise schema

List Tenants

Terminal window
\tenants

Switch Tenant Context

Terminal window
\tenant use acme_corp

Isolation Levels

LevelDescription
sharedLogical isolation via tenant_id column
schemaPer-tenant schema isolation
databaseFull database isolation

Quotas

Set Quotas

Terminal window
\tenant quota set acme storage=10GB connections=50 qps=1000

View Usage

Terminal window
\tenant usage acme

Plans

Terminal window
\tenant plans # List plans
\tenant plan create pro tier=2 storage=50GB
\tenant plan acme_corp pro # Assign plan

Change Data Capture (CDC)

Terminal window
\tenant cdc # View recent events
\tenant cdc export events.json # Export to file

Isolation over the Network

Row-level security policies apply to PostgreSQL wire sessions and to REST requests. A REST request runs as the database role named in its token’s sub claim. Give each tenant its own role, write policies against current_user, and never issue tenant tokens for superusers, who bypass row-level security. See the multi-tenant example.

REST endpoints for tenant management are planned. Until then, manage tenants with the REPL commands above.