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

# max_memory_usage_* セッション設定

> max_memory_usage_* グループに含まれる ClickHouse のセッション設定。

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/ja/reference/system-tables/settings) で確認でき、[ソースコード](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) から自動生成されています。

<div id="max_memory_usage">
  ## max\_memory\_usage
</div>

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

Cloud でのデフォルト値: レプリカ上の RAM の量によって異なります。

1 台のサーバーでクエリを実行する際に使用される RAM の最大量です。
値が `0` の場合は無制限を意味します。

この設定では、利用可能なメモリ量やマシン全体の総メモリ量は考慮されません。
この制限は、1 台のサーバー内の 1 つのクエリに適用されます。

`SHOW PROCESSLIST` を使用すると、各クエリの現在のメモリ消費量を確認できます。
ピーク時のメモリ消費量は各クエリごとに追跡され、ログに書き込まれます。

`String` および `Array` 引数を持つ以下の aggregate functions の集約状態については、
メモリ使用量は完全には追跡されません。

* `min`
* `max`
* `any`
* `anyLast`
* `argMin`
* `argMax`

メモリ消費量は、[`max_memory_usage_for_user`](/docs/ja/reference/settings/session-settings/max-memory-usage#max_memory_usage_for_user)
および [`max_server_memory_usage`](/docs/ja/reference/settings/server-settings/settings#max_server_memory_usage) の
parameter によっても制限されます。

<div id="max_memory_usage_for_user">
  ## max\_memory\_usage\_for\_user
</div>

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

単一のサーバー上で、あるユーザーのクエリ実行に使用できるRAMの最大量です。0 は無制限を意味します。

デフォルトでは、この値に制限はありません (`max_memory_usage_for_user = 0`) 。

[`max_memory_usage`](/docs/ja/reference/settings/session-settings/max-memory-usage#max_memory_usage) の説明もあわせて参照してください。

たとえば、`clickhouse_read` という名前のユーザーに対して `max_memory_usage_for_user` を 1000 バイトに設定するには、次のステートメントを使用できます

```sql theme={null}
ALTER USER clickhouse_read SETTINGS max_memory_usage_for_user = 1000;
```

クライアントからログアウトして再度ログインし、`getSetting` 関数を使用すると、正しく反映されたことを確認できます。

```sql theme={null}
SELECT getSetting('max_memory_usage_for_user');
```
