Skip to main content
Skip to main content

PostgreSQL dictionary source

Example of settings:

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'
))

Setting fields:

SettingDescription
hostThe host on the PostgreSQL server. You can specify it for all replicas, or for each one individually (inside <replica>).
portThe port on the PostgreSQL server. You can specify it for all replicas, or for each one individually (inside <replica>).
userName of the PostgreSQL user. You can specify it for all replicas, or for each one individually (inside <replica>).
passwordPassword of the PostgreSQL user. You can specify it for all replicas, or for each one individually (inside <replica>).
replicaSection of replica configurations. There can be multiple sections.
replica/hostThe PostgreSQL host.
replica/portThe PostgreSQL port.
replica/priorityThe replica priority. When attempting to connect, ClickHouse traverses the replicas in order of priority. The lower the number, the higher the priority.
dbName of the database.
tableName of the table.
whereThe selection criteria. The syntax for conditions is the same as for WHERE clause in PostgreSQL. For example, id > 10 AND id < 20. Optional.
invalidate_queryQuery for checking the dictionary status. Optional. Read more in the section Refreshing dictionary data using LIFETIME.
background_reconnectReconnect to replica in background if connection fails. Optional.
queryThe custom query. Optional.
Note

The table or where fields cannot be used together with the query field. And either one of the table or query fields must be declared.