Server Settings

Maximum size of the query condition cache.

Note

This setting can be modified at runtime and will take effect immediately.

## query\_condition\_cache\_size\_ratio[​](#query_condition_cache_size_ratio "Direct link to query_condition_cache_size_ratio")

The size of the protected queue (in case of SLRU policy) in the query condition cache relative to the cache's total size.

## query\_log[​](#query_log "Direct link to query_log")

Setting for logging queries received with the [log\_queries=1](/docs/operations/settings/settings) setting.

Queries are logged in the [system.query\_log](/docs/operations/system-tables/query_log) table, not in a separate file. You can change the name of the table in the `table` parameter (see below).

The following settings can be configured by sub-tags:

|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Setting Description Default Note|  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `database` Name of the database. |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `table` Name of the system table. |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `engine` [MergeTree Engine Definition](/docs/engines/table-engines/mergetree-family/mergetree#table_engine-mergetree-creating-a-table) for a system table. Cannot be used if `partition_by` or `order_by` defined. If not specified `MergeTree` is selected by default| `partition_by` [Custom partitioning key](/docs/engines/table-engines/mergetree-family/custom-partitioning-key) for a system table. If `engine` is specified for system table, `partition_by` parameter should be specified directly inside 'engine'| `ttl` Specifies the table [TTL](/docs/engines/table-engines/mergetree-family/mergetree#table_engine-mergetree-ttl). If `engine` is specified for system table, `ttl` parameter should be specified directly inside 'engine'| `order_by` [Custom sorting key](/docs/engines/table-engines/mergetree-family/mergetree#order_by) for a system table. Can't be used if `engine` defined. If `engine` is specified for system table, `order_by` parameter should be specified directly inside 'engine'| `storage_policy` Name of the storage policy to use for the table (optional). If `engine` is specified for system table, `storage_policy` parameter should be specified directly inside 'engine'| `settings` [Additional parameters](/docs/engines/table-engines/mergetree-family/mergetree#settings) that control the behavior of the MergeTree (optional). If `engine` is specified for system table, `settings` parameter should be specified directly inside 'engine'| `flush_interval_milliseconds` Interval for flushing data from the buffer in memory to the table. `7500` |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `max_size_rows` Maximal size in lines for the logs. When the amount of non-flushed logs reaches the max\_size, logs are dumped to the disk. `1048576` |  |  |  |  |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `reserved_size_rows` Pre-allocated memory size in lines for the logs. `8192` |  |  |  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | --- | --- | | `buffer_size_rows_flush_threshold` Threshold for amount of lines. If the threshold is reached, flushing logs to the disk is launched in background. `max_size_rows / 2` |  |  |  |  | | --- | --- | --- | --- | | `flush_on_crash` Sets whether logs should be dumped to the disk in case of a crash. `false`  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

If the table does not exist, ClickHouse will create it. If the structure of the query log changed when the ClickHouse server was updated, the table with the old structure is renamed, and a new table is created automatically.

**Example**

```
<query_log>
    <database>system</database>
    <table>query_log</table>
    <engine>Engine = MergeTree PARTITION BY event_date ORDER BY event_time TTL event_date + INTERVAL 30 day</engine>
    <flush_interval_milliseconds>7500</flush_interval_milliseconds>
    <max_size_rows>1048576</max_size_rows>
    <reserved_size_rows>8192</reserved_size_rows>
    <buffer_size_rows_flush_threshold>524288</buffer_size_rows_flush_threshold>
    <flush_on_crash>false</flush_on_crash>
</query_log>
```

## query\_masking\_rules[​](#query_masking_rules "Direct link to query_masking_rules")

Regexp-based rules, which will be applied to queries as well as all log messages before storing them in server logs,
[`system.query_log`](/docs/operations/system-tables/query_log), [`system.text_log`](/docs/operations/system-tables/text_log), [`system.processes`](/docs/operations/system-tables/processes) tables, and in logs sent to the client. That allows preventing
sensitive data leakage from SQL queries such as names, emails, personal identifiers or credit card numbers to logs.

**Example**

```
<query_masking_rules>
    <rule>
        <name>hide SSN</name>
        <regexp>(^|\D)\d{3}-\d{2}-\d{4}($|\D)</regexp>
        <replace>000-00-0000</replace>
    </rule>
</query_masking_rules>
```

**Config fields**:

|  |  |  |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Setting Description|  |  |  |  |  |  | | --- | --- | --- | --- | --- | --- | | `name` name for the rule (optional)|  |  |  |  | | --- | --- | --- | --- | | `regexp` RE2 compatible regular expression (mandatory)|  |  | | --- | --- | | `replace` substitution string for sensitive data (optional, by default - six asterisks) | | | | | | | |

The masking rules are applied to the whole query (to prevent leaks of sensitive data from malformed / non-parseable queries).

The [`system.events`](/docs/operations/system-tables/events) table has counter `QueryMaskingRulesMatch` which has an overall number of query masking rules matches.

For distributed queries each server has to be configured separately, otherwise, subqueries passed to other
nodes will be stored without masking.

## query\_metric\_log[​](#query_metric_log "Direct link to query_metric_log")

It is disabled by default.

**Enabling**

To manually turn on metrics history collection [`system.query_metric_log`](/docs/operations/system-tables/query_metric_log), create `/etc/clickhouse-server/config.d/query_metric_log.xml` with the following content: