Skip to content

High RAM usage

基础内存使用 #

🌐 Base memory usage

即使你的数据库几乎没有负载,你可能也会注意到内存使用率偏高。Supabase 除了 Postgres 之外,还需要许多其他服务来运行,这可能导致基础内存使用率较高。尤其是在只有 1 GB 内存的最小计算实例上,你的项目基础内存使用率达到约 50% 是很正常的。

🌐 You may observe elevated memory usage even when your database has little to no load. Supabase requires a wide range of services other than Postgres to operate, which can result in an elevated base memory usage. Especially on the smallest compute instance that comes with 1 GB of RAM, it is not unusual for your project to have a base memory usage of ~50%.

内存使用过高的问题 #

🌐 Issues with high memory usage

每个 Supabase 项目都运行在它自己的专用虚拟机中。你的实例会根据你的计算附加组件配置不同的硬件。根据你的工作量,你的计算硬件可能不适合,从而导致高 RAM 使用率。

🌐 Every Supabase project runs in its own dedicated virtual machine. Your instance will have a different set of hardware provisioned depending on your compute add-on. Depending on your workload, your compute hardware may not be suitable and can result in high RAM usage.

判断内存使用不健康的一个好指标是交换分区使用情况。如果你的 RAM 用完了,系统会把内存内容转到磁盘上那个速度慢得多的交换分区。如果你的交换分区使用率超过 70%,很可能你的计算硬件不适合你的工作负载。去你项目的 数据库健康 查看你的交换分区使用情况吧。

🌐 A good proxy for unhealthy memory usage is swap usage. If you run out of RAM, your system will offload memory to your disk's much slower swap partition. If your swap is above 70%, chances are high that your compute hardware is not suitable for your workload. Head over to your project's Database Health to see your swap usage.

高内存使用可能会带来一系列问题:

🌐 High RAM usage could come with a range of issues:

  • 当你的实例必须使用交换内存时,整体性能会下降
  • 当你的系统内存不足时,操作系统可能会开始终止进程
  • 在极少数情况下,你的实例可能会无响应

监控你的内存 #

🌐 Monitor your RAM

要在 Supabase 平台上查看你的 RAM 使用情况,前往 Observability 部分的数据库健康

🌐 To check your RAM usage on the Supabase Platform, head over to Database Health in the Observability section.

也可以使用 Prometheus/Grafana 来监控你的资源并设置警报。使用 Grafana,你可以看到有多少 RAM 被用于缓存,还可以跟踪其他指标,比如 Swap 使用情况。阅读 Metrics Guide 了解更多信息。

🌐 It is also possible to monitor your resources and set up alerts using Prometheus/Grafana. With Grafana you will be able to see how much of your RAM is used for caching and you can track other metrics such as your Swap usage. Read the Metrics Guide to learn more.

高内存使用率的常见原因 #

🌐 Common reasons for high RAM usage

你在 Supabase 项目中做的每件事都以某种形式消耗内存。因此,导致高内存使用率的原因可能有很多。这里是一些常见的原因:

🌐 Everything you do with your Supabase project requires memory in some form. Hence, there can be many reasons for high RAM usage. Here are some common ones:

  • 查询性能: 执行时间很长的查询(>1秒)可能没有效率地使用你的内存。查看我们关于检查查询性能的指南。
  • 连接太多: 连接到数据库的每一个连接都会消耗内存。你可以在选择项目后,进入数据库角色查看活动连接的数量。阅读我们的指南了解过多打开的连接
  • 扩展: 一些扩展比如 timescaledbpg_cron 可能会占用大量内存。当你运行太多扩展时,这个占用也会累积。你可以在仪表板的 扩展 中管理你的数据库扩展。

如何解决你的记忆问题 #

🌐 How to fix your memory issues

  1. **升级你的计算能力:**你可以为你的项目获取计算附加组件。通过选择你的项目查看你的升级选项
  2. **优化性能:**通过优化使用方式,充分利用实例的资源。看看我们的性能调优指南生产就绪指南