When slow or high-volume SQL statements saturate cluster resources, SQL throttling lets you cap the concurrency or queries per second (QPS) of specific statement patterns at the database proxy layer—without modifying application code or restarting the cluster.
SQL throttling is not enabled by default. To enable it, contact Alibaba Cloud.
Use cases
Slow query traffic surge: A batch of slow SQL statements saturates cluster resources and degrades normal business performance. Throttle the problematic pattern to cap its concurrency while you resolve the underlying issue.
High-risk SQL control: Block a class of dangerous queries by setting their concurrency limit to
0, with no changes to application code.
How it works
SQL throttling runs on the database proxy—not on the read/write or read-only nodes of the cluster. When a SQL statement arrives at the proxy, the proxy matches it against configured throttling rules before forwarding it. If a match is found, the proxy tracks concurrency or QPS for that rule and either queues excess statements for retry or rejects them.
Because throttling happens at the proxy layer, rules apply only to cluster endpoints and custom endpoints that use load balancing based on active requests. Primary endpoints and read-only endpoints that use load balancing based on connections do not support SQL throttling.
Rules configured on different endpoints are independent of each other. Rules on the same endpoint apply only to connections that use that endpoint.
Enabling SQL throttling reduces proxy forwarding performance by 5%–10% for all statements, regardless of whether they match a rule. Disable throttling rules after you resolve the underlying issue—disabled rules are saved and can be re-enabled at any time.
Create a throttling rule
Prerequisites
Before you begin, ensure that you have:
A PolarDB for PostgreSQL cluster with SQL throttling enabled (contact Alibaba Cloud support)
Access to the PolarDB console
Steps
Log on to the PolarDB console. In the left navigation pane, click Cluster List. Select the region of your cluster and click the cluster ID.
In the left navigation pane, choose Settings and Management > Security.
On the SQL Throttling tab, click Add.

