> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> QUOTA のドキュメント

# CREATE QUOTA

ユーザーまたはロールに割り当て可能な[クォータ](/ja/concepts/features/security/access-rights#quotas-management)を作成します。

構文:

```sql theme={null}
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 | normalized_query_hash} | 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 | written_bytes | execution_time | failed_sequential_authentications | queries_per_normalized_hash} = number } [,...] |
         NO LIMITS | TRACKING ONLY} [,...]]
    [TO {role [,...] | ALL | ALL EXCEPT role [,...]}]
```

キー `user_name`, `ip_address`, `client_key`, `client_key, user_name`, `client_key, ip_address`, および `normalized_query_hash` は、[system.quotas](/ja/reference/system-tables/quotas) テーブルのフィールドに対応しています。

パラメーター `queries`, `query_selects`, `query_inserts`, `errors`, `result_rows`, `result_bytes`, `read_rows`, `read_bytes`, `written_bytes`, `execution_time`, `failed_sequential_authentications`, `queries_per_normalized_hash` は、[system.quotas\_usage](/ja/reference/system-tables/quotas_usage) テーブルのフィールドに対応しています。

`ON CLUSTER` 句を使用すると、クラスター上にクォータを作成できます。詳しくは [Distributed DDL](/ja/reference/statements/distributed-ddl) を参照してください。

**例**

現在のユーザーに対して、15 か月間で最大 123 クエリという制約を設定します:

```sql theme={null}
CREATE QUOTA qA FOR INTERVAL 15 month MAX queries = 123 TO CURRENT_USER;
```

デフォルトユーザーに対して、30分間の最大実行時間を0.5秒に制限し、さらに5四半期の間のクエリの最大数を321、エラーの最大数を10に制限します:

```sql theme={null}
CREATE QUOTA qB FOR INTERVAL 30 minute MAX execution_time = 0.5, FOR INTERVAL 5 quarter MAX queries = 321, errors = 10 TO default;
```

各正規化クエリパターンに専用のバケットを割り当て、1時間あたりの実行回数を100回に制限するQUOTAを作成します:

```sql theme={null}
CREATE QUOTA qC KEYED BY normalized_query_hash FOR INTERVAL 1 hour MAX queries = 100 TO default;
```

各正規化クエリパターンの実行回数を、1時間あたり最大50回までに制限します (QUOTAキーの種類にかかわらず) :

```sql theme={null}
CREATE QUOTA qD FOR INTERVAL 1 hour MAX queries_per_normalized_hash = 50 TO default;
```

xml 設定を使用するその他の例 (ClickHouse Cloud ではサポートされていません) については、[Quotas ガイド](/ja/concepts/features/configuration/server-config/quotas)を参照してください。

<div id="related-content">
  ## 関連コンテンツ
</div>

* ブログ: [ClickHouse を使ったシングルページアプリケーションの構築](https://clickhouse.com/blog/building-single-page-applications-with-clickhouse-and-http)
