tencent cloud

TencentDB for PostgreSQL

database Resource Isolation

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-09-08 10:21:59
AI 번역

Scenarios

In some business scenarios, a database object corresponds to specific business logic. For example, in SaaS scenarios, a database corresponds to a tenant, so database resource isolation is required. This document describes how to implement CPU isolation for databases in TencentDB for PostgreSQL instances, along with the monitoring, migration, and auditing solutions provided by the management system, to meet flexible tenant and resource management requirements.

Setting database Resource Isolation

Note:
Resource isolation is supported only on PostgreSQL 14, 15, and 16 kernel versions v14.11_r1.21, v15.6_r1.10, and v16.2_r1.3 or later. For details, see Kernel Version Updates.
To enable database resource isolation, submit a ticket to contact us for enabling the tencentdb_serverless plugin and configuring the relevant parameters.
The tencentdb_serverless.min_cpu_cores parameter specifies the minimum number of CPU cores that can be configured for an instance, and the tencentdb_serverless.max_cpu_cores parameter specifies the maximum number of CPU cores that can be configured for an instance. These two parameters are mainly used by the backend management system to control resource isolation for databases in an instance. Users can view but do not need to modify them.
All CPU resource settings take effect in real time.
Currently, database resource isolation can only be enabled on primary instances.
After you have enabled the tencentdb_serverless plugin and configured the plugin parameters tencentdb_serverless.min_cpu_cores and tencentdb_serverless.max_cpu_cores, you can start the configuration. You can run the following command to check whether the plugin has been installed successfully:
postgres=> \\dx;
List of installed extensions
Name | Version | Schema | Description
-----------------------+---------+------------+------------------------------------------------------------------------
pg_stat_log | 1.0 | public | track runtime execution statistics of all SQL statements executed
pg_stat_statements | 1.9 | public | track planning and execution statistics of all SQL statements executed
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
tencentdb_serverless | 1.0 | public | extension for serverless mode
tencentdb_system_stat | 1.0 | public | track execution statistics of querssy executed
(5 rows)
The initial values of the tencentdb_serverless.min_cpu_cores and tencentdb_serverless.max_cpu_cores parameters are the current number of CPU cores of the instance. These two parameters are mainly used by the backend management system to control resource isolation for databases in an instance, and users do not need to modify them. If the instance configuration is adjusted later, these two parameters will change accordingly. You can run the following command to check the current values of the parameters.
postgres=> show tencentdb_serverless.min_cpu_cores;
tencentdb_serverless.min_cpu_cores
------------------------------------
8
(1 row)

postgres=> show tencentdb_serverless.max_cpu_cores;
tencentdb_serverless.max_cpu_cores
------------------------------------
8
(1 row)
Note:
When there are multiple database objects in the instance, a CPU resource limit needs to be set for each database for the configuration to take effect.
After the plugin and parameters are checked, you can start to set the upper and lower CPU resource limits for databases. We provide corresponding functions or views for you to call, which are described as follows:

Setting CPU Resource Limits for a Specific database

The function is defined as follows:
tencentdb_serverless.set_database_cpu_limit(database_name text [, min_cpu_cores numeric(5,1), max_cpu_cores numeric(5,1)])
Call example:
postgres=> select tencentdb_serverless.set_database_cpu_limit('tenant_001',2,2.5);
set_database_cpu_limit
------------------------
(1 row)

Clearing CPU Resource Limits for a Specific database

The function is defined as follows:
tencentdb_serverless.reset_database_limit(database_name text)
Call example:
postgres=> select tencentdb_serverless.reset_database_limit('tenant_001');
reset_database_limit
----------------------
(1 row)
Clear the CPU resource limits for all databases in the instance.
The function is defined as follows:
tencentdb_serverless.reset_all_database_limit()
Call example:
postgres=> select tencentdb_serverless.reset_all_database_limit();
reset_all_database_limit
--------------------------
(1 row)
View the details of all configured CPU resource limits in the current instance.
We provide the view tencentdb_serverless.resource_limit_view for you to view the details of all configured CPU resource limits in the current instance. The fields are defined as follows:
Column Name
Description
database_name
Database name
min_cpu_cores
Minimum CPU cores available to the current database
max_cpu_cores
Maximum CPU cores available to the current database
min_mem_kilobytes
Maximum memory size available to the current database, in kB. Reserved field, not in use yet.
max_mem_kilobytes
Maximum memory size available to the current database, in kB. Reserved field, not in use yet.
Call example:
postgres=> select * from tencentdb_serverless.resource_limit_view;
database_name | min_cpu_cores | max_cpu_cores | min_mem_kilobytes | max_mem_kilobytes
---------------+---------------+---------------+-------------------+-------------------
tenant_001 | 2.0 | 2.5 | |
tenant_002 | 2.0 | 2.5 | |
(2 rows)

Process Monitoring

After CPU resource isolation is configured for all databases in the instance, if the overall resource utilization of the instance is relatively high, each database can be guaranteed to use the minimum configured number of CPU cores. In addition, if you need to check which databases in the current system are using more resources, you can use the process monitoring capability. You can use the following statement to view the CPU resource usage details of all databases:
postgres=> select datname,sum(cpu_usage) as cpu_usage from tencentdb_process_system_usage where datname !='NULL' group by datname;
datname | cpu_usage
------------+-----------
postgres | 3
tenant_001 | 1.99
tenant_002 | 1
(3 rows)
When process monitoring detects that the resource utilization of certain databases is relatively high, you can adjust the CPU configuration of those databases in real time, and the configuration can take effect immediately.

Resource Migration

When a database corresponds to a tenant and process monitoring shows that the database's resource usage remains consistently high and requires resource rebalancing, TencentDB for PostgreSQL provides data migration capabilities. You can configure logical migration for TencentDB for PostgreSQL. The following figure shows how to configure a migration task:


Disabling database Resource Isolation

If you need to disable CPU resource isolation for a database, submit a ticket to contact us for data cleanup. After receiving the ticket, backend engineers will reset all CPU resource parameters, tencentdb_serverless.min_cpu_cores and tencentdb_serverless.max_cpu_cores, remove all resource configurations, and finally delete the tencentdb_serverless plugin.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백