跳至主要内容

CREATE QUOTA

创建可以分配给用户或角色的配额

语法

CREATE QUOTA [IF NOT EXISTS | OR REPLACE] name [ON CLUSTER cluster_name]
[IN access_storage_type]
[KEYED BY {user_name | ip_address | client_key | client_key,user_name | client_key,ip_address} | NOT KEYED]
[FOR [RANDOMIZED] INTERVAL number {second | minute | hour | day | week | month | quarter | year}
{MAX { {queries | query_selects | query_inserts | errors | result_rows | result_bytes | read_rows | read_bytes | execution_time} = number } [,...] |
NO LIMITS | TRACKING ONLY} [,...]]
[TO {role [,...] | ALL | ALL EXCEPT role [,...]}]

user_nameip_addressclient_keyclient_key, user_nameclient_key, ip_address 对应于system.quotas 表中的字段。

参数 queriesquery_selectsquery_insertserrorsresult_rowsresult_bytesread_rowsread_bytesexecution_timefailed_sequential_authentications 对应于system.quotas_usage 表中的字段。

ON CLUSTER 子句允许在集群上创建配额,请参阅分布式 DDL

示例

限制当前用户在 15 个月内最多执行 123 个查询

CREATE QUOTA qA FOR INTERVAL 15 month MAX queries = 123 TO CURRENT_USER;

对于默认用户,在 30 分钟内限制最大执行时间为半秒,并在 5 个季度内限制最大查询数为 321,最大错误数为 10

CREATE QUOTA qB FOR INTERVAL 30 minute MAX execution_time = 0.5, FOR INTERVAL 5 quarter MAX queries = 321, errors = 10 TO default;