Configuration Files

ClickHouse supports multi-file configuration management. The main server configuration file is /etc/clickhouse-server/config.xml or /etc/clickhouse-server/config.yaml. Other files must be in the /etc/clickhouse-server/config.d directory. Note, that any configuration file can be written either in XML or YAML, but mixing formats in one file is not supported. For example, you can have main configs as config.xml and users.xml and write additional files in config.d and users.d directories in .yaml.

All XML files should have the same root element, usually <yandex>. As for YAML, yandex: should not be present, the parser will insert it automatically.

Override

Some settings specified in the main configuration file can be overridden in other configuration files:

  • The replace or remove attributes can be specified for the elements of these configuration files.
  • If neither is specified, it combines the contents of elements recursively, replacing values of duplicate children.
  • If replace is specified, it replaces the entire element with the specified one.
  • If remove is specified, it deletes the element.

You can also declare attributes as coming from environment variables by using from_env="VARIABLE_NAME":

  1. <yandex>
  2. <macros>
  3. <replica from_env="REPLICA" />
  4. <layer from_env="LAYER" />
  5. <shard from_env="SHARD" />
  6. </macros>
  7. </yandex>

Substitution

The config can also define “substitutions”. If an element has the incl attribute, the corresponding substitution from the file will be used as the value. By default, the path to the file with substitutions is /etc/metrika.xml. This can be changed in the include_from element in the server config. The substitution values are specified in /yandex/substitution_name elements in this file. If a substitution specified in incl does not exist, it is recorded in the log. To prevent ClickHouse from logging missing substitutions, specify the optional="true" attribute (for example, settings for macros).

If you want to replace an entire element with a substitution use include as element name.

XML substitution example:

  1. <yandex>
  2. <!-- Appends XML subtree found at `/profiles-in-zookeeper` ZK path to `<profiles>` element. -->
  3. <profiles from_zk="/profiles-in-zookeeper" />
  4. <users>
  5. <!-- Replaces `include` element with the subtree found at `/users-in-zookeeper` ZK path. -->
  6. <include from_zk="/users-in-zookeeper" />
  7. <include from_zk="/other-users-in-zookeeper" />
  8. </users>
  9. </yandex>

Substitutions can also be performed from ZooKeeper. To do this, specify the attribute from_zk = "/path/to/node". The element value is replaced with the contents of the node at /path/to/node in ZooKeeper. You can also put an entire XML subtree on the ZooKeeper node and it will be fully inserted into the source element.

User Settings

The config.xml file can specify a separate config with user settings, profiles, and quotas. The relative path to this config is set in the users_config element. By default, it is users.xml. If users_config is omitted, the user settings, profiles, and quotas are specified directly in config.xml.

Users configuration can be splitted into separate files similar to config.xml and config.d/.
Directory name is defined as users_config setting without .xml postfix concatenated with .d.
Directory users.d is used by default, as users_config defaults to users.xml.

Note that configuration files are first merged taking into account Override settings and includes are processed after that.

XML example

For example, you can have separate config file for each user like this:

  1. $ cat /etc/clickhouse-server/users.d/alice.xml
  1. <yandex>
  2. <users>
  3. <alice>
  4. <profile>analytics</profile>
  5. <networks>
  6. <ip>::/0</ip>
  7. </networks>
  8. <password_sha256_hex>...</password_sha256_hex>
  9. <quota>analytics</quota>
  10. </alice>
  11. </users>
  12. </yandex>

YAML examples

Here you can see default config written in YAML: config.yaml.example.

There are some differences between YAML and XML formats in terms of ClickHouse configurations. Here are some tips for writing a configuration in YAML format.

You should use a Scalar node to write a key-value pair:

  1. key: value

To create a node, containing other nodes you should use a Map:

  1. map_key:
  2. key1: val1
  3. key2: val2
  4. key3: val3

To create a list of values or nodes assigned to one tag you should use a Sequence:

  1. seq_key:
  2. - val1
  3. - val2
  4. - key1: val3
  5. - map:
  6. key2: val4
  7. key3: val5

If you want to write an attribute for a Sequence or Map node, you should use a @ prefix before the attribute key. Note, that @ is reserved by YAML standard, so you should also to wrap it into double quotes:

  1. map:
  2. "@attr1": value1
  3. "@attr2": value2
  4. key: 123

From that Map we will get these XML nodes:

  1. <map attr1="value1" attr2="value2">
  2. <key>123</key>
  3. </map>

You can also set attributes for Sequence:

  1. seq:
  2. - "@attr1": value1
  3. - "@attr2": value2
  4. - 123
  5. - abc

So, we can get YAML config equal to this XML one:

  1. <seq attr1="value1" attr2="value2">123</seq>
  2. <seq attr1="value1" attr2="value2">abc</seq>

Implementation Details

For each config file, the server also generates file-preprocessed.xml files when starting. These files contain all the completed substitutions and overrides, and they are intended for informational use. If ZooKeeper substitutions were used in the config files but ZooKeeper is not available on the server start, the server loads the configuration from the preprocessed file.

The server tracks changes in config files, as well as files and ZooKeeper nodes that were used when performing substitutions and overrides, and reloads the settings for users and clusters on the fly. This means that you can modify the cluster, users, and their settings without restarting the server.