Overview
Dual execution allows you to:- Store some models in the cloud (MotherDuck)
- Store other models locally (DuckDB file)
- Reference models across both databases seamlessly
- Control data placement with simple configuration
How It Works
By using theattach parameter in your dbt profile, you can add a second database to DuckDB’s execution context. Models can then specify which database to use via the database parameter.
Configuration
profiles.yml - Cloud-First Approach
Connect to MotherDuck and attach a local database:profiles.yml
profiles.yml - Local-First Approach
Connect locally and attach MotherDuck databases:profiles.yml
Model Configuration
Specify Database for Local Models
Use thedatabase config to direct models to local storage:
models/my_second_dbt_model.sql
Cloud Models (Default)
Models without adatabase config write to the main connection (cloud):
models/my_first_dbt_model.sql
Reference Across Databases
Models can reference other models regardless of location:models/my_third_dbt_model.sql
Data Flow Example
This example shows data flowing between cloud and local:Running the Project
Build models
Use Cases
Development and testing
Development and testing
Develop and test models locally, then promote to cloud:
- Iterate quickly on local data
- Push production models to MotherDuck
- Keep test data local while production is in cloud
Hybrid architectures
Hybrid architectures
Combine local and cloud storage strategically:
- Large raw data in cloud
- Processed aggregates locally for faster access
- Temporary work tables local, final outputs cloud
Cost optimization
Cost optimization
Control storage costs by placement:
- Frequently accessed data locally
- Archive data in cloud
- Intermediate transformations local
Data locality
Data locality
Optimize for performance:
- Keep related data together
- Minimize cross-database transfers
- Cache frequently joined tables locally
Best Practices
The
attach parameter can accept multiple paths, allowing you to work with multiple databases simultaneously:Advanced: TPC-DS Example
For a more complex example, see the dbt-dual-execution repository which includes:- 24 TPC-DS raw tables
- 99 TPC-DS analytical queries
- Models distributed across cloud and local
- Complex query patterns with cross-database references