Skip to main content

Prisma Postgres 常见问题解答

关于 Prisma Postgres 如何工作、查询如何计费以及如何与 Prisma ORM 集成的常见问题。

¥Common questions about how Prisma Postgres works, how queries are billed, and how it integrates with the Prisma ORM.

一般的

¥General

我可以在不使用 Prisma ORM 的情况下使用 Prisma Postgres 吗?

¥Can I use Prisma Postgres without Prisma ORM?

是的,你可以通过 直接连接 将 Prisma Postgres 与任何数据库库或工具一起使用。

¥Yes, you can use Prisma Postgres with any database library or tool via a direct connection.

如何从 GitHub 登录切换到邮箱和密码登录?

¥How do I switch from GitHub login to email and password login?

如果你之前使用 GitHub 注册,现在想切换到邮箱和密码登录,请按以下步骤操作:

¥If you previously signed up using GitHub and want to switch to email and password login, follow these steps:

  1. 验证你的 GitHub 电子邮件地址

    ¥Verify Your GitHub Email Address

    • 检查与你的 GitHub 账户关联的主要电子邮件地址(例如,从你的 GitHub 个人资料或通知设置中)。

      ¥Check the primary email address associated with your GitHub account (e.g., from your GitHub profile or notification settings).

  2. 创建新的邮箱/密码账户

    ¥Create a New Email/Password Account

    • 前往邮箱/密码注册页面。

      ¥Go to the email/password sign-up page.

    • 使用与你的 GitHub 账户关联的相同电子邮件地址创建新账户。

      ¥Use the same email address linked to your GitHub account to create the new account.

    • 我们的系统会自动将你的新邮箱/密码账户连接到你现有的数据。

      ¥Our system will automatically connect your new email/password account to your existing data.

  3. 测试你的登录

    ¥Test Your Login

    • 注销并尝试使用你的电子邮件和刚刚创建的密码登录。

      ¥Log out and try logging in with your email and the password you just created.

注意

如果你遇到任何问题,请联系我们的支持团队以获取账户关联方面的帮助。

¥If you encounter any issues, please contact our support team for help linking your accounts.

VS Code 无法识别 $extends 方法

¥VS Code does not recognize the $extends method

如果你将 Prisma Client Accelerate 扩展添加到当前在 VS Code 中打开的现有项目中,编辑器可能无法立即识别 $extends 方法。

¥If you add the Prisma Client extension for Accelerate to an existing project that is currently open in VS Code, the editor might not immediately recognize the $extends method.

这可能是 TypeScript 服务器尚未识别重新生成的 Prisma 客户端的问题。要解决此问题,你需要重新启动 TypeScript。

¥This might be an issue with the TypeScript server not yet recognizing the regenerated Prisma Client. To resolve this, you need to restart TypeScript.

  1. 在 VS Code 中,打开命令面板。你可以按 F1 或选择“视图”>“命令面板”来执行此操作。

    ¥In VS Code, open the Command Palette. You can do so when you press F1 or select View > Command Palette.

  2. 输入 typescript 并选择并运行 TypeScript:重新启动 TS 服务器命令。

    ¥Enter typescript and select and run the TypeScript: Restart TS server command.

VS Code 现在应该可以识别 $extends 方法了。

¥VS Code should now recognize the $extends method.

定价

¥Pricing

Prisma Postgres 根据操作和所消耗的存储空间计费。访问 定价页面 了解详情,访问 博客文章解释基于操作的计费 详细了解操作的定义以及此定价模型的运作方式。

¥Prisma Postgres bills based on operations and storage consumed. Visit the pricing page for details and our blog post explaining operations-based billing for a detailed explanation on what an operation is and how this pricing model works.

什么是操作?

¥What is an operation?

每次与数据库交互时,都会计算一次操作。可读可写,简单或复杂。所有这些都算作一个。

¥An operation is counted each time you interact with your database. Read, write, simple or complex. It all simply counts as one.

操作可以是:

¥An operation can be:

查询执行时间会影响 Prisma Postgres 的定价吗?

¥Does query execution time affect pricing in Prisma Postgres?

不,Prisma Postgres 的成本完全基于操作数量,而不是执行这些操作所需的计算量。

¥No, cost for Prisma Postgres is based solely on the number of operations, not the amount of compute required to execute them.

