Understanding Memory Usage in PlanetScale: Cache vs. Process Memory
Patch your PlanetScale cluster to monitor RSS and shared_buffers, adjust work_mem, and keep cache usage high while RSS stays below threshold.
Patch your cluster configuration to set work_mem appropriately, monitor RSS via dashboard, and keep cache usage high while keeping RSS below threshold.
Summary
The article explains that the memory usage figure shown in the PlanetScale dashboard is a combination of active cache, inactive cache, RSS, and memory‑mapped pages, not just Postgres data. Active cache is reclaimable by the OS and indicates that frequently accessed data is kept close to the CPU, which is healthy for performance. RSS, or Resident Set Size, represents non‑reclaimable memory used by Postgres processes and is the main indicator of out‑of‑memory risk. The author clarifies that high memory usage can be healthy if cache dominates, but high RSS signals memory pressure. Postgres uses two caching layers: its own shared_buffers pool and the OS page cache, both of which consume RAM. The work_mem parameter, defaulted relative to cluster memory, can be tuned to control per‑query memory allocation, but setting it too low forces disk spills while setting it too high increases RSS. The article recommends monitoring metrics via the PlanetScale dashboard, checking the 'Normal operating ranges' documentation, and ensuring that cache usage stays high while RSS remains low. Understanding the distinction between cache and process memory helps prevent unnecessary restarts and performance degradation.
Key changes
- Memory usage shown combines active cache, inactive cache, RSS, and memory‑mapped pages.
- Active cache is reclaimable by OS and indicates healthy caching.
- RSS is non‑reclaimable and signals OOM risk.
- Postgres uses shared_buffers and OS page cache, both consuming RAM.
- work_mem default is relative to cluster memory and can be tuned per query.
- Tuning work_mem too low forces disk spills; too high increases RSS.
- Monitoring via PlanetScale dashboard and checking normal operating ranges is recommended.
- High memory usage can be healthy if cache dominates, but high RSS indicates memory pressure.