dbt on Snowflake in Production: Warehouses, Tags and Grants
The dbt-snowflake configs that matter in production: per-model warehouses, query tags for cost attribution, grants, dynamic tables and incremental strategies.
By Dinesh ChandraSenior Data and AI Engineer · SnowPro certified- 1.Set a small default warehouse in the profile and use snowflake_warehouse to send only the heavy models, and lightweight tests, elsewhere.
- 2.Query tags set per model, joined to QUERY_ATTRIBUTION_HISTORY, turn a warehouse bill into a cost per dbt model.
- 3.Manage access with the grants config and decide deliberately about copy_grants; Snowflake changed CREATE OR REPLACE grant behavior in 2026.
- 4.In dbt, a dynamic_table defaults to scheduler DISABLE; setting target_lag hands refreshes to Snowflake.
- 5.merge is the default incremental strategy on Snowflake. Use delete+insert for non-unique keys and microbatch for time-based data.
Table of contents
- The problem
- The common wrong approach
- The approach that works
- Step 1: A small default warehouse, with overrides
- Step 2: Tag every query with its model
- Step 3: Declare grants in config
- Step 4: Use dynamic tables where the lag is the contract
- Step 5: Pick the incremental strategy per model
- Edge cases and changes
- Trade-offs
- Pitfalls
- FAQ
- Can tests run on a different warehouse than models?
- Does the query tag in the profile still apply?
- Should I use a dynamic table or an incremental model?
- Do grants work with database roles?
- What this means for your pipelines
The dbt Snowflake adapter ships with a set of configs that never appear in a beginner tutorial but decide what a production project costs and how safe it is: which warehouse each model uses, how its queries are tagged, who can read the result, and how incremental data lands.
Most teams discover these one incident at a time. A single huge model forces the whole project onto a large warehouse. Finance asks which models drive the bill and nobody can answer. A rebuild wipes an analyst role’s access. This post collects those configs in one place, with the syntax the dbt docs document today.
It assumes you run dbt yourself or through the dbt platform. If you want Snowflake to run the project for you, see dbt Projects on Snowflake; every config here works the same way there.
The problem
By default, every query dbt sends uses the warehouse in your profile, carries no tag, and creates objects with whatever privileges the build role leaves behind. That is fine for fifty models. At five hundred, three problems appear.
First, warehouse size is set by your heaviest model. If one fact table needs a large warehouse, every staging view pays large-warehouse rates too. Second, cost is invisible. Snowflake bills warehouses, not models, so you know the total but not which model drives it. Third, access drifts. Tables are recreated on each full build, and grants applied by hand disappear or linger depending on how the object was replaced.
The common wrong approach
The usual fix is a second dbt job with a different target and a bigger warehouse for the “heavy” folder. Now you have two schedules to keep in order, two places where the same model can be selected, and cost attribution still at the job level.
For grants, the usual fix is a post-hook such as
grant select on {{ this }} to role reporter copied into each model.
It works until someone forgets it, and it never revokes anything.
The approach that works
flowchart TD
m["Model config"] --> wh["snowflake_warehouse: which compute"]
m --> tag["query_tag: who pays"]
m --> gr["grants: who reads"]
m --> mat["materialization and incremental_strategy: how data lands"]
Four configs per model answer the four production questions.
Step 1: A small default warehouse, with overrides
Put a small warehouse in the profile, then override per folder or
per model with snowflake_warehouse. Data tests accept the same
config, so tests can run on smaller compute than the models:
# dbt_project.yml
models:
my_project:
+snowflake_warehouse: TRANSFORM_XS
marts:
clickstream:
+snowflake_warehouse: TRANSFORM_L
snapshots:
+snowflake_warehouse: TRANSFORM_S
data_tests:
+snowflake_warehouse: TRANSFORM_XS
For a single model, set it in the model file:
-- models/marts/clickstream/fct_sessions.sql
{{ config(
materialized='incremental',
snowflake_warehouse='TRANSFORM_L'
) }}
select ...
Choose the override from evidence, not instinct. The signals in the warehouse sizing guide, such as spilling to remote storage, tell you when a model actually needs more compute.
Step 2: Tag every query with its model
Snowflake’s QUERY_TAG session parameter is recorded with each
query. dbt sets it from three places: a default in the profile, a
query_tag model config, or an override of the set_query_tag
macro. The macro override tags every model automatically. This
version follows the documented pattern and adds the target name:
-- macros/set_query_tag.sql
{% macro set_query_tag() -%}
{% set new_query_tag = 'dbt:' ~ target.name ~ ':' ~ model.name %}
{% set original_query_tag = get_current_query_tag() %}
{% do run_query("alter session set query_tag = '{}'".format(new_query_tag)) %}
{{ return(original_query_tag) }}
{%- endmacro %}
dbt sets the tag at the start of each materialization and resets it
at the end. Then attribute credits per model with the
QUERY_ATTRIBUTION_HISTORY view, which records compute credits per
query along with its tag:
select
query_tag,
sum(credits_attributed_compute) as credits
from snowflake.account_usage.query_attribution_history
where start_time >= dateadd('day', -30, current_timestamp())
and query_tag like 'dbt:prod:%'
group by query_tag
order by credits desc
limit 20;
That view excludes warehouse idle time and can lag by up to eight hours. Your top twenty models by credits are where the cost optimization work should start.
Step 3: Declare grants in config
The grants config makes dbt run the grant and revoke
statements needed so the object’s privileges match the YAML:
# dbt_project.yml
models:
my_project:
marts:
+grants:
select: ['reporter', 'bi_service']
Two Snowflake details matter. Grants are fully supported only for
account roles, not database roles. And copy_grants decides what
happens to existing privileges when Snowflake recreates a table or
view:
# dbt_project.yml
models:
+copy_grants: true
With copy_grants: true, dbt adds COPY GRANTS so existing
privileges survive a rebuild. With it false or unset, dbt-snowflake
v1.13 and later adds IGNORE GRANTS so old privileges are dropped
and your grants config is applied fresh. The dbt docs note that on
earlier adapter versions, after Snowflake’s 2026 change to grant
handling on CREATE OR REPLACE, extra privileges may be kept and dbt
does not remove them. Check your adapter version before relying on
either behavior. Role design itself belongs in your
RBAC model, not in dbt.
Step 4: Use dynamic tables where the lag is the contract
The dynamic_table materialization creates a Snowflake dynamic
table. In dbt v1.12 and later, how it refreshes depends on two
configs. If you set target_lag, Snowflake’s scheduler refreshes it:
-- models/marts/fct_orders_live.sql
{{ config(
materialized='dynamic_table',
snowflake_warehouse='TRANSFORM_S',
target_lag='15 minutes',
refresh_mode='INCREMENTAL'
) }}
select order_id, customer_id, status, updated_at
from {{ ref('stg_orders') }}
If you set neither target_lag nor scheduler, dbt creates it with
scheduler: DISABLE and refreshes it during dbt run. That differs
from native Snowflake DDL, where the scheduler is on by default.
Setting scheduler: DISABLE together with target_lag is an error.
Two more options help with cost: refresh_warehouse (dbt-snowflake
v1.11 and later) sends background refreshes to a smaller warehouse,
and snowflake_initialization_warehouse (v1.12 and later) uses a
larger one only for the initial build. The
dynamic tables guide covers
when dynamic tables beat scheduled models.
Step 5: Pick the incremental strategy per model
Snowflake supports merge (the default), append, delete+insert,
insert_overwrite and microbatch:
-- models/marts/fct_order_lines.sql
{{ config(
materialized='incremental',
incremental_strategy='delete+insert',
unique_key='order_id',
on_schema_change='append_new_columns'
) }}
select * from {{ ref('stg_order_lines') }}
{% if is_incremental() %}
where loaded_at > (select max(loaded_at) from {{ this }})
{% endif %}
Use merge when the key is unique. Snowflake fails a merge with a
“nondeterministic merge” error if the unique_key is not actually
unique; delete+insert is the documented fallback, as in this order
lines model where one order has many lines. append suits immutable
logs. insert_overwrite on Snowflake overwrites the whole table,
not a partition. For event data, the
microbatch strategy
uses delete+insert per time batch and adds backfills and retries.
Edge cases and changes
Temporary relations. For incremental builds, dbt on Snowflake
prefers a view over a temporary table for the staging step. You can
change this with tmp_relation_type (view, table or
transient). delete+insert with a unique_key requires a
temporary table, so forcing a view there errors. With transient,
concurrent runs in the same schema can overwrite each other’s tmp
relation; the docs show overriding
snowflake__resolve_incremental_tmp_relation to route it to a
per-run schema.
Dynamic table limits. Changing a dynamic table’s SQL requires
--full-refresh. Dynamic tables cannot sit downstream of
materialized views, external tables or streams, and dbt model
contracts are not supported on them.
Query tags on failure. Tags are set at session level. If a materialization fails midway, later queries in that session can run with the wrong tag until it is reset.
Clustering. cluster_by adds clustering keys and orders the
data on write, including the staged data before an incremental
merge.
String sizes. The dbt docs warn that a Snowflake change to
default string and binary column sizes, planned for September 2026,
can break some incremental models using sync_all_columns on
dbt-snowflake below v1.10.6. Upgrade the adapter if you are behind.
Trade-offs
Per-model warehouses lower cost but add warehouses to manage, and more warehouses can mean more idle minutes before auto-suspend. Start with two or three sizes, not one per team.
Tagging every model adds an alter session statement before and
after each model. That is extra round trips in exchange for
attribution you cannot get any other way at model level.
Dynamic tables trade orchestration for declared freshness. You stop scheduling those models, but you also lose some dbt features, such as contracts, and every SQL change rebuilds the table.
Pitfalls
- Large warehouse in the profile. Every view and test pays for it. Default small and override up.
- Grants as post-hooks. They never revoke. Use the
grantsconfig. - Assuming copy_grants behavior. It changed with adapter v1.13.
Pin the adapter and set
copy_grantsexplicitly. - Merge on a non-unique key. Snowflake errors. Fix the key or
use
delete+insert. - Forgetting dbt’s dynamic table default. Without
target_lag, Snowflake never refreshes it on its own.
FAQ
Can tests run on a different warehouse than models?
Yes. snowflake_warehouse is supported on data tests, at the
project level under data_tests: or on an individual test’s
config. Lightweight tests rarely need the compute that builds
large models.
Does the query tag in the profile still apply?
Yes. The profile tag is the default for the connection. A model’s
query_tag config or an overridden set_query_tag macro replaces it
for that model and resets it afterward.
Should I use a dynamic table or an incremental model?
Use a dynamic table when you want Snowflake to keep a result within a declared lag and the SQL fits dynamic table limits. Use an incremental model when you need dbt features such as contracts, custom merge logic or explicit scheduling.
Do grants work with database roles?
Not fully. The dbt docs state that granting and revoking is only fully supported for Snowflake account roles. Grant to account roles and map database roles outside dbt if you use them.
What this means for your pipelines
Treat these configs as part of each model’s definition, not as
tuning you do later. A model should say which compute it needs, how
its queries are tagged, who may read it, and how new data lands.
Put the defaults in dbt_project.yml so new models inherit sensible
choices, and override only where evidence says to.
Start with the two that pay back fastest: a small default warehouse
with targeted overrides, and per-model query tags joined to
QUERY_ATTRIBUTION_HISTORY. Within a week you will know which models
cost the most, and you will have the configs ready to fix them.
Sources: Snowflake configurations (dbt), grants, Incremental strategy, About microbatch, QUERY_ATTRIBUTION_HISTORY view.
Senior Data & AI Engineer · SnowPro Core & Gen AI Certified
4+ years building production data platforms on Snowflake, Databricks, AWS, and Azure. I write from hands-on experience with Medallion architectures, dbt, Airflow, PySpark, and Snowflake Cortex AI. Every tutorial on this blog reflects real pipeline decisions, not documentation rewrites.
Read more about the author →