Memory diagnosis
When a PolarDB for PostgreSQL (Compatible with Oracle) cluster shows elevated memory usage, use the two built-in diagnosis methods to pinpoint the source: regular memory diagnosis identifies which backend processes consume the most physical memory and drills down to individual memory contexts within a process; shared memory diagnosis shows how the shared memory pool is distributed across system components.
Prerequisites
Before you begin, ensure that you have:
A running PolarDB for PostgreSQL (Compatible with Oracle) cluster
The
polar_monitorextension enabled (installed by default; see Enable the polar_monitor extension if it is not active)
Regular memory diagnosis
Regular memory diagnosis identifies memory usage at the process level and, when needed, drills down into individual memory contexts within a process.
Enable the polar_monitor extension
The polar_stat_activity_rt view requires the polar_monitor extension. This extension is installed by default. If it is not active, run:
CREATE EXTENSION polar_monitor;Identify high-memory processes
Query polar_stat_activity_rt to list backend processes sorted by Resident Set Size (RSS) in descending order, refreshed every second:
SELECT pid, rss
FROM polar_stat_activity_rt
ORDER BY rss DESC;
\watch 1| Column | Description |
|---|---|
pid | Process ID of the backend |
rss | Resident Set Size — the amount of physical memory currently held by the process |
How to interpret the results: A process with a significantly larger rss than others is a candidate for further investigation. Note the pid value and use polar_backends_mcxt to identify the memory context responsible.
Drill down into memory contexts
Once you identify a high-memory process, use polar_backends_mcxt to identify which memory context within that process consumes the most memory.
Detailed documentation for memory contexts in PolarDB for PostgreSQL (Compatible with Oracle) is not yet available. For further analysis, use kernel code or SQL.
Shared memory diagnosis
Use polar_stat_shmem to view the shared memory distribution.