Has dbt moved to reading .env files by default? I can find this, and a link therein but it’s not very conclusive.
The story goes:
I’d switched connection info from “postgres_hosting_service” to 127.0.0.1.
dbt debug --connection
clearly indicated what profile file it’s reading, but printed the old host as part of the connection info. The profile.yml file in question is clearly templated to pick the info up from env vars, and the env var PSQLHOST is clearly localhost. dbt appeared to be hanging on to old information.
$ poetry run dbt debug --connection
20:49:42 Running with dbt=1.8.8
20:49:42 dbt version: 1.8.8
20:49:42 python version: 3.12.7
20:49:42 python path: /home/user/path_to_proj_dir/.venv/bin/python
20:49:42 os info: Linux-5.15.0-125-generic-x86_64-with-glibc2.31
20:49:42 Using profiles dir at /home/user/path_to_proj_dir/proj
20:49:42 Using profiles.yml file at /home/user/path_to_proj_dir/proj/profiles.yml
20:49:42 Using dbt_project.yml file at /home/user/path_to_proj_dir/proj/dbt_project.yml
20:49:42 adapter type: postgres
20:49:42 adapter version: 1.8.2
20:49:42 Skipping steps before connection verification
20:49:42 Connection:
20:49:42 host: postgres_hosting_service
20:49:42 port: 5432
20:49:42 user: user
20:49:42 database: proj
20:49:42 schema: dev
20:49:42 connect_timeout: 300
20:49:42 role: None
20:49:42 search_path: None
20:49:42 keepalives_idle: 5
20:49:42 sslmode: require
20:49:42 sslcert: None
20:49:42 sslkey: None
20:49:42 sslrootcert: None
20:49:42 application_name: dbt
20:49:42 retries: 3
20:49:42 Registered adapter: postgres=1.8.2
20:49:43 Connection test: [OK connection ok]
20:49:43 All checks passed!
$ cat /home/user/path_to_proj_dir/proj/profiles.yml
proj:
outputs:
dev:
type: postgres
threads: 1
host: "{{ env_var('PSQLHOST') }}"
port: "{{ env_var('PSQLPORT') | int }}"
user: "{{ env_var('PSQLUSER') }}"
pass: "{{ env_var('PSQLPASSWORD') }}"
dbname: "{{ env_var('PSQLDBNAME') }}"
schema: dev
connect_timeout: 300
keepalives_idle: 5
retries: 3
sslmode: require
prod:
type: postgres
threads: 1
host: "{{ env_var('PSQLHOST') }}"
port: "{{ env_var('PSQLPORT') | int }}"
user: "{{ env_var('PSQLUSER') }}"
pass: "{{ env_var('PSQLPASSWORD') }}"
dbname: "{{ env_var('PSQLDBNAME') }}"
schema: prod
target: dev
$ echo $PSQLHOST
127.0.0.1
It turns out I have a .env file two directories above this one, with the “postgres_hosting_service” info in it. When I change it to localhost, it gets reflected in dbt debug --connection
.
I cannot find this documented anywhere. Is this new, or have I really never coincidentally had a .env file in the directories above in all the years I’ve been using dbt profiles this way?