Azure Cosmos DB 服务配额Azure Cosmos DB service quotas

本文概述了 Azure Cosmos DB 中为不同资源提供的默认配额。This article provides an overview of the default quotas offered to different resources in the Azure Cosmos DB.

存储和吞吐量Storage and throughput

在订阅下创建 Azure Cosmos 帐户后,可以通过创建数据库、容器和项来管理帐户中的数据。After you create an Azure Cosmos account under your subscription, you can manage data in your account by creating databases, containers, and items. 可以在容器级别或数据库级别按请求单位 (RU) 预配吞吐量。You can provision throughput at a container-level or a database-level in terms of request units (RU/s or RUs). 下表列出了每个容器/数据库的存储和吞吐量限制。The following table lists the limits for storage and throughput per container/database.

ResourceResource 默认限制Default limit
每个容器的最大 RU 数(专用吞吐量预配模式Maximum RUs per container (dedicated throughput provisioned mode) 默认为 1,000,000。1,000,000 by default. 可以通过开具 Azure 支持票证来提高此限制You can increase it by filing an Azure support ticket
每个数据库的最大 RU 数(共享吞吐量预配模式Maximum RUs per database (shared throughput provisioned mode) 默认为 1,000,000。1,000,000 by default. 可以通过开具 Azure 支持票证来提高此限制You can increase it by filing an Azure support ticket
每个(逻辑)分区键的最大 RU 数Maximum RUs per (logical) partition key 10,00010,000
每个(逻辑)分区键的所有项的最大存储Maximum storage across all items per (logical) partition key 10 GB10 GB
最大相异(逻辑)分区键数目Maximum number of distinct (logical) partition keys 无限制Unlimited
每个容器的最大存储Maximum storage per container 无限制Unlimited
每个数据库的最大存储Maximum storage per database 无限制Unlimited
每个帐户的最大附件大小(附件功能即将弃用)Maximum attachment size per Account (Attachment feature is being depreciated) 2 GB2 GB

Note

对于具有需要更高存储或吞吐量限制的分区键的工作负荷,若要了解其最佳管理实践,请参阅创建合成分区键To learn about best practices for managing workloads that have partition keys requiring higher limits for storage or throughput, see Create a synthetic partition key.

Cosmos 容器(或共享吞吐量数据库)的吞吐量必须至少为 400 RU。A Cosmos container (or shared throughput database) must have a minimum throughput of 400 RUs. 随着容器的不断扩大,支持的最小吞吐量还取决于以下因素:As the container grows, the minimum supported throughput also depends on the following factors:

  • 可对容器设置的最小吞吐量取决于对该容器预配的最大吞吐量。The minimum throughput that you can set on a container depends on the maximum throughput ever provisioned on the container. 服务支持将容器吞吐量降低至最大预配量的 10%。The service supports lowering throughput of a container to 10% of the provisioned maximum. 例如,如果吞吐量已提高至 10000 RU,则最低可能的预配吞吐量将是 1000 RUFor example, if your throughput was increased to 10000 RUs, then the lowest possible provisioned throughput would be 1000 RUs
  • 共享吞吐量数据库的最小吞吐量也取决于曾经在共享吞吐量数据库中创建的容器总数,以每个容器 100 个 RU 计量。The minimum throughput on a shared throughput database also depends on the total number of containers that you have ever created in a shared throughput database, measured at 100 RUs per container. 例如,如果你在共享吞吐量数据库中创建了 5 个容器,则吞吐量必须至少为 500 RUFor example, if you have created five containers within a shared throughput database, then the throughput must be at least 500 RUs

可以从 Azure 门户或 SDK 检索容器或数据库的当前吞吐量和最低吞吐量。The current and minimum throughput of a container or a database can be retrieved from the Azure portal or the SDKs. 有关详细信息,请参阅对容器和数据库预配吞吐量For more information, see Provision throughput on containers and databases.

Note

在某些情况下,可将吞吐量降到 10% 以下。In some cases, you may be able to lower throughput to lesser than 10%. 使用 API 获取每个容器的确切最小 RU 数。Use the API to get the exact minimum RUs per container.

下面汇总了最低预配 RU 限制。In summary, here are the minimum provisioned RU limits.

ResourceResource 默认限制Default limit
每个容器的最小 RU 数(专用吞吐量预配模式Minimum RUs per container (dedicated throughput provisioned mode) 400400
每个数据库的最小 RU 数(共享吞吐量预配模式Minimum RUs per database (shared throughput provisioned mode) 400400
共享吞吐量数据库中每个容器的最小 RU 数Minimum RUs per container within a shared throughput database 100100

Cosmos DB 支持通过 SDK 或门户弹性缩放每个容器或数据库的吞吐量 (RU)。Cosmos DB supports elastic scaling of throughput (RUs) per container or database via the SDKs or portal. 可以同步方式或立即缩放每个容器,缩放范围为最小值和最大值之间的 10 到 100 倍。Each container can scale synchronously and immediately within a scale range of 10 to 100 times, between minimum and maximum values. 如果请求的吞吐量值超出范围,将以异步方式执行缩放。If the requested throughput value is outside the range, scaling is performed asynchronously. 完成异步缩放所需的时间为数分钟到数小时不等,具体取决于请求的吞吐量和容器中的数据存储大小。Asynchronous scaling may take minutes to hours to complete depending on the requested throughput and data storage size in the container.

控制平面操作Control plane operations

可以使用 Azure 门户、Azure PowerShell、Azure CLI 和 Azure 资源管理器模板预配和管理 Azure Cosmos 帐户You can provision and manage your Azure Cosmos account using the Azure portal, Azure PowerShell, Azure CLI, and Azure Resource Manager templates. 下表列出了每个订阅、帐户和操作数目的限制。The following table lists the limits per subscription, account, and number of operations.

ResourceResource 默认限制Default limit
每个订阅的最大数据库帐户数Maximum database accounts per subscription 默认为 50。50 by default. 可以通过开具 Azure 支持票证来提高此限制You can increase it by filing an Azure support ticket
最大区域故障转移次数Maximum number of regional failovers 默认为每小时 1 次。1/hour by default. 可以通过开具 Azure 支持票证来提高此限制You can increase it by filing an Azure support ticket

Note

区域故障转移仅适用于单区域写入帐户。Regional failovers only apply to single region writes accounts. 多区域写入帐户不需要,也不会对更改写入区域施加任何限制。Multi-region write accounts do not require or have any limits on changing the write region.

Cosmos DB 会定期自动备份数据。Cosmos DB automatically takes backups of your data at regular intervals. 有关备份保留间隔和时限的详细信息,请参阅 Azure Cosmos DB 中的联机备份和按需数据还原For details on backup retention intervals and windows, see Online backup and on-demand data restore in Azure Cosmos DB.

每个帐户的限制Per-account limits

ResourceResource 默认限制Default limit
数据库的最小数目Maximum number of databases 无限制Unlimited
每个数据库(或帐户)的最大容器数Maximum number of containers per database (or account) 无限制Unlimited
最大区域数Maximum number of regions 无限制(所有 Azure 区域)No limit (All Azure regions)

每个容器的限制Per-container limits

根据所用的 API,Azure Cosmos 容器可以代表集合、表或图形。Depending on which API you use, an Azure Cosmos container can represent either a collection, a table, or graph. 容器支持唯一键约束存储过程、触发器和 UDF索引策略的配置。Containers support configurations for unique key constraints, stored procedures, triggers, and UDFs, and indexing policy. 下表列出了特定于容器中的配置的限制。The following table lists the limits specific to configurations within a container.

ResourceResource 默认限制Default limit
数据库或容器名称的最大长度Maximum length of database or container name 255255
每个容器的最大存储过程数Maximum stored procedures per container 100 *100 *
每个容器的最大 UDF 数Maximum UDFs per container 25 *25 *
索引策略中的最大路径数Maximum number of paths in indexing policy 100 *100 *
每个容器的最大唯一键数Maximum number of unique keys per container 10 *10 *
每个唯一键约束的最大路径数Maximum number of paths per unique key constraint 16 *16 *

* 可以联系 Azure 支持人员来提高上述每个容器的限制。* You can increase any of these per-container limits by contacting Azure Support.

每个项的限制Per-item limits

根据所用的 API,Azure Cosmos 项可以代表集合中的文档、表中的行,或者图形中的节点或边缘。Depending on which API you use, an Azure Cosmos item can represent either a document in a collection, a row in a table, or a node or edge in a graph. 下表显示了 Cosmos DB 中每个项的限制。The following table shows the limits per item in Cosmos DB.

ResourceResource 默认限制Default limit
项的最大大小Maximum size of an item 2 MB(JSON 表示形式的 UTF-8 长度)2 MB (UTF-8 length of JSON representation)
分区键值的最大长度Maximum length of partition key value 2048 字节2048 bytes
ID 值的最大长度Maximum length of id value 1024 字节1024 bytes
每个项的最大属性数Maximum number of properties per item 无实际限制No practical limit
最大嵌套深度Maximum nesting depth 无实际限制No practical limit
属性名称的最大长度Maximum length of property name 无实际限制No practical limit
属性值的最大长度Maximum length of property value 无实际限制No practical limit
字符串属性值的最大长度Maximum length of string property value 无实际限制No practical limit
数字属性值的最大长度Maximum length of numeric property value IEEE754 双精度 64 位IEEE754 double-precision 64-bit

项有效负载(例如属性数和嵌套深度)没有限制,不过,分区键和 ID 值存在长度限制,且总大小限制为 2 MB。There are no restrictions on the item payloads like number of properties and nesting depth, except for the length restrictions on partition key and id values, and the overall size restriction of 2 MB. 对于采用大型或复杂项结构的容器,可能需要配置索引策略来降低 RU 消耗。You may have to configure indexing policy for containers with large or complex item structures to reduce RU consumption. 为 Cosmos DB 中的项建模中提供了一个真实示例,以及用于管理大项的模式。See Modeling items in Cosmos DB for a real-world example, and patterns to manage large items.

每个请求的限制Per-request limits

Cosmos DB 支持针对容器、项和数据库等资源执行 CRUD 和查询操作Cosmos DB supports CRUD and query operations against resources like containers, items, and databases.

ResourceResource 默认限制Default limit
单个操作(例如存储过程执行或单个查询页检索)的最长执行时间Maximum execution time for a single operation (like a stored procedure execution or a single query page retrieval) 5 秒5 sec
最大请求大小(存储过程,CRUD)Maximum request size (stored procedure, CRUD) 2 MB2 MB
最大响应大小(例如分页查询)Maximum response size (for example, paginated query) 4 MB4 MB

一旦查询等操作达到执行超时或响应大小限制,就会返回一个结果页面,并向客户端返回一个继续令牌用于恢复执行。Once an operation like query reaches the execution timeout or response size limit, it returns a page of results and a continuation token to the client to resume execution. 单个查询可以针对不同的页面/继续执行活动运行的持续时间没有实际的限制。There is no practical limit on the duration a single query can run across pages/continuations.

Cosmos DB 使用 HMAC 进行授权。Cosmos DB uses HMAC for authorization. 可以使用主密钥或资源令牌对容器、分区键或项等资源进行精细的访问控制。You can use either a master key, or a resource tokens for fine-grained access control to resources like containers, partition keys, or items. 下表列出了 Cosmos DB 中授权令牌的限制。The following table lists limits for authorization tokens in Cosmos DB.

ResourceResource 默认限制Default limit
主令牌最长过期时间Maximum master token expiry time 15 分钟15 min
资源令牌最短过期时间Minimum resource token expiry time 10 分钟10 min
资源令牌最长过期时间Maximum resource token expiry time 默认为 24 小时。24 h by default. 可以通过开具 Azure 支持票证来提高此限制You can increase it by filing an Azure support ticket
令牌授权的最大时钟偏差Maximum clock skew for token authorization 15 分钟15 min

Cosmos DB 支持在写入期间执行触发器。Cosmos DB supports execution of triggers during writes. 对于每个写入操作,服务最多支持一个前触发器和一个后触发器。The service supports a maximum of one pre-trigger and one post-trigger per write operation.

SQL 查询限制SQL query limits

Cosmos DB 支持使用 SQL 查询项。Cosmos DB supports querying items using SQL. 下表描述了查询语句的限制,例如子句数目或查询长度方面的限制。The following table describes restrictions in query statements, for example in terms of number of clauses or query length.

ResourceResource 默认限制Default limit
SQL 查询的最大长度Maximum length of SQL query 256 KB *256 KB *
每个查询的最大 JOIN 数目Maximum JOINs per query 5 *5 *
每个查询的最大 AND 数目Maximum ANDs per query 2000 *2000 *
每个查询的最大 OR 数目Maximum ORs per query 2000 *2000 *
每个查询的最大 UDF 数目Maximum UDFs per query 10 *10 *
每个 IN 表达式的最大参数数目Maximum arguments per IN expression 6000 *6000 *
每个多边形的最大点数目Maximum points per polygon 4096 *4096 *

* 可以联系 Azure 支持人员来提高上述 SQL 查询限制。* You can increase any of these SQL query limits by contacting Azure Support.

特定于 MongoDB API 的限制MongoDB API-specific limits

Cosmos DB 支持针为 MongoDB 编写的应用程序使用 MongoDB 线路协议。Cosmos DB supports the MongoDB wire protocol for applications written against MongoDB. 可以在支持的 MongoDB 功能和语法中找到支持的命令和协议版本。You can find the supported commands and protocol versions at Supported MongoDB features and syntax.

下表列出了特定于 MongoDB 功能支持的限制。The following table lists the limits specific to MongoDB feature support. 针对 SQL(核心)API 所述的其他服务限制同样适用于 MongoDB API。Other service limits mentioned for the SQL (core) API also apply to the MongoDB API.

ResourceResource 默认限制Default limit
最大 MongoDB 查询内存大小Maximum MongoDB query memory size 40 MB40 MB
MongoDB 操作的最长执行时间Maximum execution time for MongoDB operations 30 秒30s

后续步骤Next steps

详细了解 Cosmos DB 的核心概念多区域分布分区预配的吞吐量Read more about Cosmos DB's core concepts multiple-region distribution and partitioning and provisioned throughput.

请通过阅读以下快速入门文章之一,来开始使用 Azure Cosmos DB:Get started with Azure Cosmos DB with one of our quickstarts: