Skip to content
Platform

性能调优

Supabase 平台会自动优化你的 Postgres 数据库,以充分利用你项目所在计划的计算资源。不过,这些优化是基于对项目使用的工作流程类型的假设,所以针对你具体的工作流程对数据库进行调优可能会得到更好的效果。

🌐 The Supabase platform automatically optimizes your Postgres database to take advantage of the compute resources of the plan your project is on. However, these optimizations are based on assumptions about the type of workflow the project is being used for, and it is likely that better results can be obtained by tuning the database for your particular workflow.

检查查询性能 #

🌐 Examining query performance

未优化的查询是数据库性能差的主要原因。要分析查询的性能,请参阅调试和监控指南

🌐 Unoptimized queries are a major cause of poor database performance. To analyze the performance of your queries, see the Debugging and monitoring guide.

优化连接数量 #

🌐 Optimizing the number of connections

Postgres 和 Supavisor 的默认连接限制是根据你的计算大小来设定的。查看 Compute Add-ons 部分了解默认连接数量。

🌐 The default connection limits for Postgres and Supavisor is based on your compute size. See the default connection numbers in the Compute Add-ons section.

如果连接数不足,连接数据库时你会收到以下错误:

🌐 If the number of connections is insufficient, you will receive the following error upon connecting to the DB:

1
$ psql -U postgres -h ...
2
FATAL: remaining connection slots are reserved for non-replication superuser connections

在这种情况下,你可以考虑:

🌐 In such a scenario, you can consider:

配置客户端以使用更少的连接 #

🌐 Configuring clients to use fewer connections

你可以使用 pg_stat_activity 视图来调试哪些客户端在你的数据库上保持着打开的连接。pg_stat_activity 只显示数据库的直接连接信息。有关连接到 Supavisor 的数量信息,可以通过 指标端点 获取。

🌐 You can use the pg_stat_activity view to debug which clients are holding open connections on your DB. pg_stat_activity only exposes information on direct connections to the database. Information on the number of connections to Supavisor is available via the metrics endpoint.

根据所涉及的客户端,你可能可以配置它们以使用更少的连接(例如,通过限制它们允许使用的最大连接数),或者将特定工作负载改为通过 Supavisor 连接。临时工作流(可以根据流量快速扩展和收缩,例如无服务器函数)尤其可以通过使用连接池而不是直接连接数据库来获益。

🌐 Depending on the clients involved, you might be able to configure them to work with fewer connections (e.g. by imposing a limit on the maximum number of connections they're allowed to use), or shift specific workloads to connect via Supavisor instead. Transient workflows, which can scale up and down rapidly in response to traffic (e.g. serverless functions), can especially benefit from using a connection pooler rather than connecting to the DB directly.

允许更多连接 #

🌐 Allowing higher number of connections

你可以通过使用 自定义 Postgres 配置 来设置 Postgres 连接数限制以及其他参数。

🌐 You can configure Postgres connection limit among other parameters by using Custom Postgres Config.

企业 #

🌐 Enterprise

如果你需要针对你的具体工作流程优化数据库,联系我们