安装

1
  pip install dbt-postgres -i https://pypi.doubanio.com/simple

Install with pip | dbt Developer Hub

项目初始化

dbt init 创建项目

编辑profiles

profiles.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mydb:
  outputs:
    # 开发环境
    dev:
      type: postgres
      threads: 1
      host:
      port: 5432
      user:
      pass:
      dbname: test
      schema: 'dev'

    # 正式环境
    prod:
      type: postgres
      threads: 1
      host:
      port: 5432
      user:
      pass:
      dbname: test
      schema: 'prod'

  target: prod



常用命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  # 初始化一个项目
  dbt init

  # 安装依赖的package,如果有的话
  dbt deps

  # 启动
  dbt run

  # 生成数据文档
  dbt docs generate

  # 将数据文档作为网页打开
  dbt docs serve

  # 配置数据库参数
  dbt debug –config-dir

  # 测试数据库连接
  dbt debug

  # 运行指定模型
  dbt run -s models.sql