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

# How to configure settings for a user in ClickHouse

> Learn how to define settings in ClickHouse for individual queries, client sessions, or specific users using `SET` and `ALTER USER` commands.

{frontMatter.description}

<h2 id="introduction">
  Introduction
</h2>

There are several ways to define a setting for a user in ClickHouse, depending on the use case and how long you want the setting to be configured. Let's look at a few scenarios...

<h2 id="configure-a-setting-for-a-single-query">
  Configure a setting for a single query
</h2>

A `SELECT` query can contain a `SETTINGS` clause where you can define any number of settings. The settings are only applied for that particular query. For example:

```sql theme={null}
SELECT *
FROM my_table
SETTINGS max_threads = 8;
```

The maximum number of threads will be 8 for this particular query.

<h2 id="configure-a-setting-for-a-session">
  Configure a setting for a session
</h2>

You can define a setting for the lifetime of a client session using a `SET` clause. This is handy for ad-hoc testing or for when you want a setting to live for the lifetime of a few queries - but not longer.

```sql theme={null}
SET max_threads = 8;

SELECT *
FROM my_table;
```

<h2 id="configure-a-setting-for-a-particular-user">
  Configure a setting for a particular user
</h2>

Use `ALTER USER` to define a setting just for one user. For example:

```sql theme={null}
ALTER USER my_user_name SETTINGS max_threads = 8;
```

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_threads');
```

<Note>
  Specifying the settings this way will overwrite the current settings of the user i.e if you had other settings applied to the user but did not specify them in the `ALTER USER` statement, they will be lost.

  If you want to retain your settings use the `ALTER USER ... MODIFY SETTING ...` instead
</Note>
