> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# log_queries_* 会话设置

> ClickHouse 在 log_queries_* 生成分组中的会话设置。

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>类型</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>默认值</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          无需重启即可更改
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

这些设置可在 [system.settings](/docs/zh/reference/system-tables/settings) 中查看，并根据 [源代码](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) 自动生成。

<div id="log_queries">
  ## log\_queries
</div>

<SettingsInfoBlock type="Bool" default_value="1" />

启用查询日志记录。

发送到 ClickHouse 且启用此设置的查询，会按照 [query\_log](/docs/zh/reference/settings/server-settings/settings#query_log) 服务器配置参数中的规则记录。

示例：

```text theme={null}
log_queries=1
```

<div id="log_queries_cut_to_length">
  ## log\_queries\_cut\_to\_length
</div>

<SettingsInfoBlock type="UInt64" default_value="100000" />

如果查询长度超过指定阈值 (以字节为单位) ，则在写入 query log 时截断该查询。同时也会限制在普通文本日志中输出的查询长度。

<div id="log_queries_min_query_duration_ms">
  ## log\_queries\_min\_query\_duration\_ms
</div>

<SettingsInfoBlock type="Milliseconds" default_value="0" />

如果启用 (非零值) ，则耗时短于此设置值的查询不会被记录到日志中 (你可以将其视为 [MySQL Slow Query Log](https://dev.mysql.com/doc/refman/5.7/slow-query-log.html) 的 `long_query_time`) 。这也就意味着，你无法在以下表中找到这些查询：

* `system.query_log`
* `system.query_thread_log`

只有以下类型的查询才会被记录到日志中：

* `QUERY_FINISH`

* `EXCEPTION_WHILE_PROCESSING`

* Type: 毫秒

* Default value: 0 (任意查询)

<div id="log_queries_min_type">
  ## log\_queries\_min\_type
</div>

<SettingsInfoBlock type="LogQueriesType" default_value="QUERY_START" />

记录到 `query_log` 的最小类型。

可能的值：

* `QUERY_START` (`=1`)
* `QUERY_FINISH` (`=2`)
* `EXCEPTION_BEFORE_START` (`=3`)
* `EXCEPTION_WHILE_PROCESSING` (`=4`)

可用于限制哪些条目会写入 `query_log`。例如，如果你只关注错误，则可以使用 `EXCEPTION_WHILE_PROCESSING`：

```text theme={null}
log_queries_min_type='EXCEPTION_WHILE_PROCESSING'
```

<div id="log_queries_probability">
  ## log\_queries\_probability
</div>

<SettingsInfoBlock type="Float" default_value="1" />

允许用户仅按指定概率，随机选择部分查询并将其写入 [query\_log](/docs/zh/reference/system-tables/query_log)、[query\_thread\_log](/docs/zh/reference/system-tables/query_thread_log) 和 [query\_views\_log](/docs/zh/reference/system-tables/query_views_log) 系统表。这有助于在每秒查询量很大时降低负载。

可能的值：

* 0 — 查询不会记录到系统表中。
* 范围在 \[0..1] 内的正浮点数。例如，如果该设置的值为 `0.5`，则大约一半的查询会记录到系统表中。
* 1 — 所有查询都会记录到系统表中。
