2020-04-03 13:23:32 +00:00
---
2022-04-09 13:29:05 +00:00
sidebar_position: 62
sidebar_label: Constraints on Settings
2020-04-03 13:23:32 +00:00
---
2022-06-02 10:55:18 +00:00
# Constraints on Settings
2019-06-10 18:38:03 +00:00
2020-02-26 15:07:23 +00:00
The constraints on settings can be defined in the `profiles` section of the `user.xml` configuration file and prohibit users from changing some of the settings with the `SET` query.
2020-03-19 08:31:06 +00:00
The constraints are defined as the following:
2019-06-10 18:38:03 +00:00
2020-03-20 10:10:48 +00:00
``` xml
2019-06-10 18:38:03 +00:00
< profiles >
< user_name >
< constraints >
< setting_name_1 >
< min > lower_boundary< / min >
< / setting_name_1 >
< setting_name_2 >
< max > upper_boundary< / max >
< / setting_name_2 >
< setting_name_3 >
< min > lower_boundary< / min >
< max > upper_boundary< / max >
< / setting_name_3 >
< setting_name_4 >
< readonly / >
< / setting_name_4 >
< / constraints >
< / user_name >
< / profiles >
```
2020-03-20 10:10:48 +00:00
If the user tries to violate the constraints an exception is thrown and the setting isn’ t changed.
2020-03-19 08:31:06 +00:00
There are supported three types of constraints: `min` , `max` , `readonly` . The `min` and `max` constraints specify upper and lower boundaries for a numeric setting and can be used in combination. The `readonly` constraint specifies that the user cannot change the corresponding setting at all.
2019-06-10 18:38:03 +00:00
**Example:** Let `users.xml` includes lines:
2020-03-20 10:10:48 +00:00
``` xml
2019-06-10 18:38:03 +00:00
< profiles >
< default >
< max_memory_usage > 10000000000< / max_memory_usage >
< force_index_by_date > 0< / force_index_by_date >
...
< constraints >
< max_memory_usage >
< min > 5000000000< / min >
< max > 20000000000< / max >
< / max_memory_usage >
< force_index_by_date >
< readonly / >
< / force_index_by_date >
< / constraints >
< / default >
< / profiles >
```
The following queries all throw exceptions:
2020-03-20 10:10:48 +00:00
``` sql
2019-06-10 18:38:03 +00:00
SET max_memory_usage=20000000001;
SET max_memory_usage=4999999999;
SET force_index_by_date=1;
```
2020-03-20 10:10:48 +00:00
``` text
2019-06-10 18:38:03 +00:00
Code: 452, e.displayText() = DB::Exception: Setting max_memory_usage should not be greater than 20000000000.
Code: 452, e.displayText() = DB::Exception: Setting max_memory_usage should not be less than 5000000000.
Code: 452, e.displayText() = DB::Exception: Setting force_index_by_date should not be changed.
```
2020-03-20 10:10:48 +00:00
**Note:** the `default` profile has special handling: all the constraints defined for the `default` profile become the default constraints, so they restrict all the users until they’ re overridden explicitly for these users.
2019-06-10 18:38:03 +00:00
2021-09-19 20:05:54 +00:00
[Original article ](https://clickhouse.com/docs/en/operations/settings/constraints_on_settings/ ) <!--hide-->