High memory usage in Postgres is good, actually
Blog post from PlanetScale
High memory usage in Postgres, particularly in the context of caching, is often indicative of a healthy and efficient system rather than a problem. Unlike high CPU usage, which can lead to bottlenecks and increased latency, high memory usage primarily reflects the database's ability to keep frequently accessed data in RAM, thus reducing the need for slower disk reads. Postgres utilizes two primary layers of caching: its own buffer pool, shared_buffers, and the operating system's page cache, both of which aim to minimize expensive disk operations. However, memory usage can become problematic when Resident Set Size (RSS) increases due to inefficient memory allocation, poorly configured extensions, or excessive concurrent connections, potentially leading to out-of-memory events and degraded performance. Understanding the difference between cache-related memory usage and process memory can help diagnose performance issues, and tools like Query Insights can assist in identifying patterns that contribute to high RSS. Ultimately, monitoring and managing the types of memory usage is crucial to maintaining a performant Postgres database.