跳转到主内容
跳转到主内容

PostgreSQL 字典源

设置示例:

SOURCE(POSTGRESQL(
    port 5432
    host 'postgresql-hostname'
    user 'postgres_user'
    password 'postgres_password'
    db 'db_name'
    table 'table_name'
    replica(host 'example01-1' port 5432 priority 1)
    replica(host 'example01-2' port 5432 priority 2)
    where 'id=10'
    invalidate_query 'SQL_QUERY'
    query 'SELECT id, value_1, value_2 FROM db_name.table_name'
))

设置字段:

SettingDescription
hostPostgreSQL 服务器上的主机地址。可为所有副本统一指定,或者为每个副本单独指定(在 <replica> 内)。
portPostgreSQL 服务器上的端口。可为所有副本统一指定,或者为每个副本单独指定(在 <replica> 内)。
userPostgreSQL 用户名。可为所有副本统一指定,或者为每个副本单独指定(在 <replica> 内)。
passwordPostgreSQL 用户的密码。可为所有副本统一指定,或者为每个副本单独指定(在 <replica> 内)。
replica副本配置部分。可以包含多个此类部分。
replica/hostPostgreSQL 主机地址。
replica/portPostgreSQL 端口。
replica/priority副本优先级。尝试连接时,ClickHouse 会按优先级顺序遍历副本。数字越小,优先级越高。
db数据库名称。
table表名称。
where选择条件。条件语法与 PostgreSQL 中 WHERE 子句相同。例如,id > 10 AND id < 20。可选。
invalidate_query用于检查字典状态的查询。可选。详情参见章节 使用 LIFETIME 刷新字典数据
background_reconnect当连接失败时在后台重新连接到副本。可选。
query自定义查询。可选。
注意

tablewhere 字段不能与 query 字段同时使用,并且必须声明 tablequery 字段中的一个。