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.

资源Resource 默认限制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 20 GB20 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
每 1 GB 需要的最小 RU 数Minimum RUs required per 1 GB 10 RU/秒10 RU/s


若要了解有关管理其分区键需要更高存储或吞吐量限制的工作负荷的最佳做法,请参阅创建合成分区键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 RU/s. 随着容器的扩展,支持的最小吞吐量还取决于以下因素:As the container grows, the minimum supported throughput also depends on the following factors:

  • 曾经为容器预配的最大吞吐量。The maximum throughput ever provisioned on the container. 例如,如果吞吐量已增加到 50000 RU/秒,则可能的最低预配吞吐量为 500 RU/秒For example, if your throughput was increased to 50,000 RU/s, then the lowest possible provisioned throughput would be 500 RU/s
  • 容器中的当前存储大小 (GB)。The current storage in GB in the container. 例如,如果容器有 100 GB 的存储空间,则可能的最低预配吞吐量为 1000 RU/秒For example, if your container has 100 GB of storage, then the lowest possible provisioned throughput would be 1000 RU/s
  • 共享吞吐量数据库上的最小吞吐量还取决于曾在共享吞吐量数据库中创建的容器总数,按每个容器 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 RU/s per container. 例如,如果在共享吞吐量数据库中创建了五个容器,则吞吐量必须至少为 500 RU/秒For example, if you have created five containers within a shared throughput database, then the throughput must be at least 500 RU/s

可以从 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.


在某些情况下,可将吞吐量降到 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.

资源Resource 默认限制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.

资源Resource 默认限制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


区域故障转移仅适用于单个区域写入帐户。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

资源Resource 默认限制Default limit
数据库的最小数目Maximum number of databases 无限制Unlimited
具有共享吞吐量的每个数据库的最大容器数Maximum number of containers per database with shared throughput 2525
具有专用吞吐量的每个数据库或帐户的最大容器数Maximum number of containers per database or account with dedicated throughput 不受限制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.

资源Resource 默认限制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.

资源Resource 默认限制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 1023 个字节1023 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

Azure Cosmos DB 支持对容器、项和数据库等资源执行 CRUD 和查询操作Azure Cosmos DB supports CRUD and query operations against resources like containers, items, and databases. 它还支持针对容器中具有相同分区键的多个项的事务性批处理请求It also supports transactional batch requests against multiple items with the same partition key in a container.

资源Resource 默认限制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 (for example, stored procedure, CRUD) 2 MB2 MB
最大响应大小(例如分页查询)Maximum response size (for example, paginated query) 4 MB4 MB
事务性批处理中的最大操作数Maximum number of operations in a transactional batch 100100

一旦查询之类的操作达到执行超时或响应大小限制,它会向客户端返回结果页和继续标记,以继续执行操作。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.

资源Resource 默认限制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.

自动缩放预配吞吐量限制Limits for autoscale provisioned throughput

有关自动缩放吞吐量和存储限制的更多详细说明,请参阅自动缩放文章和常见问题解答See the Autoscale article and FAQ for more detailed explanation of the throughput and storage limits with autoscale.

