Solutions

dbt Relation Cache Deadlock Diagnosis

Identify concurrent lock patterns that cause dbt incremental model failures in Airflow.

What is a dbt relation cache deadlock?

A relation cache deadlock occurs when a single Airflow DAG invocation triggers dbt to query the warehouse system tables (like sys.tables or information_schema.tables) at two points simultaneously — once during dbt's internal relation cache population at startup, and again during an incremental model's MERGE or UPSERT operation. The two concurrent reads acquire conflicting locks and deadlock, causing the run to fail with a generic lock timeout or deadlock error.

Why relation cache deadlocks are hard to diagnose

The error message from a relation cache deadlock looks like a generic warehouse lock timeout — it doesn't mention "relation cache" or "deadlock" explicitly. Data engineers typically suspect hardware issues, warehouse resource contention, or concurrent user queries before discovering the dbt-internal lock conflict. Reproducing the issue locally is difficult because it only occurs under specific Airflow scheduling conditions.

How Ordo detects relation cache deadlocks

Ordo analyzes warehouse query logs for the failed run window, looking for concurrent queries on system tables that overlap with incremental MERGE operations from the same dbt invocation. When this pattern is found, Ordo identifies the specific model causing the lock conflict and the exact query timeline:

Relation cache deadlock detected (88% confidence)

Pattern: Concurrent sys.tables query + MERGE on fct_events

Timeline:

03:14:22 — dbt relation cache population (queries sys.tables)

03:14:23 — fct_events MERGE (also queries sys.tables for schema)

03:14:24 — Lock timeout: deadlock detected

Fix: Add --no-populate-cache flag to dbt run, or serialize model execution

Which warehouses are affected

Relation cache deadlocks are most common on Snowflake and Redshift with concurrent incremental model runs in Airflow. BigQuery uses a different locking model and is less susceptible to this pattern. Ordo checks for this pattern across all three warehouses.

Ready to stop debugging pipelines manually?