Help wanted!

The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.

Help ClickHouse documentation by editing this page

对设置的限制

在设置的约束可以在定义 profiles 一节 user.xml 配置文件,并禁止用户更改一些设置与 SET 查询。
约束定义如下:

  1. <profiles>
  2. <user_name>
  3. <constraints>
  4. <setting_name_1>
  5. <min>lower_boundary</min>
  6. </setting_name_1>
  7. <setting_name_2>
  8. <max>upper_boundary</max>
  9. </setting_name_2>
  10. <setting_name_3>
  11. <min>lower_boundary</min>
  12. <max>upper_boundary</max>
  13. </setting_name_3>
  14. <setting_name_4>
  15. <readonly/>
  16. </setting_name_4>
  17. </constraints>
  18. </user_name>
  19. </profiles>

如果用户试图违反约束,将引发异常,并且设置不会更改。
支持三种类型的约束: min, max, readonly. 该 minmax 约束指定数值设置的上边界和下边界,并且可以组合使用。 该 readonly constraint指定用户根本无法更改相应的设置。

示例:users.xml 包括行:

  1. <profiles>
  2. <default>
  3. <max_memory_usage>10000000000</max_memory_usage>
  4. <force_index_by_date>0</force_index_by_date>
  5. ...
  6. <constraints>
  7. <max_memory_usage>
  8. <min>5000000000</min>
  9. <max>20000000000</max>
  10. </max_memory_usage>
  11. <force_index_by_date>
  12. <readonly/>
  13. </force_index_by_date>
  14. </constraints>
  15. </default>
  16. </profiles>

以下查询都会引发异常:

  1. SET max_memory_usage=20000000001;
  2. SET max_memory_usage=4999999999;
  3. SET force_index_by_date=1;
  1. Code: 452, e.displayText() = DB::Exception: Setting max_memory_usage should not be greater than 20000000000.
  2. Code: 452, e.displayText() = DB::Exception: Setting max_memory_usage should not be less than 5000000000.
  3. Code: 452, e.displayText() = DB::Exception: Setting force_index_by_date should not be changed.

注:default 配置文件具有特殊的处理:所有定义的约束 default 配置文件成为默认约束,因此它们限制所有用户,直到为这些用户显式复盖它们。

原始文章