---
title: "Multi-Tenancy"
---

# Multi-Tenancy

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

## Tenant Management

### Create Tenant

```bash
\tenant create acme_corp enterprise schema
```

### List Tenants

```bash
\tenants
```

### Switch Tenant Context

```bash
\tenant use acme_corp
```

## Isolation Levels

| Level | Description |
|-------|-------------|
| `shared` | Logical isolation via tenant_id column |
| `schema` | Per-tenant schema isolation |
| `database` | Full database isolation |

## Quotas

### Set Quotas

```bash
# \tenant quota set <tenant> <storage_mb> <connections> <qps>
\tenant quota set acme_corp 10240 50 1000
```

### View Usage

```bash
\tenant usage acme_corp
```

## Plans

```bash
\tenant plans                    # List plans
\tenant plan create pro 2 51200 50 1000   # <name> <tier> <storage_mb> <conn> <qps>
\tenant plan acme_corp pro       # Assign plan
```

## Change Data Capture (CDC)

```bash
\tenant cdc                      # View recent events
\tenant cdc export events.json   # Export to file
```

## Where Tenants Are Managed

Manage tenants, plans and quotas from the REPL (above) or the embedded Rust API; a REST
API for tenant management is planned. Tenants, plans and policies live in the memory of
the process that defines them and are not persisted across restarts.

In the stock Nano server, row-level security is enforced through the embedded API and the
REPL; SQL `CREATE POLICY` and enforcement for REST and wire clients are planned.

## Related

- [Row-Level Security](https://www.heliosdb.com/docs/nano/features/rls/) - Policy-based access control
- [REST API Reference](https://www.heliosdb.com/docs/nano/api/rest-api/) - HTTP routes in the current release
