Postgres设置
dbt-postgres
- 维护者: dbt Labs
- 作者: dbt Labs
- GitHub repo: dbt-labs/dbt-core
- PyPI package:
dbt-postgres - Slack channel: #db-postgres
- Supported dbt Core version: v0.4.0及以后
- dbt Cloud support: Supported
- Minimum data platform version: v0.4.0
安装dbt-postgres
pip安装是最简便的方式:
pip install dbt-postgres
安装 dbt-postgres同时会安装 dbt-core 以及其它依赖.
配置 dbt-postgres
Postgres专项配置请参考 Postgres配置
查看后期计划,请参考GitHub仓库: dbt-labs/dbt-core
Profile配置¶
Postgres targets应该在你的profiles.yml文件里遵循以下配置:
company-name:
target: dev
outputs:
dev:
type: postgres
host: [hostname]
user: [username]
password: [password]
port: [port]
dbname: [database name] # or database instead of dbname
schema: [dbt schema]
threads: [optional, 1 or more]
[keepalives_idle](#keepalives_idle): 0 # default 0, indicating the system default. See below
connect_timeout: 10 # default 10 seconds
[retries](#retries): 1 # default 1 retry on error/timeout when opening connections
[search_path](#search_path): [optional, override the default postgres search_path]
[role](#role): [optional, set the role dbt assumes when executing queries]
[sslmode](#sslmode): [optional, set the sslmode used to connect to the database]
配置¶
search_path¶
search_path配置控制dbt在打开数据库的新连接时配置的Postgres“搜索路径”。默认情况下,Postgres搜索路径为$user,public,这意味着将在public模式(schema)或与登录用户同名的模式中搜索表, **注意:**对于dbt的典型用法,不需要设置自定义值,建议将search_path设置为默认值。
role¶
role配置控制dbt在打开与数据库的新连接时所扮演的Postgres角色(v0.16.0增加)。
sslmode¶
sslmode配置控制dbt使用SSL连接Postgres数据库。参阅Postgres文档里的sslmode,如果没有设置,dbt将使用Postgres默认方式连接数据库。
keepalives_idle¶
如果数据库在dbt等待数据时关闭了连接,您可能会看到错误SSL SYSCALL error: EOF detected。降低keepalives_idle值可能会阻止这种情况的发生,因为服务器会频繁地发送ping以使连接保持活动状态。
dbt默认设置是 0, 但也可以设置成稍低一些(120或60秒),以节省网络开销.
retries¶
如果dbt-postgres在打开新连接时遇到操作错误或超时,它将重试retries配置的次数。默认值为1次重试。如果设置为2次以上重试,则dbt将等待1秒后重试。如果设置为0,则dbt根本不会重试。