Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

rds_pg_sql_ccl

Updated on 2025-01-02 GMT+08:00

Introduction

To prevent highly concurrent SQL statements that consume too many resources from causing instance instability, RDS for PostgreSQL provides rds_pg_sql_ccl, a Huawei-developed extension. ccl is short for concurrent control. SQL statement concurrency control can ensure instance stability, optimize performance, and guarantee resources for critical tasks in the following scenarios:

  • When workloads increase sharply, the instance stability is ensured by limiting the execution of a certain type of SQL statements.
  • When there are not enough resources, the success of core tasks is ensured by limiting the execution of other SQL statements to reduce resource consumption.

This extension provides two concurrency control methods:

  • Method 1: It limits the number of SQL statements that can be executed at the same time. This number is specified by the rds_pg_sql_ccl.max_concurrent_sql parameter. The default value is -1, indicating that the number is not limited.
  • Method 2: It limits the number of a certain type of SQL statements (with the same query ID) that can be executed at the same time. This number is specified by concurrency control rules. For details about concurrency control rules, see below.

Supported Versions

This extension is available to the latest minor versions of RDS for PostgreSQL 11.20, 12.15, 13.11, 14.8, 15.4, 16.2, and above. You can run the following SQL statement to check whether your DB instance supports this extension:

SELECT * FROM pg_available_extension_versions WHERE name = 'rds_pg_sql_ccl'; 

If this extension is not supported, upgrade the minor version of your DB instance or upgrade the major version using dump and restore.

To see more extensions supported by RDS for PostgreSQL, go to Supported Extensions.

Notes

SQL statement concurrency control rules must be configured based on workloads and resource usage.

Creating Rules

  1. In any given database, each rule must have a unique query ID, but rules in different databases can have the same query ID.
  2. A rule does not take effect immediately after being created. You need to call the enable_ccl_rule function to make it applied.
  3. The get_query_id function cannot obtain the query IDs of SQL statements using bind variables, and the add_ccl_rule_by_query function cannot limit the execution of such SQL statements.
  4. You can obtain the query ID of a SQL statement with bind variables using the pg_stat_statements extension. Then, you can use add_ccl_rule_by_queryid to create rules. For details, see "Concurrency Control for SQL Statements with Bind Variables".

How Rules Take Effect

  1. Method 1 limits the number of SQL statements that can be concurrently executed. Rules creating using this method take effect preferentially. On the basis of method 1, you can use method 2 to further limit concurrent execution of a specific type of SQL statements.
  2. After an instance reboot, none of the rules are applied.
  3. Read replicas synchronize the rules of the primary instance and call the enable_ccl_rule function to make the rules apply.
  4. A rule is only applied to SQL statements executed after the rule was enabled.

Concurrency Control for SQL Statements Without Bind Variables

Prerequisites:

  1. Install the kernel extension rds_pg_sql_ccl on the console or by running SQL statements.
    SELECT control_extension ('create', 'rds_pg_sql_ccl');
  2. Set kernel parameters.
    rds_pg_sql_ccl.enable_ccl = on

Then, perform the following operations:

  1. On the Instances page, click the instance name to go to the Overview page.
  2. In the navigation pane, choose DBA Assistant > Historical Diagnosis.
  3. Choose SQL Explorer > Concurrency Control.
  4. Toggle on the concurrency control switch.
  5. Click Add Rule and configure required parameters.
    Figure 1 Adding a concurrency control rule
    • Locate the rule and click Enable in the Operation column to enable the rule.
      Figure 2 Enabling a rule
    • To disable a rule, click Disable.
      Figure 3 Disabling a rule
    • To delete a rule, click Delete. After a concurrency control rule that is enabled is deleted, the rule is not applied anymore.
      Figure 4 Deleting a rule

Concurrency Control for SQL Statements with Bind Variables

Drivers such as JDBC support prepared statements. They precompile parameterized SQL statements and execute them after parameters are entered. In the pg_stat_statements view, the statements are displayed as bind variables. For SQL statements using bind variables, the query IDs calculated by the kernel are different from those of the same statements using actual parameter values. The concurrent execution of such statements cannot be limited by adding the statements.

