Updated on 2025-12-12 GMT+08:00

CREATE RESOURCE POOL

Function

CREATE RESOURCE POOL creates a resource pool and specifies the Cgroup for the resource pool. The system resources (CPU, memory, I/O, and storage resources) of a database are limited. When multiple types of services (such as data loading, batch analysis, and real-time query) are running at the same time, they may compete for resources and hinder operations. As a result, the throughput decreases and the overall performance deteriorates. Allocating system resources correctly prevents efficiency loss due to poor resource use. DWS offers a resource management feature that lets you create separate resource pools for different needs. These pools keep resources independent from one another.

This syntax is for reference only. You are advised to create a resource pool on the console. For details about resource pools, see "DWS Resource Load Management" in the User Guide.

Precautions

As long as the current user has CREATE permission, it can create a resource pool.

Syntax

1
2
CREATE RESOURCE POOL pool_name
    [WITH ({MEM_PERCENT=pct | CONTROL_GROUP="group_name" | ACTIVE_STATEMENTS=stmt | MAX_DOP = dop | MEMORY_LIMIT='memory_size' | io_limits=io_limits | io_priority='priority' | nodegroup='nodegroup_name' | is_foreign = boolean | except_rule='except_rule' | weight=bandwidth_weight | enable_concurrency_scaling=boolean}[, ... ])];

Parameter Description

Table 1 CREATE RESOURCE POOL parameters

Parameter

Description

Value Range or Example

pool_name

Specifies the name of a resource pool.

The name of a resource pool cannot be same as that of an existing resource pool.

A string, which must comply with the identifier naming convention.

CONTROL_GROUP

Specifies the name of a Cgroup.

Control groups (Cgroups) are a mechanism provided by the Linux kernel to restrict, record, and isolate physical resources (such as CPU, memory, and I/O resources) used by process groups. Cgroups have strict restrictions on Linux system resources. If a process is added to a Cgroup, it can use only restricted resources. For details about Cgroup principles, see the product manual corresponding to your OS.

The DefaultClass Cgroup is preset in the environment, and the Timeshare Cgroup under the DefaultClass is divided into the following four levels: Rush, High, Medium, and Low.

  • You can use either double quotation marks ("") or single quotation mark ('') in the syntax when setting the name of a Cgroup.
  • The value of group_name is case-sensitive.
  • If group_name is not specified, the string "Medium" will be used by default in the syntax, indicating the Medium Timeshare Cgroup under DefaultClass.

Create a default resource pool, and associate it with the Medium Timeshare Workload Cgroup under DefaultClass.

1
CREATE RESOURCE POOL pool1;

Create a resource pool, and associate it with the High Timeshare Workload Cgroup under DefaultClass.

1
CREATE RESOURCE POOL pool2 WITH (CONTROL_GROUP="High");

ACTIVE_STATEMENTS

Specifies the maximum number of complex statements that can be concurrently executed in a resource pool. The value is a number ranging from -1 to INT_MAX. If this parameter is not specified, the default value 10 is used.

Create pool3 and set the maximum number of complex statements that can be concurrently executed to 5, the memory usage to 50%, and the network weight to 5.

1
CREATE RESOURCE POOL pool3 WITH (ACTIVE_STATEMENTS=5, MEM_PERCENT=50, weight=5);

MAX_DOP

Specifies the maximum number of simple SQL statements that can be concurrently executed in a resource pool. The value is a number ranging from -1 to INT_MAX. The value -1 or 0 indicates that the maximum number of statements is not limited. If the value is not specified, the default value -1 is used.

Create pool4 and set the maximum number of concurrent simple SQL statements to 10.

1
CREATE RESOURCE POOL pool4 WITH (MAX_DOP=10);

MEMORY_LIMIT

Specifies the estimated maximum memory for a resource pool.

A string.

  • default: The memory limit is half of the resource pool memory.
  • unlimited: no limit.
  • The value is from 1 KB to 2047 GB.

If this parameter is not specified, default is used.

-

MEM_PERCENT

Specifies the proportion of available resource pool memory to the total memory or group user memory.

  • The value ranges from 0 to 100. The default value is 0.

-

io_limits

This parameter has been discarded in 8.1.2 and is reserved for compatibility with earlier versions.

-

io_priority

This parameter has been discarded in 8.1.2 and is reserved for compatibility with earlier versions.

-

nodegroup

Specifies the name of a logical cluster where the resource pool is. The logical cluster must already exist.

If the logical cluster name contains uppercase letters or special characters or begins with a digit, enclose the name with double quotation marks in SQL statements.

is_foreign

