Day 2: Configuring dbt Profile¶
Postgres Profile¶
profiles.yml¶
~/.dbt/profiles.yml
postgres_at_my_company:
target: dev
outputs:
dev:
type: postgres
user: postgres
password: xxx
database: postgres
schema: postgres
host: localhost
port: 5432
dbt_project.yml¶
dbt_project.yml
name: 'dbt_postgres_demo'
config-version: 2
version: 1.0.0
profile: 'postgres_at_my_company'
require-dbt-version: ">=1.1.1"
Start Postgres¶
Docker official image of PostgreSQL
docker run \
-d \
--rm \
--name postgres \
-e POSTGRES_PASSWORD=xxx \
-p "5432:5432" \
postgres
$ docker exec -it postgres psql -U postgres
psql (14.4 (Debian 14.4-1.pgdg110+1))
Type "help" for help.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=# \dn+
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(1 row)
dbt debug¶
Use dbt debug to validate warehouse credentials
$ dbt debug --config-dir
To view your profiles.yml file, run:
open /Users/jacek/.dbt
$ dbt debug
dbt version: 1.1.1
python version: 3.9.13
python path: /Users/jacek/.pyenv/versions/dbt/bin/python3.9
os info: macOS-11.6.6-x86_64-i386-64bit
Using profiles.yml file at /Users/jacek/.dbt/profiles.yml
Using dbt_project.yml file at /Users/jacek/dev/sandbox/dbt-sandbox/dbt_project.yml
Configuration:
profiles.yml file [OK found and valid]
dbt_project.yml file [OK found and valid]
Required dependencies:
- git [OK found]
Connection:
host: localhost
port: 5432
user: postgres
database: postgres
schema: postgres
search_path: None
keepalives_idle: 0
sslmode: None
Connection test: [OK connection ok]
All checks passed!
dbt run¶
models/nums.sql
SELECT *
FROM (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (num,letter)
$ dbt run
Found 1 model, 0 tests, 0 snapshots, 0 analyses, 167 macros, 0 operations, 0 seed files, 0 sources, 0 exposures, 0 metrics
Concurrency: 1 threads (target='dev')
1 of 1 START view model postgres.nums .......................................... [RUN]
1 of 1 OK created view model postgres.nums ..................................... [CREATE VIEW in 0.06s]
Finished running 1 view model in 0.16s.
Completed successfully
Done. PASS=1 WARN=0 ERROR=0 SKIP=0 TOTAL=1