0
0
DbtHow-ToBeginner ยท 4 min read

How to Configure dbt for Snowflake: Step-by-Step Guide

To configure dbt for Snowflake, you need to set up the profiles.yml file with your Snowflake account details, including account, user, password, role, warehouse, database, and schema. This file tells dbt how to connect to your Snowflake environment for running models and transformations.
๐Ÿ“

Syntax

The profiles.yml file uses YAML syntax to define connection details for Snowflake. Key parts include:

  • account: Your Snowflake account identifier.
  • user: Your Snowflake username.
  • password: Your Snowflake password or use environment variables for security.
  • role: The Snowflake role to use for permissions.
  • warehouse: The compute warehouse to run queries.
  • database: The target database.
  • schema: The target schema within the database.
yaml
your_profile_name:
  target: dev
  outputs:
    dev:
      type: snowflake
      account: your_account
      user: your_username
      password: your_password
      role: your_role
      warehouse: your_warehouse
      database: your_database
      schema: your_schema
      threads: 1
      client_session_keep_alive: false
๐Ÿ’ป

Example

This example shows a complete profiles.yml configuration for connecting dbt to Snowflake. Replace placeholders with your actual Snowflake details.

yaml
my_snowflake_profile:
  target: dev
  outputs:
    dev:
      type: snowflake
      account: xy12345.us-east-1
      user: dbt_user
      password: SuperSecret123
      role: SYSADMIN
      warehouse: COMPUTE_WH
      database: ANALYTICS_DB
      schema: RAW_DATA
      threads: 4
      client_session_keep_alive: true
โš ๏ธ

Common Pitfalls

Common mistakes when configuring dbt for Snowflake include:

  • Using incorrect account format; it must match your Snowflake URL without https or .snowflakecomputing.com.
  • Hardcoding passwords instead of using environment variables for security.
  • Not specifying the correct role or warehouse, causing permission or resource errors.
  • Forgetting to set threads which controls parallelism.
  • Misnaming the profile in dbt_project.yml so dbt cannot find the connection.

Example of a wrong and right way to specify the account:

yaml
# Wrong account format
account: https://xy12345.us-east-1.snowflakecomputing.com

# Correct account format
account: xy12345.us-east-1
๐Ÿ“Š

Quick Reference

SettingDescriptionExample
accountSnowflake account identifier (no URL prefix)xy12345.us-east-1
userSnowflake usernamedbt_user
passwordPassword or env var referenceSuperSecret123
roleSnowflake role for permissionsSYSADMIN
warehouseCompute warehouse to run queriesCOMPUTE_WH
databaseTarget databaseANALYTICS_DB
schemaTarget schema in databaseRAW_DATA
threadsNumber of parallel threads4
client_session_keep_aliveKeep session alive during long runstrue
โœ…

Key Takeaways

Configure your Snowflake connection in the profiles.yml file under your dbt profile.
Use the correct account format without URL prefixes for the Snowflake account setting.
Avoid hardcoding passwords; use environment variables for better security.
Specify the right role, warehouse, database, and schema to avoid permission errors.
Set threads to control parallel execution and improve performance.