Project: ClickHouse (App Definition and Development / Database)
File: constraints-on-settings.md

slug: /en/operations/settings/constraints-on-settings sidebar_position: 62 sidebar_label: Constraints on Settings 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. The constraints are defined as the following: ``` xml <profiles> <user_name> <constraints> <settingname1> <min>lower_boundary</min> </settingname1> <settingname2> <max>upper_boundary</max> </settingname2> <settingname3> <min>lower_boundary</min> <max>upper_boundary</max> </settingname3> <settingname4> <readonly/> </settingname4> <settingname5> <min>lower_boundary</min> <max>upper_boundary</max> <changeableinreadonly/> </settingname5> </constraints> </user_name> </profiles> ``` If the user tries to violate the constraints an exception is thrown and the setting isnt changed. There are supported few types of constraints: `min`, `max`, `readonly` (with alias `const`) and `changeableinreadonly`. The `min` and `max` constraints specify upper and lower boundaries for a numeric setting and can be used in combination. The `readonly` or `const` constraint specifies that the user cannot change the corresponding setting at all. The `changeableinreadonly` constraint type allows user to change the setting within `min`/`max` range even if `readonly` setting is set to 1, otherwise settings are not allow to be changed in `readonly=1` mode. Note that `changeableinreadonly` is supported only if `settingsconstraintsreplace_previous` is enabled: ``` xml <accesscontrolimprovements> <settingsconstraintsreplaceprevious>true</settingsconstraintsreplaceprevious> </accesscontrolimprovements> ``` If there are multiple profiles active for a user, then constraints are merged. Merge process depends on `settingsconstraintsreplace_previous`: true (recommended): constraints for the same setting are replaced during merge, such that the last constraint is used and all previous are ignored including fields that are not set in new constraint. false (default): constraints for the same setting are merged in a way that every not set type of constraint is taken from previous profile and every set type of constraint is replaced by value from new profile. Read-only mode is enabled by `readonly` setting (not to confuse with `readonly` constraint type): `readonly=0`: No read-only restrictions. `readonly=1`: Only read queries are allowed and settings cannot be changed unless `changeableinreadonly` is set. `readonly=2`: Only read queries are allowed, but settings can be changed, except for `readonly` setting itself. Example: Let `users.xml` includes lines: ``` xml <profiles> <default> <maxmemoryusage>10000000000</maxmemoryusage> <forceindexbydate>0</forceindexbydate> ... <constraints> <maxmemoryusage> <min>5000000000</min> <max>20000000000</max> </maxmemoryusage> <forceindexby_date> <readonly/> </forceindexby_date> </constraints> </default> </profiles> ``` The following queries all throw exceptions: ``` sql SET maxmemoryusage=20000000001; SET maxmemoryusage=4999999999; SET forceindexby_date=1; ``` ``` text Code: 452, e.displayText() = DB::Exception: Setting maxmemoryusage should not be greater than 20000000000. Code: 452, e.displayText() = DB::Exception: Setting maxmemoryusage should not be less than 5000000000. Code: 452, e.displayText() = DB::Exception: Setting forceindexby_date should not be changed. ``` 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 theyre overridden explicitly for these users. It is possible to set constraints for . These constraints are applied when table with merge tree engine is created or its storage settings are altered. Name of merge tree setting must be prepended by `mergetree` prefix when referenced in `<constraints>` section. Example: Forbid to create new tables with explicitly specified `storage_policy` ``` xml <profiles> <default> <constraints> <mergetreestorage_policy> <const/> </mergetreestorage_policy> </constraints> </default> </profiles> ```