In the Create SQL Throttling Rule dialog box, configure the parameters below and click OK.
Basic information
| Parameter | Description |
|---|---|
| Rule Name | Name of the rule. Up to 30 characters; uppercase letters, lowercase letters, and digits only. |
| Description | (Optional) Description to help with future management. Up to 64 characters. |
| EndpointID | The endpoint to which the rule applies. Only cluster endpoints and custom endpoints that use load balancing based on active requests (read/write or read-only) are supported. |
Configurations
| Parameter | Description |
|---|---|
| Rule Type | How to measure the throttle limit. Throttle Active Concurrent Statements: limits total concurrently running statements that match the rule. Use this for most workloads. Throttle QPS per Connection: limits requests per second per individual connection. Use this when your application uses a connection pool or persistent connections. |
| Current Mode | How the proxy matches incoming SQL against the SQL template. Template Match: constants (strings and numbers) are normalized to wildcards (?) before matching—one template covers all parameter variations. Full-text Match: normalizes whitespace and comments only; constants are kept as-is. See SQL templates and matching modes. |
| Database Account Name | Accounts the rule applies to. Up to 10 accounts, comma-separated. Leave blank to apply to all accounts. |
| Database Name | Databases the rule applies to. Up to 10 databases, comma-separated. Leave blank to apply to all databases. |
| SQL Template | The SQL pattern to match. See SQL templates and matching modes. |
| Maximum Waiting Queue Length | Number of throttled statements that can wait for a retry slot (range: 0–1,024). When the queue is full, new matching statements are rejected immediately. Setting a limit prevents the queue from growing unbounded and avoids out-of-memory (OOM) errors in the proxy. |
| Maximum Active Concurrent Statements | Maximum number of concurrently running statements allowed for this rule. Setting to 0 immediately rejects all matching statements. Required when Rule Type is Throttle Active Concurrent Statements. |
| Maximum QPS per Connection | Maximum requests per second for each individual connection. Setting to 0 immediately rejects all matching statements. Required when Rule Type is Throttle QPS per Connection. |
SQL templates and matching modes
Template matching vs. full-text matching
When you create a rule, the proxy preprocesses your SQL template based on the matching mode and generates a unique identifier from the result. When a business SQL statement arrives, the proxy applies the same preprocessing and compares the identifier against configured rules.
Given this SQL template:
SELECT * FROM tbl WHERE id < 1;| Mode | Preprocessing result | What it matches |
|---|---|---|
| Template matching | SELECT * FROM tbl WHERE id < ? | Any value substituted for the constant (e.g., id < 100, id < 999) |
| Full-text matching | SELECT * FROM tbl WHERE id < 1 | Only statements where the constant is exactly 1 |
For the business SQL SELECT * FROM tbl WHERE id < 100, only a template matching rule hits.
Parameterization support
SQL templates accept PostgreSQL's standard parameter binding syntax ($1, $2, and so on):
SELECT * FROM tbl WHERE id < $1 AND name = $2 LIMIT 1;The proxy normalizes parameters to ? in both modes:
-- Template matching result
SELECT * FROM tbl WHERE id < ? AND name = ? limit ?
-- Full-text matching result
SELECT * FROM tbl WHERE id < ? AND name = ? limit 1For the business SQL SELECT * FROM tbl WHERE id < $1 AND name = 2 LIMIT 100, a template matching rule hits; a full-text matching rule does not.
Do not use?directly in an SQL template—it does not follow PostgreSQL syntax and will not match any statement. Use$1,$2,$3, and so on instead:
-- Invalid
SELECT ?, ?, ?;
-- Valid
SELECT $1, $2, $3;Prepared statements
For prepared statements, only the EXECUTE statement triggers throttling—not PREPARE. The proxy matches the SQL part of the corresponding PREPARE statement against the rule.
The following two SQL templates are equivalent in a throttling rule:
-- Template 1
PREPARE s1 AS SELECT * FROM tbl WHERE id < $1 AND name > $2;
-- Template 2
SELECT * FROM tbl WHERE id < $1 AND name > $2;Example: Using template matching with the rule template SELECT * FROM tbl WHERE id < $1 AND name > $2:
-- PREPARE does not trigger throttling
PREPARE s1 AS SELECT * FROM tbl WHERE id < $1 AND name > 100;
-- Each EXECUTE hits the rule and is throttled
EXECUTE s1;
EXECUTE s1;
EXECUTE s1;For more information on prepared statements, see PREPARE.
Extended protocol support
When an application driver uses the PostgreSQL extended query protocol, only Execute messages trigger throttling. The proxy finds the corresponding Parse message to calculate the SQL template for matching. No special configuration is needed—SQL throttling handles both simple and extended protocol connections automatically.
For more information, see the PostgreSQL extended query protocol documentation.
Throttling behavior
When a SQL statement hits a throttling rule and the configured concurrency or QPS limit is reached, the proxy places the statement in a waiting queue and retries it after a delay. The delay is inversely proportional to the configured limit—lower limits result in longer waits.
If the waiting queue reaches Maximum Waiting Queue Length, the proxy rejects subsequent matching statements immediately and returns:
Current query is being throttled and waiting queue is full.This error does not affect transaction state. The client can still commit or roll back the current transaction normally.
Setting Maximum Active Concurrent Statements or Maximum QPS per Connection to 0 causes the proxy to reject all matching statements immediately—no waiting queue is used. Use this to completely block a class of SQL statements.
High availability considerations
For high availability (HA), the database proxy runs on two or more nodes. Client connections are distributed across these nodes, and each node tracks concurrency and queue length independently. For a deployment with N nodes, where C is the per-node Maximum Active Concurrent Statements and Q is the per-node Maximum Waiting Queue Length:
Client concurrency range:
[C+Q, N × (C+Q)]Database active concurrency range:
[C, N × C]
The actual total concurrency across the cluster is not precisely controlled. Plan your limits with this range in mind.
The waiting queue has a minimum retry interval. If the configured maximum QPS is high, the actual throughput may be slightly lower than the configured value.
Limitations
| Limitation | Details |
|---|---|
| Multi-statement SQL | SQL text containing multiple statements separated by semicolons does not trigger any throttling rule. Example (Java Database Connectivity (JDBC)): statement.execute("select 1; select 2; select 3"). |
| Transaction control statements and stored procedures | Statements such as COMMIT are not throttled to avoid blocking transaction completion. |
| Statement batching | When a driver batches multiple SQL statements, only the first throttling rule hit takes effect. For example, if rules exist for SELECT 1, SELECT 2, and SELECT 3, only the rule for SELECT 1 triggers. |
| Case-sensitive keywords | SQL templates are case-sensitive. The case in your template must match the actual SQL text you want to throttle. |
| Variable-length expressions | Templates do not match IN or ANY expressions with a different number of elements. A template for WHERE id IN ($1, $2, $3) matches WHERE id IN (1, 6, 8) but not WHERE id IN (1, 6, 8, 8). |
| Rule propagation to existing connections | If no rules exist on an endpoint, a newly added rule does not take effect on existing connections. Once any rule exists (enabled or disabled), subsequent additions, modifications, and deletions take effect on all connections in real time. If your application uses persistent connections, add a placeholder rule, disable it, and leave it in place so that future rule changes apply to all connections immediately. If the database proxy version is 2.3.58 or later, rule changes always propagate to all connections in real time. View your proxy version. If the version does not meet the requirement, upgrade the database proxy. |







