The process-level cache eviction feature is supported to reduce the memory usage of persistent connections and ensure that your database does not run out of memory due to excessive persistent connections. The feature uses the Least Recently Used (LRU) policy to release caches that are infrequently used. This reduces the memory usage of connections and improves the stability of ApsaraDB RDS for PostgreSQL instances.
Prerequisites
The RDS instance runs PostgreSQL 11 or later. If the feature is still not supported, you must update the minor engine version of the RDS instance. For more information, see Update the minor engine version.
Background information
Each time a backend process in PostgreSQL accesses a table, the metadata of the table is cached to your on-premises device, and the cache is not proactively released. This reduces subsequent disk access. As a result, persistent connections may generate a large number of caches and cause out of memory (OOM) errors. To resolve this issue, the cache eviction feature is introduced to release the caches that are infrequently used at the earliest opportunity.
Scenarios
Software as a service (SaaS) scenarios in which a large number of persistent connections exist
Impacts
The modification of the parameters that are involved in this topic does not trigger instance restart.
Usage notes
To ensure that your RDS instance runs as expected, some caches cannot be evicted. In extreme cases, the specified upper limit on caches cannot be fully met.
Procedure
The connection caches of ApsaraDB RDS for PostgreSQL consist of the following caches: relcache
, syscache
, and plancache
. relcache is used to cache the metadata of user tables. syscache is used to cache the tuples of system tables. plancache is used to cache user-defined execution plans. ApsaraDB RDS for PostgreSQL allows you to adjust the numbers of objects that can be cached in relcache
and syscache
. The number of objects that can be cached in plancache
cannot be limited.
If you want to monitor the cache usage of each process, you must execute the CREATE EXTENSION rdsutils
statement to install a dependent extension and set the value of the rds_enable_cache_monitor
parameter to on
.
If you set the
rds_enable_cache_monitor
parameter toon
, the database performance deteriorates, and the execution duration of each SQL statement is increased by approximately 2 milliseconds.You can modify the
rds_enable_cache_monitor
parameter only in the ApsaraDB RDS console. For more information, see Modify the parameters of an ApsaraDB RDS for PostgreSQL instance.
Modify the settings of the cache eviction feature for the current connection
-- Enable the eviction feature for relcache of the current connection to cache a maximum of 1,000 user tables.
SET rds_relcache_max_cached_relations = 1000;
-- Disable the eviction feature for relcache of the current connection.
SET rds_relcache_max_cached_relations = -1;
-- Enable the eviction feature for syscache of the current connection to cache the tuples of a maximum of 10,000 system tables.
set rds_syscache_max_cached_tuples = 10000;
-- Disable the eviction feature for syscache of the current connection.
set rds_syscache_max_cached_tuples = -1;
Configure the cache eviction feature for all connections
Log on to the ApsaraDB RDS console and configure the rds_relcache_max_cached_relations
and rds_syscache_max_cached_tuples
parameters. For more information, see Modify the parameters of an ApsaraDB RDS for PostgreSQL instance.
Parameters
Parameter | Description | Setting |
rds_enable_cache_monitor | Specifies whether to monitor the cache usage of each process. Valid values:
| You need to configure this parameter based on your business requirements. |
rds_relcache_max_cached_relations | The maximum number of user tables that can be cached for a single connection. Valid values: [-1, INT_MAX]. Default value: -1, which indicates that the number is not limited. |
|
rds_syscache_max_cached_tuples | The maximum number of tuples of system tables that can be cached for a single connection. Valid values: [-1, INT_MAX]. Default value: -1, which indicates that the number is not limited. |
|