Quick Start¶
This guide will have you extracting database subsets in under 5 minutes.
Basic Extraction¶
Extract a single record and all its related data:
This outputs SQL to stdout. Pipe it to a file:
Understanding Seeds¶
Seeds tell dbslice where to start. Two formats are supported:
Primary Key — table.column=value
dbslice extract $DB_URL --seed "orders.id=12345"
dbslice extract $DB_URL --seed "users.email=john@example.com"
WHERE Clause — table:WHERE_CLAUSE
dbslice extract $DB_URL --seed "orders:status='failed'"
dbslice extract $DB_URL --seed "orders:created_at > '2024-01-01'"
Multiple Seeds¶
Extract data for multiple records:
Control Traversal¶
Depth¶
Limit how many FK hops to follow (default: 3):
# Only immediate relationships
dbslice extract $DB_URL --seed "orders.id=1" --depth 1
# Deep traversal
dbslice extract $DB_URL --seed "orders.id=1" --depth 5
Direction¶
Control which relationships to follow:
# Parents only (referenced tables)
dbslice extract $DB_URL --seed "orders.id=1" --direction up
# Children only (tables that reference this)
dbslice extract $DB_URL --seed "orders.id=1" --direction down
# Both (default)
dbslice extract $DB_URL --seed "orders.id=1" --direction both
Anonymize Sensitive Data¶
Automatically detect and anonymize PII:
Add specific fields to redact:
Output Formats¶
# SQL (default)
dbslice extract $DB_URL --seed "orders.id=1" --output sql
# JSON
dbslice extract $DB_URL --seed "orders.id=1" --output json
# CSV
dbslice extract $DB_URL --seed "orders.id=1" --output csv
Save to File¶
Import to Local Database¶
# Extract
dbslice extract $PROD_DB --seed "orders.id=1" --anonymize > subset.sql
# Import to local
psql -d localdb < subset.sql
Inspect Schema First¶
Before extracting, you can inspect your database schema:
This shows tables, foreign keys, and detected sensitive fields.
Using Config Files¶
For repeated extractions, use a config file:
# Generate config from database
dbslice init postgres://localhost/mydb
# Use config
dbslice extract --config dbslice.yaml --seed "orders.id=123"
Next Steps¶
- CLI Reference - All options explained
- Configuration - YAML config files
- Advanced Usage - Complex scenarios