资源Resource 默认限制Default limit
系统可以缩放到的最大 RU/秒Maximum RU/s the system can scale to Tmax,用户设置的自动缩放最大 RU/秒Tmax, the autoscale max RU/s set by user
系统可以缩放到的最小 RU/秒Minimum RU/s the system can scale to 0.1 * Tmax
系统缩放到的当前 RU/秒Current RU/s the system is scaled to 0.1*Tmax <= T <= Tmax根据使用情况0.1*Tmax <= T <= Tmax, based on usage
每小时最小可计费 RU/秒Minimum billable RU/s per hour 0.1 * Tmax
计费以小时为单位,在这种情况下,将按系统在一小时内缩放到的最高 RU/秒或 0.1*Tmax 计费,以较大者为准。Billing is done on a per-hour basis, where you are billed for the highest RU/s the system scaled to in the hour, or 0.1*Tmax, whichever is higher.
容器的最小自动缩放最大 RU/秒Minimum autoscale max RU/s for a container MAX(4000, highest max RU/s ever provisioned / 10, current storage in GB * 100),舍入为最接近的 1000 RU/秒MAX(4000, highest max RU/s ever provisioned / 10, current storage in GB * 100) rounded to nearest 1000 RU/s
数据库的最小自动缩放最大 RU/秒Minimum autoscale max RU/s for a database MAX(4000, highest max RU/s ever provisioned / 10, current storage in GB * 100, 4000 + (MAX(Container count - 25, 0) * 1000)),舍入为最接近的 1000 RU/秒。MAX(4000, highest max RU/s ever provisioned / 10, current storage in GB * 100, 4000 + (MAX(Container count - 25, 0) * 1000)), rounded to nearest 1000 RU/s.
请注意,如果数据库有 25 个以上的容器,每增加一个容器,系统会将最小自动缩放最大 RU/秒增加 1000 RU/秒。Note if your database has more than 25 containers, the system increments the minimum autoscale max RU/s by 1000 RU/s per additional container. 例如,如果有 30 个容器,则可以设置的最低自动缩放最大 RU/秒为 9000 RU/秒(缩放范围是 900 - 9000 RU/秒)。For example, if you have 30 containers, the lowest autoscale maximum RU/s you can set is 9000 RU/s (scales between 900 - 9000 RU/s).

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.

资源Resource 默认限制Default limit
最大 SQL 队列长度Maximum length of SQL query 256 KB256 KB
每个查询的最大 JOIN 数Maximum JOINs per query 5 *5 *
每个查询的最大 UDF 数Maximum UDFs per query 10 *10 *
每个多边形的最大点数Maximum points per polygon 40964096
每个容器的最大包含路径数Maximum included paths per container 500500
每个容器的最大排除路径数Maximum excluded paths per container 500500
组合索引中的最大属性数Maximum properties in a composite index 88

* 可以联系 Azure 支持来提高上述 SQL 查询限制。* You can increase 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.

资源Resource 默认限制Default limit
最大 MongoDB 查询内存大小(此限制仅适用于 3.2 服务器版本)Maximum MongoDB query memory size (This limitation is only for 3.2 server version) 40 MB40 MB
MongoDB 操作的最长执行时间Maximum execution time for MongoDB operations 30 秒30s
导致服务器端连接关闭的空闲连接超时值*Idle connection timeout for server side connection closure* 30 分钟30 minutes

* 我们建议客户端应用程序将驱动程序设置中的空闲连接超时值设为 2-3 分钟,因为 Azure LoadBalancer 的默认超时值为 4 分钟* We recommend that client applications set the idle connection timeout in the driver settings to 2-3 minutes because the default timeout for Azure LoadBalancer is 4 minutes. 此超时值可确保客户端计算机与 Azure Cosmos DB 之间的中间负载均衡器不会关闭空闲连接。This timeout will ensure that idle connections are not closed by an intermediate load balancer between the client machine and Azure Cosmos DB.

免费层帐户限制Free tier account limits

下表列出了 Azure Cosmos DB 免费层帐户的限制。The following table lists the limits for Azure Cosmos DB free tier accounts.

资源Resource 默认限制Default limit
每个 Azure 订阅的免费层帐户数Number of free tier accounts per Azure subscription 11
免费层折扣持续时间Duration of free-tier discount 帐户的生存期。Lifetime of the account. 必须在创建帐户期间选择加入。Must opt-in during account creation.
免费层的最大 RU/sMaximum RU/s for free 400 RU/s400 RU/s
免费层的最大存储量Maximum storage for free 5 GB5 GB
最大共享吞吐量数据库数Maximum number of shared throughput databases 55
共享吞吐量数据库中的最大容器数Maximum number of containers in a shared throughput database 2525
在免费层帐户中,最多包含 25 个容器的共享吞吐量数据库的最小 RU/s 为 400 RU/s。In free tier accounts, the minimum RU/s for a shared throughput database with up to 25 containers is 400 RU/s.

除上述限制外,每个帐户的限制也适用于免费层帐户。In addition to the above, the Per-account limits also apply to free tier accounts.

后续步骤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: