Troubleshooting dbt
When things go wrong with dbt, systematic debugging saves time. This guide covers common issues and their solutions.
Compilation errors
Syntax errors
Symptom: dbt compile fails with SQL syntax error
Common causes:
- Missing commas between columns
- Unclosed parentheses
- Invalid SQL syntax
Solution:
- Check line numbers in error messages
- Validate SQL in your warehouse's query editor
- Look for syntax highlighting issues in your IDE
-- Error: Missing comma
select
customer_id
customer_name -- Missing comma here!
email
from customers
Reference errors
Symptom: Model 'xxx' not found
Common causes:
- Typo in model name
- Model doesn't exist yet
- Wrong path or naming
Solution:
- Verify the model name:
dbt ls | grep model_name
- Check for typos in ref():
-- Wrong
{{ ref('cutomers') }} -- typo!
-- Correct
{{ ref('customers') }}
Jinja errors
Symptom: Template syntax errors
Common causes:
- Missing closing tags
- Invalid variable references
- Logic errors in macros
Solution:
- Check Jinja syntax:
-- Wrong: Missing endif
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
-- Correct
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}
- Debug Jinja with print:
{{ log('Variable value: ' ~ my_variable, info=True) }}
Connection errors
Database connection failed
Symptom: Database connection failed or timeout errors
Common causes:
- Wrong credentials
- Network issues
- Database server down
- Firewall blocking
Solution:
- Test connection directly:
dbt debug
- Verify profiles.yml:
my_profile:
target: dev
outputs:
dev:
type: snowflake
account: your-account # Check this!
user: your-user
password: your-password
database: analytics
warehouse: compute_wh
schema: dbt_dev
- Check environment variables:
echo $SNOWFLAKE_ACCOUNT
echo $SNOWFLAKE_USER
Permission denied
Symptom: Insufficient privileges or Access denied
Solution:
- Verify user has required permissions:
-- As admin, check grants
SHOW GRANTS TO USER dbt_user;
- Required permissions:
- CREATE SCHEMA
- CREATE TABLE
- CREATE VIEW
- SELECT on source tables
- Grant permissions:
GRANT USAGE ON WAREHOUSE compute_wh TO ROLE dbt_role;
GRANT USAGE ON DATABASE analytics TO ROLE dbt_role;
GRANT CREATE SCHEMA ON DATABASE analytics TO ROLE dbt_role;
Test failures
Uniqueness test failed
Symptom: Uniqueness test failed for column 'xxx'
Causes:
- Duplicate values in source data
- Incorrect grain assumption
- Data quality issues
Solution:
- Find duplicates:
select customer_id, count(*)
from {{ ref('stg_customers') }}
group by 1
having count(*) > 1
- Check source data quality
- Consider composite key if single column isn't unique
- Fix upstream data pipeline
Relationship test failed
Symptom: Relationship test failed - orphaned records
Causes:
- Referential integrity violation
- Missing parent records
- Data loading order issues
Solution:
- Find orphaned records:
select o.customer_id
from {{ ref('stg_orders') }} o
left join {{ ref('stg_customers') }} c
on o.customer_id = c.customer_id
where c.customer_id is null
- Decide strategy:
- Fix source data
- Use inner join instead of left join
- Accept orphanage (remove test)
Accepted values test failed
Symptom: Accepted values test failed
Solution:
- Find unexpected values:
select distinct status
from {{ ref('stg_orders') }}
where status not in ('pending', 'complete', 'cancelled')
- Update accepted values or fix source data
Performance issues
Slow compilation
Symptom: dbt compile takes too long
Causes:
- Too many models
- Complex macros
- Inefficient Jinja
Solutions:
- Use partial parsing:
dbt compile --partial-parse
- Reduce macro complexity
- Split large projects
Slow model execution
Symptom: Models take hours to build
Solutions:
- Check query plan in warehouse
- Add indexes/clustering keys
- Use incremental materialization
- Optimize joins
- Filter early in CTEs
See: dbt Performance Optimization
Out of memory
Symptom: Out of memory or warehouse crashes
Solutions:
- Increase warehouse size temporarily:
{{ config(
materialized='table',
snowflake_warehouse='LARGE_WH'
) }}
- Process data in batches
- Use incremental models
- Optimize aggregations
Package issues
Package not found
Symptom: Package dbt-labs/dbt_utils not found
Solution:
- Check packages.yml:
packages:
- package: dbt-labs/dbt_utils
version: 1.1.1
- Install packages:
dbt deps
- Verify package hub is accessible
Version conflicts
Symptom: Package version conflicts
Solution:
- Pin specific versions:
packages:
- package: dbt-labs/dbt_utils
version: [">=1.0.0", "<2.0.0"]
- Clear dbt packages:
rm -rf dbt_packages/
dbt deps
Incremental model issues
Incremental model not updating
Symptom: Incremental model shows stale data
Solutions:
- Check incremental logic:
{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}
- Force full refresh:
dbt run --full-refresh --select model_name
- Check for schema changes
Duplicate records in incremental model
Symptom: Incremental model has duplicates
Solutions:
- Use merge strategy:
{{ config(
materialized='incremental',
unique_key='id',
incremental_strategy='merge'
) }}
- Ensure unique_key is actually unique
- Check for late-arriving data handling
Git and version control
Merge conflicts
Symptom: Git merge conflicts in dbt files
Solution:
- For schema.yml conflicts:
# Accept both changes
git checkout --ours models/schema.yml
git checkout --theirs models/schema.yml
git add models/schema.yml
- For SQL files:
- Manually resolve
- Test compilation after merge
- Run full test suite
Schema drift
Symptom: Tests fail after team member's changes
Solutions:
- Run full test suite before merging:
dbt test
- Use CI/CD to catch issues
- Communicate breaking changes
Debugging techniques
Enable verbose logging
dbt run --select model_name --debug
Print variable values
{{ log('My variable: ' ~ my_var, info=True) }}
Check compiled SQL
# View compiled SQL
cat target/compiled/project_name/models/model_name.sql
Test models in isolation
# Run single model
dbt run --select model_name
# Run model and children
dbt run --select model_name+
Getting help
Check logs
# View recent logs
tail -f logs/dbt.log
# Search for errors
grep "ERROR" logs/dbt.log
Community resources
- dbt Slack: #troubleshooting channel
- GitHub Issues: Check existing issues
- Documentation: Official dbt docs
- Discourse: dbt Community forum
Reporting issues
When reporting issues, include:
- dbt version (
dbt --version) - Full error message
- Relevant model code
- profiles.yml (redacted)
- Steps to reproduce
FAQ
Why does dbt compile fail?
Common causes include syntax errors in SQL, missing references, incorrect Jinja syntax, or missing packages. Check the error message line numbers and verify all dependencies are installed.
How do I fix connection errors?
Verify your profiles.yml configuration, check credentials are correct, ensure network access to the warehouse, and confirm the database user has proper permissions.
Why are my tests failing?
Test failures indicate data quality issues. Check the failed records if store_failures is enabled, review recent data loads for anomalies, and verify test logic matches expectations.
How do I debug slow models?
Check query execution plans in your warehouse, look for missing indexes or clustering keys, review join efficiency, and consider incremental materialization for large datasets.