无论查询执行需要 10 毫秒还是 10 秒,其定价影响都保持不变。

¥Whether a query takes 10ms or 10sec to execute, its pricing impact remains the same.

使用 Prisma ORM 和直接 TCP 连接的定价有何不同?

¥How does pricing differ between using Prisma ORM and direct TCP connections?

Prisma ORM 和 直接 TCP 连接 的基于操作的定价基本原则保持不变。但是,根据你使用 Prisma ORM 还是直接 SQL 与数据库交互,操作会有所不同:

¥The fundamental principle of operations-based pricing remains the same for Prisma ORM and direct TCP connection. However, depending on whether you use Prisma ORM or direct SQL to interact with your database, an operation is something different:

  • 使用 Prisma ORM 时:通过 Prisma 客户端发送的查询(例如 prisma.user.findMany()

    ¥when using Prisma ORM: a query sent with Prisma Client (e.g. prisma.user.findMany())

  • 使用其他工具时:通过直接连接发送的 SQL 查询(例如 SELECT * from "User"

    ¥when using another tool: a SQL query sent via the direct connection (e.g. SELECT * from "User")

请注意,单个 Prisma ORM 查询可能会转换为多个 SQL 查询,这可能使使用 Prisma ORM 比直接使用 SQL 更经济。

¥Note that a single Prisma ORM query may translate into multiple SQL queries which may make using Prisma ORM more economical than direct SQL.

读写查询是否需要开销一样吗?

¥Do read and write queries cost the same?

是的,读取和写入查询均计为操作,并以相同的方式计费。

¥Yes, read and write queries are counted equally as operations and are billed the same way.

SELECT 1 查询算作可计费操作吗?

¥Does a SELECT 1 query count as a billable operation?

是的,像 SELECT 1 这样的查询算作一次操作,并将相应计费(即使查询中没有访问实际数据)。

¥Yes, a query like SELECT 1 counts as an operation and will be billed accordingly (even if no actual data is accessed in the query).

如何估算操作数量在 Prisma ORM 中?

¥How can I estimate the number of operations in Prisma ORM?

你可以通过将 Prometheus 等应用性能监控工具与 Prisma ORM 的 metrics 预览功能 集成来估算你在 Prisma ORM 中的操作使用情况。启用 metrics 预览功能后,请查看 prisma_client_queries_total 指标以了解操作数量。

¥You can estimate your operation usage in Prisma ORM by integrating an application performance monitoring tool like Prometheus with Prisma ORM's metrics preview feature. Once you enable the metrics preview feature, look at the prisma_client_queries_total metric for the number of operations.

Prisma Postgres 使用 prisma_client_queries_total 计数器,该计数器跟踪发送到数据库的每个客户端操作以计算你的账单。有关配置 Prometheus 和监控应用的详细分步指南,请参阅 查看我们的完整指南

¥Prisma Postgres uses the prisma_client_queries_total counter, which tracks every client operation sent to your database to calculate your billing. For a detailed, step-by-step walkthrough on configuring Prometheus and monitor your application, see our full guide.

我可以使用哪些策略来优化每次操作的成本?

¥What strategies can I use to optimize cost per operation?

Prisma Postgres 按操作计费。单个操作执行的操作越多,账单就越低。减少操作数量的一些技巧:

¥Prisma Postgres bills by operation. The more you can perform using a single operation, the lower your bill. Some tips to reduce the number of operations:

  • 批量写入createManyupdateManydeleteMany 一起使用,而不是循环遍历单行调用。

    ¥Batch your writes with createMany, updateMany, or deleteMany instead of looping over single-row calls.

    // One operation, three users
    await prisma.user.createMany({
    data: [
    { name: 'Alice' },
    { name: 'Bob' },
    { name: 'Carol' },
    ],
    })
  • 使用嵌套关系助手(例如 connectOrCreateset)在单个操作中创建或链接相关记录。

    ¥Use nested-relation helpers such as connectOrCreate or set to create or link related records in a single operation.

    // Post and (if needed) its author, all in one request
    await prisma.post.create({
    data: {
    title: 'Hello World',
    author: {
    connectOrCreate: {
    where: { email: 'alice@example.com' },
    create: { name: 'Alice', email: 'alice@example.com' },
    },
    },
    },
    })
  • 当各个查询彼此不依赖时,建议使用常规(数组)transactions 而不是 交互式事务

    ¥Prefer regular (array) transactions over interactive transactions when the individual queries don't depend on each other.

    // Interactive transaction: counted as 2 operations
    await prisma.$transaction(async (tx) => {
    await tx.user.create({ data: { name: 'Alice' } })
    await tx.post.create({ data: { title: 'Hello', authorId: 1 } })
    })

    // Array transaction: counted as 1 operation
    await prisma.$transaction([
    prisma.user.create({ data: { name: 'Alice' } }),
    prisma.post.create({ data: { title: 'Hello', authorId: 1 } }),
    ])

如果后续查询需要先前查询的结果(例如,你需要刚刚创建的用户 ID),请坚持使用交互式事务以确保正确性。此外,批处理和数组事务允许你将多个查询合并为一个计费操作,从而同时降低操作数量和成本。

¥If a later query needs the result of an earlier one (for example, you need the user ID you just created), stick with an interactive transaction for correctness. Otherwise, batching and array transactions let you collapse multiple queries into a single billed operation, keeping both your operation count, and your cost down.

是否有示例工作负载可以估算我的预期费用?

¥Is there a sample workload to estimate my expected charges?

我们将演示三个示例工作负载,并分别估算小型、中型和大型工作负载的账单。每个方案都结合了实际的月活跃用户 (MAU) 数量、每个用户的典型每日活动水平以及近似的存储空间。

¥We will demonstrate three example workloads and estimate bills for small, medium, and large workloads. Each combine a realistic number of monthly active users (MAUs), a typical level of daily activity per user, and a rounded storage footprint.

我们将使用以下公式估算每月账单:

¥We will use the following equations to estimate the monthly bill:

total_ops            = MAUs x actions_per_user_per_day x 30      
billable_ops = total_ops - 100_000
ops_cost = (billable_ops ÷ 1_000_000) x plan_rate

billable_storage_GB = storage_used_GB - free_storage_for_plan
storage_cost = billable_storage_GB x storage_rate_for_plan

total_monthly_cost = ops_cost + storage_cost + base_plan_fee
注意

你可以使用你自己的 MAU 数量、活动级别和存储量,并结合上述公式来预测任何计划的成本。

¥You can use your own MAU count, activity level, and storage used to project costs on any plan using the equations above.

我们会将每个工作负载与一个方案及其相应的定价详情关联起来,例如,适用于小型工作负载的 Starter 方案、适用于中型工作负载的专业方案以及适用于大型工作负载的商业年度方案。然后,我们将这些公式应用于示例工作负载,以粗略估算每月账单。例如:

¥We will associate each workload with a plan and its corresponding pricing details, for example, the Starter plan for the small workload, the Pro plan for the medium workload, and the Business Annual plan for the large workload. Then we will apply the equations to the example workloads to generate a rough estimate of a monthly bill. For example:

定价详情

以下是每个定价方案的详细信息:

¥Here are the details for each pricing plan:

  • 入门套餐 - 每百万次操作 18 美元

    ¥Starter plan - $18 per million operations

    • 基础套餐费用 - 每月 0 美元

      ¥Base plan fee - $0 per month

    • 存储空间 - 1 GB 免费,之后每增加 1 GB 2 美元 GB

      ¥Storage - 1 GB free then $2 per additional GB

  • 专业套餐 - 每百万次操作 8 美元

    ¥Pro plan - $8 per million operations

    • 基础套餐费用 - 每月 49.00 美元

      ¥Base plan fee - $49.00 per month

    • 存储空间 - 5 GB 免费,之后每增加 1 GB 加收 1.5 美元

      ¥Storage - 5 GB free then $1.5 per additional GB

  • 企业年费套餐 - 在 50-100M/月使用量范围内,每百万次操作 4 美元

    ¥Business Annual plan - $4 per million operations in the 50-100M/month usage bracket

    • 基础套餐费用 - 每月 129.00 美元

      ¥Base plan fee - $129.00 per month

    • 存储空间 - 10 GB 免费,之后每增加 1 GB 加收 1 美元

      ¥Storage - 10 GB free then $1 per additional GB

你还可以了解更多关于 定价页面 上每个计划的定价详情。

¥You can also learn more about the pricing details for each plan on the pricing page.

Starter 套餐中低负载示例:

¥Example of a small workload on the Starter plan:

一款业余爱好或早期副项目,服务于约 500 个月活跃用户。每个用户每天执行约 10 次操作,整个数据库使用约 0.5 GB 的存储空间。基于这些假设,你可以使用以下公式计算每月账单:

¥A hobby or early-stage side-project with ~500 MAUs. Each user performs ~10 actions per day, and the entire database uses ~0.5 GB of storage. Based on the assumptions, you would calculate the monthly bill using the following equations:

  • total_ops = 500 x 10 x 30 = 150000

  • billable_ops = 50000

  • ops_cost = (50000 ÷ 1000000) x $18 = $0.90

  • storage_cost = $0(0.5 GB 低于 1 GB 免费套餐)

    ¥storage_cost = $0 (0.5 GB is below the 1 GB free tier)

  • base_plan_fee = $0

total_monthly_cost = 每月 $0.90

¥total_monthly_cost = $0.90 per month

Pro 套餐中中等负载示例:

¥Example of a medium workload on the Pro plan:

一款不断发展的 SaaS 产品,服务于约 5000 个月活跃用户。高级用户平均每天执行约 40 次操作,应用存储约 6 GB 的数据。基于这些假设,你可以使用以下公式计算每月账单:

¥A growing SaaS product serving ~5000 MAUs. Power users average ~40 actions per day, and the app stores ~6 GB of data. Based on the assumptions, you would calculate the monthly bill using the following equations:

  • total_ops = 5000 x 40 x 30 = 6000000

  • billable_ops = 5900000

  • ops_cost = (5900000 ÷ 1000000) = 5.9 x $8 = $47.20

  • storage_cost = (6 GB - 5 GB) x $1.50 = $1.50

  • base_plan_fee = $49.00

total_monthly_cost = $47.20 + $1.50 + $49.00 = 每月 $97.70

¥total_monthly_cost = $47.20 + $1.50 + $49.00 = $97.70 per month

Business 包年套餐中高负载示例:

¥Example of a large workload on the Business Annual plan:

一款面向消费者的生产级应用,服务于约 50000 个月活跃用户。高负载(每个用户每天执行约 60 次操作)会带来大量流量,数据集将达到约 40 GB。基于这些假设,你可以使用以下公式计算每月账单:

¥A production-grade, consumer-facing application handling ~50000 MAUs. Heavy usage with ~60 actions per user per day drives significant traffic, and the dataset reaches ~40 GB. Based on the assumptions, you would calculate the monthly bill using the following equations:

  • total_ops = 50000 x 60 x 30 = 90000000

  • billable_ops = 89900000

  • ops_cost = (89900000 ÷ 1000000) = 89.9 x $4 = $359.6

  • storage_cost = (40 GB - 10 GB) x $1 = $30.00

  • base_plan_fee = $129.00

total_monthly_cost = $359.6 + $30.00 + $129.00 = 每月 $518.60

¥total_monthly_cost = $359.6 + $30.00 + $129.00 = $518.60 per month

缓存操作的计费是否相同?

¥Are cached operations billed the same?

每个请求,无论是访问数据库还是从缓存中获取,都算作一次操作。Prisma Postgres 使用固定的每操作价格,并且从不对出站流量收费,因此缓存响应不会产生任何额外或减少的费用。这种统一的费率使计费模型可预测,并避免了每个请求的复杂性。

¥Every request, whether it hits the database or is served from cache, counts as an operation. Prisma Postgres use a flat per-operation price and never charge for egress traffic, so a cached response doesn't incur any extra or reduced fee. This unified rate keeps the billing model predictable and avoids per-request complexity.

缓存

¥Caching

Prisma Postgres 包含内置连接池和全局缓存。这些功能通过优化查询的路由和缓存方式来提高性能。

¥Prisma Postgres includes built-in connection pooling and global caching. These features improve performance by optimizing how your queries are routed and cached.

Prisma Postgres 的缓存层如何知道从哪个区域获取缓存?

¥How does Prisma Postgres's cache layer know what region to fetch the cache from?

在底层,Prisma Postgres 的缓存层使用 Cloudflare,而 Cloudflare 使用 Anycast 进行网络寻址和路由。传入的请求将被路由到最近的数据中心或其网络中能够高效处理请求的 "node"。要了解有关其工作原理的更多信息,我们建议你查看 Anycast

¥Under the hood, Prisma Postgres's cache layer uses Cloudflare, which uses Anycast for network addressing and routing. An incoming request will be routed to the nearest data center or "node" in their network that has the capacity to process the request efficiently. To learn more about how this works, we recommend looking into Anycast.

如何使 Prisma Postgres 的缓存失效?

¥How can I invalidate a cache for Prisma Postgres?

如果你使用的是 付费计划,你可以通过 $accelerate.invalidate API 按需使缓存失效;或者,你可以在项目级别使整个缓存失效,每天最多五次。此限制基于 你的计划 设定。你可以通过 Accelerate 配置页面进行管理。

¥You can invalidate the cache on-demand via the $accelerate.invalidate API if you're on a paid plan, or you can invalidate your entire cache, on a project level, a maximum of five times a day. This limit is set based on your plan. You can manage this via the Accelerate configuration page.

Prisma Postgres 缓存层的一致性模型是什么?

¥What is Prisma Postgres's caching layer's consistency model?

Prisma Postgres 中的缓存层没有一致性模型。它不是一个需要节点达成共识的分布式系统(因为数据仅存储在最靠近用户的缓存节点中)。但是,Prisma Postgres 缓存节点中缓存的数据不会传播到其他节点,因此缓存层在设计上不需要一致性模型。

¥The caching layer in Prisma Postgres does not have a consistency model. It is not a distributed system where nodes need to reach a consensus (because data is only stored in the cache node(s) closest to the user). However, the data cached in Prisma Postgres's cache nodes doesn't propagate to other nodes, so the cache layer by design doesn't need a consistency model.

Prisma Postgres 实现了一个特别适合读取密集型工作负载的 读透缓存策略

¥Prisma Postgres implements a read-through caching strategy particularly suitable for read-heavy workloads.

缓存数据的新鲜度取决于查询中定义的缓存策略。有关为你的查询选择正确的缓存策略的更多信息,请参阅 本节

¥The freshness of the data served by the cache depends on the cache strategy defined in your query. Refer to this section for more information on selecting the right cache strategy for your query.

Prisma Postgres 的缓存层与其他缓存工具(例如 Redis)有何不同?

¥How is Prisma Postgres's caching layer different from other caching tools, such as Redis?

Prisma Postgres 的缓存层:

¥The caching layer of Prisma Postgres:

  • 是一种专用缓存,允许你使用缓存策略在查询级别优化代码中的数据访问。另一方面,Redis 和 Memcached 等工具是通用缓存,旨在具有适应性和灵活性。

    ¥Is a specialized cache that allows you to optimize data access in code at the query level with a cache strategy. On the other hand, tools such as Redis and Memcached are general-purpose caches designed to be adaptable and flexible.

  • 这是一种托管服务,可减少构建和维护缓存服务的时间、风险和工程工作量。

    ¥Is a managed service that reduces the time, risk, and engineering effort of building and maintaining a cache service.

  • 默认情况下,它是全局分布的,可降低查询的延迟。其他缓存工具需要额外配置才能全局使用。

    ¥Is globally distributed, by default, reducing the latency of your queries. Other cache tools would require additional configuration to make them available globally.

什么时候不应该使用 Prisma Postgres 的缓存功能?

¥When should I not use Prisma Postgres's caching features?

Prisma Postgres 的缓存层是一个全局数据缓存和连接池,允许你在查询级别优化代码中的数据访问。虽然使用 Prisma Postgres 进行缓存可以显著提升应用的性能,但它并不总是适合你用例的最佳选择。

¥The caching layer of Prisma Postgres is a global data cache and connection pool that allows you to optimize data access in code at the query level. While caching with Prisma Postgres can greatly boost the performance of your app, it may not always the best choice for your use case.

如果出现以下情况,此全局缓存功能可能不适合你应用:

¥This global cache feature may not be a good fit for your app if:

  • 你的应用仅在特定区域内使用,并且你的应用服务器和数据库都位于同一网络的同一区域内。例如,如果你的应用服务器和数据库位于同一区域和网络,数据库查询速度可能会更快。但是,如果你的应用服务器与数据库位于不同的区域或网络中,缓存节点将加快你的查询速度,因为数据将缓存在距离你的应用最近的数据中心。

    ¥Your app is exclusively used within a specific region and both your application server and database are situated in that same region on the same network. For example, database queries will likely be much faster if your application server and database are in the same region and network. However, If your application server is in different regions or networks from your database, the cache nodes will speed up your queries because the data will be cached in the closest data center to your application.

  • 你的应用数据始终需要在检索时保持最新,这使得制定合理的缓存策略变得困难。

    ¥Your application data always needs to be up-to-date on retrieval, making it difficult to establish a reasonable cache strategy.

配置 cacheStrategy 时,ttl 参数的允许最大值是多少?

¥What is the maximum allowed value for the ttl parameter when configuring cacheStrategy?

生存时间 (ttl) 参数最多可设置一年。但是,需要注意的是,如果缓存中的项目访问频率不高,它们可能会被逐出。

¥The Time-to-live (ttl) parameter can be set for up to a year. However, it's important to note that items within the cache may be evicted if they are not frequently accessed.

根据我们的实验,我们发现缓存项可以保留大约 18 小时。如果项目被主动访问,它们可能会在缓存中保留较长时间,但这并不能保证。

¥Based on our experimentation, we’ve seen cache items persist for around 18 hours. While items may remain in the cache for an extended period if they are actively accessed, there is no guarantee.

:::[note]

即使是频繁访问的项目也可能偶尔会被从缓存中移除。无论项目活跃度如何,它都不太可能存活超过一个月。

¥Even frequently accessed items may occasionally be evicted from the cache. It's unlikely for an item to survive for up to or longer than a month, regardless of its activity level.

:::

为什么我有时会看到意外的缓存行为?

¥Why do I sometimes see unexpected cache behavior?

当项目负载较高时,Prisma Postgres 的缓存层性能最佳。许多缓存操作(例如将数据提交到缓存和刷新陈旧数据)都是异步发生的。对缓存层进行基准测试时,我们建议使用循环或负载测试方法。这将更好地模拟高负载场景,并减少低频操作带来的异常值。

¥Prisma Postgres's cache layer performs best when it observes a higher load from a project. Many cache operations, such as committing data to cache and refreshing stale data, happen asynchronously. When benchmarking the cache layer, we recommend doing so with loops or a load testing approach. This will mimic higher load scenarios better and reduce outliers from low frequency operations.

Prisma 操作通过 HTTP 发送到 Prisma Postgres。因此,对 Prisma Postgres 的第一个请求必须建立 HTTP 握手,因此可能会产生额外的延迟。我们正在探索未来减少初始请求延迟的方法。

¥Prisma operations are sent to Prisma Postgres over HTTP. As a result, the first request to Prisma Postgres must establish an HTTP handshake and may have additional latency as a result. We're exploring ways to reduce this initial request latency in the future.

Prisma Postgres 的缓存节点在哪些区域可用?

¥What regions are Prisma Postgres's cache nodes available in?

Prisma Postgres 的缓存层在 Cloudflare 网络上运行,缓存命中由 Cloudflare 的 300 多个站点提供。你可以在此处找到 Prisma Postgres 缓存节点可用的区域:https://www.cloudflare.com/network/

¥Prisma Postgres's cache layer runs on Cloudflare's network and cache hits are served from Cloudflare's 300+ locations. You can find the regions where Prisma Postgres's cache nodes are available here: https://www.cloudflare.com/network/.

使缓存查询结果失效需要多长时间?

¥How long does it take to invalidate a cache query result?

由于需要全局清除缓存,因此很难提供具体的时间范围。但是,缓存的数据最终是一致的,通常会在几秒钟内传播到所有 PoP。在极少数情况下,这可能需要更长时间。

¥As the cache needs to be cleared globally, it is difficult to provide a specific time frame. However, the cached data is eventually consistent and typically propagates to all PoPs within a few seconds. In very rare cases, it may take longer.

以下是 演示应用,用于测试使缓存查询结果无效所需的时间。

¥Here is a demo app to test the time it takes to invalidate a cache query result.

Invalidate 和 Revalidate 之间有什么区别?

¥What is the difference between Invalidate and Revalidate?

失效:缓存条目将被删除,新的数据将在下次请求时获取,从而导致缓存未命中。这会删除过时的数据,但可能会导致响应速度变慢,直到重新填充缓存为止。

¥Invalidate: The cache entry is deleted, and new data will be fetched on the next request, causing a cache miss. This removes stale data but may lead to slower responses until the cache is repopulated.

重新验证:缓存条目会主动更新,确保下次请求使用缓存中的新数据。这可以使缓存保持有效,并通过避免缓存未命中来保持更快的响应时间。

¥Revalidate: The cache entry is updated proactively, ensuring the next request uses fresh data from the cache. This keeps the cache valid and maintains faster response times by avoiding cache misses.

什么是按需缓存失效?

¥What is on-demand cache invalidation?

按需缓存失效 允许应用在特定缓存数据发生变化时立即更新,而无需等待常规的缓存刷新周期。这可以使信息保持准确和最新。

¥On-demand cache invalidation lets applications instantly update specific cached data when it changes, instead of waiting for regular cache refresh cycles. This keeps information accurate and up-to-date for users.

何时应该使用缓存失效 API?

¥When should I use the cache invalidate API?

当数据一致性无法等待缓存的标准过期或重新验证时,缓存失效 API 至关重要。主要用例包括:

¥The cache invalidate API is essential when data consistency cannot wait for the cache’s standard expiration or revalidation. Key use cases include:

  • 内容更新:当发生需要立即可见的关键更改(例如对已发布文章的编辑、产品更新或配置文件修改)时。

    ¥Content updates: When critical changes occur, such as edits to a published article, product updates, or profile modifications, that need to be visible immediately.

  • 库存管理:在实时应用中,例如库存或预订系统,库存水平、可用性或预订状态必须反映最新信息。

    ¥Inventory management: In real-time applications, like inventory or booking systems, where stock levels, availability, or reservation statuses must reflect the latest information.

  • 高优先级数据:对于时间敏感的数据,例如突发新闻或紧急通知,用户必须立即查看最新信息。

    ¥High-priority data: For time-sensitive data, like breaking news or urgent notifications, where it’s essential for users to see the most current information right away.

在这些情况下使用按需缓存失效有助于仅刷新必要的数据,从而保持系统性能,同时确保为用户提供准确、最新的信息。

¥Using on-demand cache invalidation in these scenarios helps keep only the necessary data refreshed, preserving system performance while ensuring accurate, up-to-date information for users.

连接池

¥Connection pooling

我可以增加 Prisma Postgres 实例的查询时长和响应大小限制吗?

¥Can I increase the query duration and response size limits for my Prisma Postgres instance?

是的,你可以根据你的订阅计划增加 Prisma Postgres 的限制。以下是可配置的限制:

¥Yes, you can increase your Prisma Postgres limits based on your subscription plan. Here are the configurable limits:

限制入门专业版计划商业计划
查询超时最多 10 秒最多 20 秒最多 60 秒
交互式事务超时最多 15 秒最多 30 秒最多 90 秒
响应大小最多 5 MB最多 10 MB最多 20 MB

查看 定价页面 文档,了解更多关于可用方案及其相应限制的详细信息。

¥Check the pricing page for more details on the available plans and their corresponding limits.

警告

虽然你可以根据你的订阅方案增加这些限制,但仍然建议你优化数据库操作。在我们的故障排除指南中了解更多信息。

¥While you can increase these limits based on your subscription plan, it's still recommended to optimize your database operations. Learn more in our troubleshooting guide.

查询优化

¥Query optimization

Prisma Postgres 允许通过 Prisma 优化 进行查询优化,并提供性能建议,以帮助你在开发过程中改进数据库查询。你可以使用 Prisma Postgres 或 也可与你自己的数据库一起使用 启用它,但设置和集成步骤有所不同。

¥Prisma Postgres allows query optimization via Prisma Optimize and provides performance recommendations to help improve your database queries during development. You can enable it with Prisma Postgres or also use it with your own database, but setup and integration steps differ.

你们可以自动实现优化吗?

¥Can you automatically implement optimizations?

Prisma Postgres 的查询优化功能提供了有关如何改进数据库查询的见解和建议。它不会更改任何现有查询或你的 Prisma 模式。

¥Prisma Postgres's query optimization feature offers insights and recommendations on how to improve your database queries. It does not alter any existing queries or your Prisma schema.

录制会话会保留多长时间?

¥How long is a recording session retained?

存储保留期没有限制。查询性能记录会话将被存储,直到你明确删除它。

¥There are no limits on the storage retention period. A query performance recording session will be stored until you explicitly delete it.

推荐限制每月都会重置吗?

¥Do recommendation limits reset monthly?

是的,建议使用量会在每个日历月初重置。例如,如果你在月底前使用了 5 的建议,你的使用量将在下月初重置为 0

¥Yes, the recommendation usage resets at the beginning of each calendar month. For example, if you use 5 recommendations by the end of the month, your usage will reset to 0 at the start of the next month.

超出入门计划的建议限制会被收费吗?

¥Can I get charged for exceeding the recommendation limit on the starter plan?

是的,如果你使用的是入门套餐,在一个计费周期内超过 5 的建议用量将导致在该周期结束时产生 $5 费用。更多信息,请访问 我们的定价页面

¥Yes, if you’re on the starter plan, exceeding 5 recommendations in a billing cycle will result in a $5 charge at the end of that cycle. For more information, visit our pricing page.

如何跟踪 Prisma AI 建议以进行计费?它们是基于生成的推荐还是查看的推荐进行计数的?

¥How are viewed Prisma AI recommendations tracked for billing? Are they counted based on generated or viewed recommendations?

它们根据已查看的推荐进行计数。点击建议表中的某条建议并查看其详情页面后,该建议即被视为已查看。

¥They are counted based on viewed recommendations. Once you click on a recommendation from the recommendations table and view the recommendation's detail page, it counts as being seen.

我可以在生产环境中为 Prisma Postgres 启用查询优化吗?

¥Can I enable query optimizations for Prisma Postgres in production?

不,Prisma Postgres 的查询优化不适用于生产环境。它专为本地开发而设计,可在该阶段提供宝贵的见解和优化。虽然从技术上讲,可以在生产环境中运行它,但这样做可能会导致性能问题或意外行为,因为它并非为处理生产工作负载的复杂性和规模而构建。为了获得最佳体验,我们建议仅在你的开发环境中测试查询优化。

¥No, query optimizations for Prisma Postgres is not meant to be enabled for production use. It is specifically designed for local development, providing valuable insights and optimizations during that phase. While it's technically possible to run it in a production environment, doing so could result in performance problems or unexpected behaviors, as this is not built to handle the complexity and scale of production workloads. For the best experience, we recommend testing query optimization solely in your development environment.

你可以使用客户端扩展中的 enable 属性来运行 仅限开发环境。默认情况下,enable 属性设置为 true

¥You can use the enable property in the client extension to run it only in development environment. By default, the enable property is set to true.

script.ts
import { PrismaClient } from '@prisma/client'
import { withOptimize } from "@prisma/extension-optimize"

const prisma = new PrismaClient().$extends(
withOptimize({
apiKey: process.env.OPTIMIZE_API_KEY,
enable: process.env.ENVIRONMENT === 'development',
})
);

为什么我会看到“[optimize] HTTP 409 冲突:“没有活动记录可供写入查询”警告?

¥Why do I see "[optimize] HTTP 409 Conflict: There is no active recording to write queries to" warning?

当 Prisma Optimize 收到查询但没有活动的记录会话时,可能会出现此警告。通常,如果你在生产环境中无意中启用了 Prisma Optimize,就会发生这种情况。Prisma Optimize 专为本地开发环境设计,不应在生产环境中启用。为避免出现此警告,请确保将 Prisma Optimize 配置为仅在开发期间运行。

¥This warning may occur when Prisma Optimize receives queries but no recording session is active. Typically, this can happen if Prisma Optimize is unintentionally enabled in your production environment. Prisma Optimize is specifically designed for use in local development environments and should not be enabled in production. To avoid this warning, ensure that Prisma Optimize is configured to run only during development.

如果你在开发环境中看到此警告,请确保你已在 Prisma Optimize 仪表板中启动了记录会话。

¥If you are seeing this warning in your development environment, ensure that you have started a recording session in the Prisma Optimize Dashboard.