> ## 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.

# alter_* 会话设置

> ClickHouse alter_* 生成组中的会话设置。

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="alter_move_to_space_execute_async">
  ## alter\_move\_to\_space\_execute\_async
</div>

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

以异步方式执行 ALTER TABLE MOVE ... TO \[DISK|VOLUME]

<div id="alter_partition_verbose_result">
  ## alter\_partition\_verbose\_result
</div>

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

启用或禁用显示已成功应用于分区和 parts 的操作所涉及的 parts 信息。
适用于 [ATTACH PARTITION|PART](/docs/zh/reference/statements/alter/partition#attach-partitionpart) 和 [FREEZE PARTITION](/docs/zh/reference/statements/alter/partition#freeze-partition)。

可能的值：

* 0 — 禁用详细输出。
* 1 — 启用详细输出。

**示例**

```sql theme={null}
CREATE TABLE test(a Int64, d Date, s String) ENGINE = MergeTree PARTITION BY toYYYYMDECLARE(d) ORDER BY a;
INSERT INTO test VALUES(1, '2021-01-01', '');
INSERT INTO test VALUES(1, '2021-01-01', '');
ALTER TABLE test DETACH PARTITION ID '202101';

ALTER TABLE test ATTACH PARTITION ID '202101' SETTINGS alter_partition_verbose_result = 1;

┌─command_type─────┬─partition_id─┬─part_name────┬─old_part_name─┐
│ ATTACH PARTITION │ 202101       │ 202101_7_7_0 │ 202101_5_5_0  │
│ ATTACH PARTITION │ 202101       │ 202101_8_8_0 │ 202101_6_6_0  │
└──────────────────┴──────────────┴──────────────┴───────────────┘

ALTER TABLE test FREEZE SETTINGS alter_partition_verbose_result = 1;

┌─command_type─┬─partition_id─┬─part_name────┬─backup_name─┬─backup_path───────────────────┬─part_backup_path────────────────────────────────────────────┐
│ FREEZE ALL   │ 202101       │ 202101_7_7_0 │ 8           │ /var/lib/clickhouse/shadow/8/ │ /var/lib/clickhouse/shadow/8/data/default/test/202101_7_7_0 │
│ FREEZE ALL   │ 202101       │ 202101_8_8_0 │ 8           │ /var/lib/clickhouse/shadow/8/ │ /var/lib/clickhouse/shadow/8/data/default/test/202101_8_8_0 │
└──────────────┴──────────────┴──────────────┴─────────────┴───────────────────────────────┴─────────────────────────────────────────────────────────────┘
```

<div id="alter_sync">
  ## alter\_sync
</div>

**别名**: `replication_alter_partitions_sync`

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

用于指定由 [`ALTER`](/docs/zh/reference/statements/alter/index)、[`OPTIMIZE`](/docs/zh/reference/statements/optimize) 或 [`TRUNCATE`](/docs/zh/reference/statements/truncate) 查询触发、并在副本上执行的操作的等待行为。

可能的值：

* `0` — 不等待。
* `1` — 等待本副本执行完成。
* `2` — 等待所有副本完成。
* `3` - 仅等待活跃副本。

Cloud 默认值：`0`。

<Note>
  `alter_sync` 仅适用于 `Replicated` 和 `SharedMergeTree` 表；对非 `Replicated` 或 `Shared` 表执行 alter 时，此设置不起作用。
</Note>

<div id="alter_update_mode">
  ## alter\_update\_mode
</div>

<SettingsInfoBlock type="AlterUpdateMode" default_value="heavy" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.5"},{"label": "heavy"},{"label": "新增设置"}]}]} />

用于带有 `UPDATE` 命令的 `ALTER` 查询的模式。

可能的值：

* `heavy` - 执行常规变更。
* `lightweight` - 如果可以，则执行轻量级更新；否则执行常规变更。
* `lightweight_force` - 如果可以，则执行轻量级更新；否则抛出异常。