Such SQL statements can only be limited by executing them first and then adding concurrency control rules.

  1. Execute a SQL statement with bind variables. In this way, the kernel calculates its query ID. An example of the JDBC-based prepared statement program is as follows:
    String sql = "select pg_sleep(?);";
    PreparedStatement preparedStatement = conn.prepareStatement(sql);
    preparedStatement.setInt(1, 500);
    ResultSet resultSet = preparedStatement.executeQuery();
  2. Query the query ID of the SQL statement in the pg_stat_statements view.
    select queryid from pg_stat_statements where query like '%select pg_sleep%';
  3. Add a concurrency control rule based on the query ID.
    select rds_pg_sql_ccl.add_ccl_rule_by_queryid($queryid);
  4. Enable the rule based on the return value (rule_id) of the previous SQL statement.
    select rds_pg_sql_ccl.enable_ccl_rule($rule_id);
  5. Obtain all rules applied from the get_all_enabled_rule view provided by the extension.
    select * from rds_pg_sql_ccl.get_all_enabled_rule;

Parameters

Table 1 Parameter description

Parameter

Data Type

Default Value

Maximum Value

Minimum Value

Description

rds_pg_sql_ccl.enable_ccl

bool

false

-

-

Whether to enable a concurrency control rule.

rds_pg_sql_ccl.max_enabled_rules

int

5000

500000

0

The number of rules that take effect at the same time.

rds_pg_sql_ccl.max_concurrent_sql

int

-1

50000

-1

The number of SQL statements that can be concurrently executed (its priority is higher than that of concurrency control rules). If the value is less than 0, the number of SQL statements is not limited.

Function Interface Description

Table 2 Function interface description

No.

Function

Parameter

Return Value

Description

1

rds_pg_sql_ccl.get_query_id

query_string text,

search_path text default 'public'

queryid

Calculates the query ID of a SQL statement.

2

rds_pg_sql_ccl.add_ccl_rule_by_query

query_string text,

max_concurrency int default 0,

max_waiting int default 0,

search_path text default 'public'

ruleid

Adds a concurrency control rule using SQL statements.

3

rds_pg_sql_ccl.add_ccl_rule_by_queryid

query_id bigint,

max_concurrency int default 0,

max_waiting int default 0,

search_path text default 'public'

ruleid

Adds a concurrency control rule based on the query ID.

5

rds_pg_sql_ccl.enable_ccl_rule

rule_id bigint

bool

Enables a concurrency control rule based on the rule ID.

6

rds_pg_sql_ccl.disable_ccl_rule

rule_id bigint

bool

Disables a concurrency control rule based on the rule ID.

7

rds_pg_sql_ccl.disable_all_ccl_rule

-

void

Disables all rules.

8

rds_pg_sql_ccl.delete_ccl_rule

rule_id bigint

void

Deletes a concurrency control rule based on the rule ID.

9

rds_pg_sql_ccl.update_ccl_rule

new_rule_id bigint,

new_max_concurrency int,

new_max_waiting int

void

Updates a concurrency control rule based on the rule ID.

Description of some parameters:

  • max_concurrency: The maximum number of SQL statements that can be concurrently executed.
  • max_wait: The maximum waiting time after which new SQL statements of a specified type will fail to be executed when the maximum number of concurrent SQL statements is reached.
  • new_max_concurrency: The new maximum number of concurrent SQL statements.
  • new_max_wait: The new maximum waiting time.

View Interface Description

Table 3 View interface description

No.

View

Column

Description

1

rds_pg_sql_ccl.get_all_enabled_rule

dbid oid,

queryid bigint,

max_concurrency int,

max_wait int

Displays all concurrency control rules applied.

2

rds_pg_sql_ccl.get_activity_query_status

queryid bigint,

wait_start_time timestamptz,

pid int,

dbid oid

Displays the status of each SQL statement in the current instance, such as the query ID and whether the SQL statement is waiting.

3

rds_pg_sql_ccl.get_current_db_ccl_rule

rule_id bigint,

query_id bigint,

query_string,

max_concurrency int,

max_waiting int,

search_path text,

create_time timestamptz,

enabled bool

Displays the concurrency control rules created for the current database (whether applied or not).

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback