REDB CLI
Database management from your terminal. Schema init, data export & import.
dotnet tool install --global redb.CLI
Commands
$ redb init
Create all REDB tables, sequences, functions and views in an existing empty database.
bash
# PostgreSQL
redb init -p postgres -c "Host=localhost;Database=mydb;Username=postgres;Password=pass"
# SQL Server
redb init -p mssql -c "Server=localhost;Database=mydb;User Id=sa;Password=pass;TrustServerCertificate=True"| Option | Alias | Required | Description |
|---|---|---|---|
--provider | -p | Yes | Database provider: postgres, mssql |
--connection | -c | Yes | ADO.NET connection string |
--verbose | -v | No | Show detailed output |
$ redb schema
Output the full SQL initialization script to a file or stdout. Useful for DBA review or CI/CD pipelines.
bash
# Write to file
redb schema -p postgres -o redb_schema.sql
# Output to stdout
redb schema -p postgres
# Pipe to psql
redb schema -p postgres | psql -d mydb| Option | Alias | Required | Description |
|---|---|---|---|
--provider | -p | Yes | Database provider: postgres, mssql |
--output | -o | No | Output file. If omitted, writes to stdout |
$ redb export
Export the entire database (or specific schemes) to a .redb file — JSONL format, optionally compressed.
bash
# Full export with compression
redb export -p postgres -c "Host=localhost;Database=redb;..." \
-o backup.redb --compress --batch-size 100000 -v
# Export specific schemes only
redb export -p postgres -c "..." -o partial.redb --schemes 100,200
# Dry run
redb export -p postgres -c "..." -o test.redb --dry-run| Option | Alias | Required | Description |
|---|---|---|---|
--provider | -p | Yes | Database provider |
--connection | -c | Yes | Connection string |
--output | -o | Yes | Output file path (.redb) |
--compress | No | Compress output with ZIP | |
--schemes | No | Scheme IDs to export (comma-separated) | |
--batch-size | No | Batch size (default: 1000) | |
--dry-run | No | Preview without execution | |
--verbose | -v | No | Detailed output |
$ redb import
Import data from a .redb file into the database.
bash
# Import with clean (truncates tables first)
redb import -p postgres -c "Host=localhost;Database=redb;..." \
-i backup.redb --clean -v --batch-size 100000
# Dry run
redb import -p mssql -c "..." -i backup.redb --dry-run| Option | Alias | Required | Description |
|---|---|---|---|
--provider | -p | Yes | Database provider |
--connection | -c | Yes | Connection string |
--input | -i | Yes | Input file path (.redb) |
--clean | No | Truncate all REDB tables before import | |
--batch-size | No | Batch size for bulk insert (default: 1000) | |
--dry-run | No | Preview without execution | |
--verbose | -v | No | Detailed output |
Supported Providers
| Provider | Aliases | Connection String Example |
|---|---|---|
| PostgreSQL | postgres, postgresql, pgsql |
Host=localhost;Port=5432;Database=redb;Username=postgres;Password=pass |
| SQL Server | mssql, sqlserver |
Server=localhost;Database=redb;User Id=sa;Password=pass;TrustServerCertificate=True |
Typical Workflows
New Project Setup
bash
# 1. Create database
createdb myapp
# 2. Initialize REDB schema
redb init -p postgres -c "Host=localhost;Database=myapp;Username=postgres;Password=pass" -v
# 3. Run your application
dotnet run --project MyAppDatabase Migration (Postgres → MSSQL)
bash
# 1. Export from PostgreSQL
redb export -p postgres -c "Host=src;Database=redb;..." -o data.redb --compress -v
# 2. Init schema in SQL Server
redb init -p mssql -c "Server=dst;Database=redb;..." -v
# 3. Import into SQL Server
redb import -p mssql -c "Server=dst;Database=redb;..." -i data.redb --clean -vBackup & Restore
bash
# Backup
redb export -p postgres -c "..." -o backup_2026-02-13.redb --compress
# Restore
redb import -p postgres -c "..." -i backup_2026-02-13.redb --clean -vAlso Available from Code
All CLI operations are also accessible programmatically via IRedbService:
csharp
// A: Auto-create on startup (recommended)
await redb.InitializeAsync(ensureCreated: true);
// B: Explicit call
await redb.EnsureDatabaseAsync();
await redb.InitializeAsync();
// C: Export SQL for DBA review
var sql = redb.GetSchemaScript();
File.WriteAllText("redb_schema.sql", sql);