Databases

Create, attach, and manage databases across providers.

Overview

Relight manages Postgres databases on multiple providers:

ProviderServiceType
gcpCloud SQL (Postgres)GCP native
awsRDS (Postgres)AWS native
azureFlexible Server (Postgres)Azure native
doManaged Databases (Postgres)DigitalOcean

All providers use managed Postgres for unified backup, migration, and export across clouds.

List databases

relight db
relight db --db do             # filter by provider
relight db --json

Create a database

relight db create mydb
relight db create mydb --db aws
relight db create mydb --db do
relight db create mydb --location enam

For full-stack providers (GCP, AWS, Azure), this creates a database on a shared Postgres instance. If no shared instance exists, Relight creates one first.

For DigitalOcean, this creates a database on a Managed Databases cluster.

Attach to an app

relight db attach mydb myapp

This:

  1. Creates a per-app database user with isolated permissions
  2. Injects DATABASE_URL into the app’s env vars

You can attach the same database to multiple apps. Each app gets its own user with independent credentials.

Detach from an app

relight db detach myapp

Removes the per-app database user, revokes its permissions, and removes the injected env vars.

Connect directly

relight db shell mydb                    # interactive SQL REPL
relight db query mydb "SELECT 1"         # run a single query
relight db query mydb "SELECT 1" --json  # JSON output

Import and export

relight db import mydb backup.sql        # import a .sql file
relight db export mydb                   # dump to stdout
relight db export mydb -o backup.sql     # dump to file

Credentials

relight db info mydb               # show connection details
relight db token mydb              # show auth token
relight db token mydb --rotate     # rotate credentials

Reset (drop all tables)

relight db reset mydb
relight db reset mydb --confirm mydb   # skip prompt

Destroy

relight db destroy mydb
relight db destroy mydb --confirm mydb

Detach all apps first. On full-stack providers, this drops the database from the shared instance and removes all per-app users.

Per-app user isolation

When you attach a database to an app, Relight creates a Postgres user named app_<dbname>_<appname> with:

  • CONNECT on the database
  • USAGE on the public schema
  • ALL PRIVILEGES on all tables and sequences
  • ALTER DEFAULT PRIVILEGES so the app user can access future tables

Each app’s user is independent. Detaching revokes all privileges and drops the user. Destroying the database cleans up all per-app users automatically.