Environment management helps keep your work organized and safe. It separates your development, testing, and live data so you don't mix them up.
Environment management (dev, staging, prod) in dbt
profiles.yml
my_profile:
target: dev
outputs:
dev:
type: postgres
host: localhost
user: user_dev
password: pass_dev
dbname: mydb_dev
schema: dev_schema
staging:
type: postgres
host: staging_host
user: user_staging
password: pass_staging
dbname: mydb_staging
schema: staging_schema
prod:
type: postgres
host: prod_host
user: user_prod
password: pass_prod
dbname: mydb_prod
schema: prod_schemaThe profiles.yml file defines connection details for each environment.
You switch environments by changing the target in your profile or using the --target flag when running dbt commands.
dbt run --target dev
dbt run --target staging
dbt run --target prod
This example shows how to run dbt commands in different environments using the --target flag. Each environment uses its own database and schema to keep data separate.
# profiles.yml example # Define three environments: dev, staging, prod # Run dbt in dev environment !dbt run --target dev # Run dbt in staging environment !dbt run --target staging # Run dbt in prod environment !dbt run --target prod
Always test your changes in dev or staging before running in prod.
Keep your credentials safe and do not share production passwords.
You can automate environment switching in CI/CD pipelines for smooth deployments.
Environment management separates your work into dev, staging, and prod.
Use profiles.yml to set connection details for each environment.
Switch environments easily with the --target flag when running dbt commands.