dbt run: Execute dbt Models
The dbt run
command is a core dbt command that executes your project’s compiled SQL model files on your specified target database. This command connects to the database and runs SQL statements required to build your data models according to the predefined materialization strategies (opens in a new tab).
These models are processed in a sequence determined by their interdependencies through the use of the ref()
macro in the models definition.
How to Run Only Specific Models
dbt allows you to selectively materialize models, which is beneficial during development or particular use cases. For instance, you might choose to run only a subset of models to test new changes without affecting the entire data set:
Selection Flags
To specify which nodes to execute, dbt provides several flags:
--select
: specifies models or groups to execute.--exclude
: omits certain models from execution.--selector
: uses predefined lists of models.
Graph Operations
Graph operators allow you to expand the selection contextually based on the dependency graph:
The +
operator is used to include related nodes:
- Placing + after a model name (
model+
) selects the model and all its downstream dependencies (i.e., nodes that depend on this model). - Placing + before a model name (
+model
) selects the model and all its upstream dependencies (i.e., nodes that the model depends on). - Enclosing a model name with + on both sides (
+model+
) selects the model, and all its upstream and downstream dependencies.
_10dbt run --select "my_model+" # Runs 'my_model' and all nodes that are downstream._10dbt run --select "+my_model" # Runs 'my_model' and all upstream nodes._10dbt run --select "+my_model+" # Runs 'my_model', its ancestors, and descendants.
Combining Flags for Advanced Selection
You can combine various flags to finely control which parts of your project are executed. This flexibility is particularly useful in complex projects where you need to run or test specific sections of your data model.
_10dbt run --select "+my_model" --exclude "my_model+2"
In this command:
--select
:+my_model
selects my_model and all its ancestors.--exclude
:my_model+2
removes the model and its direct and second-degree descendants from the selection.
Refreshing Incremental Models
To fully refresh incremental models (opens in a new tab), the --full-refresh
option is used:
_10dbt run --full-refresh
This flag is useful in scenarios such as schema modifications of incremental models or complete reprocessing due to updated logic. When this flag is used, the is_incremental() macro will evaluate to false, affecting the behavior of your models.
Advanced Options
dbt supports advanced operational features like:
- Fail-fast mode (-x), which immediately stops the run if any errors are detected.
- Colorized logs can be enabled or disabled, influencing how output is displayed in your terminal.
_10dbt run --fail-fast # Run dbt models with the fail-fast option. This stops the run immediately if any errors occur._10dbt run --use-colors # Run dbt models with colorized output enabled. This makes the terminal output easier to read by highlighting important information.
Manage Sources and dbt Models in one place
Build end-to-end pipelines using a single framework.
Get Started