> ## 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_* session settings

> ClickHouse session settings in the max_memory_usage_* generated group.

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
  }}>Type</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>Default</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          Changeable without restart
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

These settings are available in [system.settings](/docs/reference/system-tables/settings) and are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).

<h2 id="max_memory_usage">
  max\_memory\_usage
</h2>

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

Cloud default value: depends on the amount of RAM on the replica.

The maximum amount of RAM to use for running a query on a single server.
A value of `0` means unlimited.

This setting does not consider the volume of available memory or the total volume
of memory on the machine. The restriction applies to a single query within a
single server.

You can use `SHOW PROCESSLIST` to see the current memory consumption for each query.
Peak memory consumption is tracked for each query and written to the log.

Memory usage is not fully tracked for states of the following aggregate functions
from `String` and `Array` arguments:

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

Memory consumption is also restricted by the parameters [`max_memory_usage_for_user`](/docs/reference/settings/session-settings/max-memory-usage#max_memory_usage_for_user)
and [`max_server_memory_usage`](/docs/reference/settings/server-settings/settings#max_server_memory_usage).

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

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

The maximum amount of RAM to use for running a user's queries on a single server. Zero means unlimited.

By default, the amount is not restricted (`max_memory_usage_for_user = 0`).

Also see the description of [`max_memory_usage`](/docs/reference/settings/session-settings/max-memory-usage#max_memory_usage).

For example if you want to set `max_memory_usage_for_user` to 1000 bytes for a user named `clickhouse_read`, you can use the statement

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

You can verify it worked by logging out of your client, logging back in, then use the `getSetting` function:

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