dbslice
Extract minimal, referentially-intact database subsets for local development and debugging.
The Problem
Copying an entire production database to your machine is infeasible. But reproducing a bug often requires having the exact data that caused it. dbslice solves this by extracting only the records you need, following foreign key relationships to ensure referential integrity.
Quick Example
# Extract an order and all related records
dbslice extract postgres://localhost/myapp --seed "orders.id=12345" > subset.sql
# Import into local database
psql -d localdb < subset.sql
Key Features
Feature
Description
Zero-config
Introspects schema automatically, no data model file required
Single command
Extract complete data subsets with one command
Safe by default
Auto-detects and anonymizes sensitive fields
Cross-database
PostgreSQL, MySQL, SQLite with identical interface
Virtual FKs
Support for Django GenericForeignKeys and implicit relationships
Getting Started
Use Cases
Scenario
How dbslice helps
Debug a production bug
Extract the failing order and all related data
Create test fixtures
Extract representative data samples with anonymization
Seed development database
Get realistic data without the full database dump
Data migration testing
Extract subset to test migration scripts safely
How It Works
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Seed ID │────▶│ FK Graph │────▶│ Topo Sort │
│ orders.id=1 │ │ Traversal │ │ & Output │
└──────────────┘ └──────────────┘ └──────────────┘
│
┌──────┴──────┐
│ │
┌───▼───┐ ┌─────▼─────┐
│ users │ │ products │
└───────┘ └───────────┘
Introspect - Reads database schema to discover tables and FK relationships
Traverse - Starting from seed record(s), follows FK relationships via BFS
Extract - Fetches all identified records
Sort - Topologically sorts tables for correct INSERT order
Output - Generates SQL/JSON/CSV with proper escaping
Documentation