In logical cluster mode, the current resource pool is used to control the resources of common users who are not associated with the logical cluster specified by nodegroup.

  • nodegroup must specify an existing logical cluster, and cannot be elastic_group or the default Node Group (group_version1), which is generated during cluster installation.
  • If is_foreign is set to true, the resource pool cannot be associated with users. That is, CREATE USER... RESOURCE POOL cannot be used to configure resource pools for users. The resource pool automatically checks whether the users are associated with its logical cluster. If they are not, they will be controlled by the resource pool when performing operations on DNs in the logical cluster.

except_rule

Name of an exception rule set.

An exception rule set is a set of rule thresholds that define the job execution time, job queuing time, CPU usage, and maximum disk flushing. It is used together with a resource pool. When an exception rule is triggered during job execution, the job is terminated or degraded.

For more information, see CREATE EXCEPT RULE.

Example: Create an exception rule to terminate a job when the job runs for more than 10 seconds.

weight

Specifies the network bandwidth weight of the resource pool. The value is an integer ranging from -1 to 2147483647. The default value is -1, indicating that no weight is set.

-

enable_concurrency_scaling

Specifies whether to enable the elastic concurrency expansion function. This function is supported only by clusters of version 9.1.0.100 or later.

  • true indicates that the elastic concurrent expansion function of jobs in the resource pool is enabled.
  • false indicates that the elastic concurrent expansion function of jobs in the resource pool is disabled.

The default value is false.

Examples

This example assumes that Cgroups have been created by users in advance.

Create a default resource pool, and associate it with the Medium Timeshare Workload Cgroup under DefaultClass.

1
CREATE RESOURCE POOL pool1;

Create a resource pool, and associate it with the High Timeshare Workload Cgroup under DefaultClass.

1
CREATE RESOURCE POOL pool2 WITH (CONTROL_GROUP="High");

Create pool_p and set the maximum number of complex statements that can be concurrently executed to 5, the memory usage to 50%, and the network weight to 5.

1
CREATE RESOURCE POOL pool_p WITH (ACTIVE_STATEMENTS=5, MEM_PERCENT=50, weight=5);

Query the configuration parameters of the resource pool in the PG_RESOURCE_POOL system catalog.

1
SELECT * FROM PG_RESOURCE_POOL WHERE respool_name = 'pool_p';

Create an exception rule set except_rule4, set elapsedtime to 10 (unit: seconds), and create a resource pool and bind the exception rule to the resource pool.
1
2
CREATE EXCEPT RULE except_rule4 WITH (elapsedtime=10);
CREATE resource pool resource_pool_a4 WITH (except_rule='except_rule4');

Create a resource pool and enable the elastic concurrent expansion function of the resource pool.

1
CREATE RESOURCE POOL pool6 WITH (enable_concurrency_scaling=true);

Example: Create an exception rule to terminate a job when the job runs for more than 10 seconds.

In DWS resource load management, exception rules take effect only after being bound to a resource pool, and then the user who executes a job is bound to a specified resource pool. If an exception rule is triggered when a user executes a job, the job will be terminated. Perform the following operations to simulate the termination process.

  1. Create a test table and import data to the table.

    1. Connect to the database as the system administrator and run the following SQL statements to create temporary table src to provide data sources for subsequent INSERT operations:
      1
      2
      CREATE SCHEMA test;
      CREATE TABLE test.src AS SELECT 1;
      
    2. Run the following SQL statements to create table test.test:
      1
      2
      DROP TABLE IF EXISTS test.test;
      CREATE TABLE test.test(a int, b numeric(15,2)) WITH(orientation=column);
      
    3. Run the SQL statements to insert 20 million rows of data into the two tables. It takes about half a minute. Please wait.
      1
      INSERT INTO test.test SELECT generate_series(1,20000000) % 1000,generate_series(1,20000000) FROM test.src;
      

  2. Create exception rule set except_rule4 and set elapsedtime to 10 seconds.

    1
    CREATE EXCEPT RULE except_rule4 WITH (elapsedtime=10);
    

  3. Create resource pool resource_pool_a4 and bind the exception rule to it.

    1
    CREATE resource pool resource_pool_a4 WITH (except_rule='except_rule4');
    

  4. Create a job user and bind the user to resource_pool_a4. The password is configured as required.

    1
    CREATE USER user4 RESOURCE POOL 'resource_pool_a4' PASSWORD 'password';
    

  5. Grant the permission to access table test.test to user4.

    1
    2
    GRANT USAGE ON SCHEMA test TO user4;
    GRANT SELECT ON TABLE test.test TO user4;
    

  6. Connect to the database as user4 and run the following SQL statement. Once the statement is executed for more than 10 seconds, it is terminated.

    1
    SELECT * FROM test.test;
    

  7. Check exception rule definitions in the PG_EXCEPT_RULE system catalog.

    1
    SELECT * FROM PG_EXCEPT_RULE WHERE name = 'except_rule4';