Interpreting Supabase Grafana Memory Charts
这里是内存使用不健康的例子:
🌐 Here are examples of unhealthy memory usage:
- 黄色:表示活跃的记忆
- 红色:表示 SWAP,它是系统当作内存使用的磁盘存储
- 绿色:未被占用(系统总会保留一些未占用的内存)
- 蓝色:它是缓存数据和一个缓冲区
Postgres 中的缓存很重要,因为数据库会把经常访问的数据存储在里面以便快速获取。如果需要太多活动内存,就有可能过度挤占缓存。这会迫使查询去检查磁盘,这会很慢。
🌐 The cache in Postgres is important because the database will store frequently accessed data in it for rapid retrieval. If too much active memory is needed, it runs the risk of excessively displacing cache. This will force queries to check disk, which is slow.
数据库中的大部分数据都是闲置的,但在内存很少或未缓存的数据被频繁访问的情况下,可能会发生抖动。
理想情况下,你希望查询命中缓存的次数达到99%。你可以使用 Supabase CLI 的 inspect db cache hit 命令来检查缓存命中率。或者,你也可以在 SQL 编辑器 中运行在 CLI 的 GitHub 仓库里找到的 查询。
🌐 Ideally, you want queries to hit the cache 99% of the time. You can use the Supabase CLI inspect db cache hit command to check your cache hit rate. Alternatively, you can run the query found in the CLI's GitHub repo in the SQL Editor
1# login to the CLI2npx supabase login34# initlize a local supabase directory5npx supabase init67#link your project8npx supabase link910# find cache hit rate11npx supabase inspect db cache-hit --linked如果缓存命中率开始低于理想水平,就应该考虑采取以下措施:
🌐 If the cache hit rate begins to drop below the ideal amount, one should consider taking the following actions:
优化中:
🌐 Optimizing:
- 应用索引:可以减少从磁盘加载到内存的数据量
- 增加计算规模
- 通过使用只读副本分配负载
- 分区:通常应在非常大的表上使用,以尽量减少从磁盘调入内存的数据
- 清理冗余:冗余数据可能会把数据分散到各个页面上,导致从磁盘读取重复数据。
- 表格重构:把表拆开,把那些不常访问的列隔离出来,这样在访问更热门的数据时,它们就不会被多余地加载到内存里
其他有用的 Supabase Grafana 指南: #
🌐 Other useful Supabase Grafana guides: