Quotas in ClickHouse CloudQuotas are supported in ClickHouse Cloud but must be created using the DDL syntax. The XML configuration approach documented below is not supported.
- Place restrictions on a set of queries that can be run over a period of time, instead of limiting a single query.
- Account for resources spent on all remote servers for distributed query processing.
queries – The total number of requests.
query_selects – The total number of select requests.
query_inserts – The total number of insert requests.
errors – The number of queries that threw an exception.
result_rows – The total number of rows given as a result.
result_bytes - The total size of rows given as a result.
read_rows – The total number of source rows read from tables for running the query on all remote servers.
read_bytes - The total size read from tables for running the query on all remote servers.
written_bytes - The total size of a writing operation.
written_rows - The total number of rows written by INSERT queries.
execution_time – The total query execution time, in seconds (wall time).
failed_sequential_authentications - The total number of sequential authentication errors.
queries_per_normalized_hash – The maximum number of executions of any single normalized query. Normalized queries are queries with literals replaced by placeholders, so SELECT 1 and SELECT 2 are considered the same normalized query. This limit is tracked per distinct normalized query pattern independently.
In addition to the predefined amounts above, a limit can be set on any profile event (see the system.events table) by using the event name as the tag, for example:
profile_events column of the system.quotas_usage table. Profile events accumulated outside of queries (for example, by background merges) are not charged to quotas.
For a distributed query, the profile events that the remote servers report back to the initiator are charged to the quota of the initiating user together with the local ones. The remote servers always send these reports for a distributed query, regardless of the send_profile_events setting in the query, in its SETTINGS clause, or in the settings constraints of the user on the remote server, so a user cannot turn them off. This includes a synchronous INSERT into a Distributed table or the remote table function, for which a remote server reports its profile events once it has received all the data; the background sends of Distributed tables with distributed_foreground_insert = 0 are not part of any user query and are not charged. The deferred flush of asynchronous inserts is charged to the quota of the user who submitted the inserts, in the same bucket as the inserts were checked against (for a quota keyed by ip_address or forwarded_ip_address, the bucket of the client address; for a quota keyed by normalized_query_hash, the bucket of the submitted INSERT), and not to the query that forces the flush, such as SYSTEM FLUSH ASYNC INSERT QUEUE. If a remote server receiving a distributed INSERT queues it as an asynchronous insert, the deferred flush on that server is charged there, to the quota of the user the initiator connects as, and is not reported back to the initiator. Nothing is counted twice: the rows that the initiator of a distributed INSERT sends to a remote server are charged once in InsertedRows and InsertedBytes, while what the remote server writes beyond them, for example into the target tables of materialized views, is charged in addition.
If the limit is exceeded for at least one time interval, an exception is thrown with a text about which restriction was exceeded, for which interval, and when the new interval begins (when queries can be sent again).
Queries excluded from quota accountingTo allow quota configuration and usage to be inspected even when a quota is exhausted,
SELECT queries that exclusively read from one of the following system tables are not charged to quotas and are not subject to query-complexity limits:system.quotassystem.quota_limitssystem.quota_usagesystem.quotas_usagesystem.one
<keyed_by_normalized_query_hash />:
SELECT number FROM numbers(1) and SELECT number FROM numbers(2) share the same bucket (because they have the same normalized form), but SELECT number, number FROM numbers(1) uses a separate bucket.
The quota is assigned to users in the ‘users’ section of the config. See the section “Access rights”.
For distributed query processing, the accumulated amounts are stored on the requestor server. So if the user goes to another server, the quota there will “start over”.
When the server is restarted, quotas are reset.