Connect Amazon Redshift to dbt to build, test, and document SQL models in a version-controlled workflow.
dbt turns raw Redshift tables into tested, documented models using version-controlled SQL. Integration lets engineers modularize queries, run incremental pipelines, and manage schema changes through code.
Add a Redshift target in ~/.dbt/profiles.yml
. Provide host, port, user, password, dbname, and schema. Use iam_role
or cluster_id
for IAM auth. Verify the profile with dbt debug
.
Required: host
, port
(5439), user
, password
or AWS auth, dbname
, schema
, threads
, keepalives_idle
, connect_timeout
. Optional: sslmode
, search_path
, role
, ra3_node
.
Run dbt init ecommerce_warehouse
, choose Redshift, and point to the profile name. Commit generated files to Git. Execute dbt run
to build initial models.
Create models/orders_summary.sql
that joins Orders, Customers, and OrderItems. Mark it incremental so only new rows rebuild. Add tests and docs in YAML, then run dbt build
.
Use dbt Cloud, Airflow, or GitHub Actions to call dbt run
and dbt test
. Store logs in S3 or CloudWatch and alert failures via Slack.
Use incremental models, define proper DISTKEY
and SORTKEY
, prefer COPY
over INSERT
, cap concurrency with threads
, and schedule VACUUM
after large loads.
Avoid building models in the public
schema; use a dedicated analytics
schema. Never commit secrets to Git—load them via environment variables or AWS Secrets Manager.
Yes. Set method: iam
and cluster_id
or iam_profile
in the profile. dbt will obtain temporary credentials automatically.
Use merge_strategy='delete_insert'
in an incremental model or switch to dbt snapshots
for slowly changing dimensions.
Yes. Set create_schema: true
in dbt_project.yml
or enable it per-model with {{ config(create_schema=True) }}
.
Absolutely. Point external tables to Spectrum in your models and set external_location
configs. dbt will treat them like any other source.