All Products
Search
Document Center

Hologres:Run read and write tasks with serverless computing

Last Updated:Mar 26, 2026

DML and DQL workloads competing with production queries can cause out-of-memory (OOM) errors and degrade instance stability. Serverless Computing routes these workloads to an elastic resource pool outside your instance, isolating heavy operations without affecting live traffic. Supported in Hologres V2.1.17 and later.

Supported tasks

VersionSupported tasks
V2.1.17+Major Data Manipulation Language (DML) tasks: INSERT (excluding INSERT OVERWRITE), INSERT ON CONFLICT (UPSERT), DELETE, UPDATE
V2.2.14+Data Query Language (DQL) tasks
V3.0.1+COPY tasks in DML
V3.0.9+CREATE TABLE AS (CTAS) tasks in DML
V2.2.42, V3.0.19+RESHARDING tasks
V3.0.26+INSERT OVERWRITE via the hg_insert_overwrite stored procedure; DML and DQL within stored procedures
V3.1.0+Native INSERT OVERWRITE syntax in DML; REBUILD tasks
V3.1.3+Read from and write to encrypted internal Hologres tables and encrypted external MaxCompute tables. Enable the GUC parameter hg_serverless_computing_enable_encrypted_table for encrypted internal tables. See Data encryption.
V3.1.11+Compaction tasks. See Use Serverless Computing to run compaction tasks.
V4.0+Read from and write to Data Lake Formation (DLF) external tables. See Accelerate access to data in OSS data lakes based on DLF.

Supported function extensions: ClickHouse, Flow Analysis, PostGIS, RoaringBitmap, BSI, and Proxima.

Limitations

Serverless Computing does not support:

  • Queries on read-only secondary instances. Primary instances and virtual warehouse instances are not affected.

  • Queries with multi-row DML transactions enabled (set hg_experimental_enable_transaction = on).

  • SQL statements that use Fixed Plan.

  • Cross-database queries and writes.

Route SQL to serverless resources

Hologres evaluates routing rules in the following priority order. The first matching rule applies:

PriorityMethodBest for
1 (highest)Session-level SETOne-time or ad hoc tasks in the current connection
2User-level ALTER USERSpecific users or roles that should always use serverless resources
3Query Queue-level configurationBatches of SQL by type, engine, SQL fingerprint, or storage mode
4Adaptive Serverless ComputingAutomatically identifying and routing large tasks
5 (lowest)None — instance resourcesAll other SQL
Note

When an SQL statement runs on serverless resources, the compute resources are exclusively allocated to that statement. No other SQL runs concurrently on those resources.

Important

Routing a request to serverless resources involves metadata processing on the instance, which consumes a small amount of instance compute resources. Avoid excessively high QPS (queries per second) for serverless requests.

  • On general-purpose instances, metadata processing consumes the instance's own compute resources.

  • On compute group-type instances, metadata processing consumes resources from the Leader compute group, regardless of whether you connect through the Leader or the Follower compute group of a Table Group.

Session-level configuration

Set hg_computing_resource at the session level to route all SQL in the current connection to serverless resources. Reset the parameter immediately after your task to avoid unintentionally routing subsequent queries.

Use this method for:

  • One-time tasks such as historical data refreshes or table schema modifications (REBUILD).

  • Periodic offline import tasks (M+1, T+1, or H+1). Add the SET and RESET commands to your scheduled task.

  • Any scenario where you need flexible, per-session control over resource routing.

-- Route the current session to Serverless Computing resources.
-- Default value is local (uses instance resources).
SET hg_computing_resource = 'serverless';

-- Run your DML statement.
INSERT INTO sink_tbl SELECT * FROM source_tbl;

-- Reset after the task. This prevents subsequent SQL from using serverless resources unintentionally.
RESET hg_computing_resource;
Important

Do not set this parameter at the database level. Always run RESET hg_computing_resource after your task.

Full example:

-- Data preparation
CREATE TABLE source_tbl (id int);
CREATE TABLE sink_tbl (id int);
INSERT INTO source_tbl SELECT * FROM generate_series(1, 99999999);

-- Route to serverless and run the task
SET hg_computing_resource = 'serverless';
INSERT INTO sink_tbl SELECT * FROM source_tbl;
RESET hg_computing_resource;

User-level configuration

Configure all SQL initiated by a specific user or role to run on serverless resources by default. This method takes priority over database-level GUC configuration but yields to session-level configuration. For details, see GUC parameters.

Use this method for:

  • Superusers or other high-privilege users whose tasks should always use serverless resources.

  • Data source accounts that power high-priority dashboards.

-- Route all SQL from a specific user in a database to serverless resources.
ALTER USER "<role_name>" IN DATABASE <db_name> SET hg_computing_resource = 'serverless';

-- Revert the configuration.
ALTER USER "<role_name>" IN DATABASE <db_name> RESET hg_computing_resource;

Query Queue-level configuration

Configure an entire Query Queue to route all its SQL to serverless resources. This lets you use Query Queue classifiers to target specific SQL by type, engine, SQL fingerprint, or storage mode. For information on configuring a Query Queue, see Query Queue.

Examples of what you can target:

  • By query type: INSERT, SELECT, UPDATE, DELETE

  • By query engine: HQE, PQE, SQE, HiveQE. For example, route all SQE tasks (non-direct-read MaxCompute external table queries) to serverless resources.

  • By SQL fingerprint: If a specific query pattern poses a stability risk, configure its SQL fingerprint to always run on serverless resources.

  • By storage mode: Route all cold storage queries to serverless resources.

General-purpose instance:

-- Route all queries in the target queue to serverless resources.
CALL hg_set_query_queue_property('<query_queue_name>', 'computing_resource', 'serverless');

-- (Optional) Set the query priority for this queue when using serverless resources.
-- Valid values: 1-5. Default: 3.
CALL hg_set_query_queue_property('<query_queue_name>', 'query_priority_when_using_serverless_computing', '<priority>');

Virtual warehouse instance:

-- Route all queries in the target queue to serverless resources.
CALL hg_set_query_queue_property('<warehouse_name>', '<query_queue_name>', 'computing_resource', 'serverless');

-- (Optional) Set the query priority for this queue when using serverless resources.
-- Valid values: 1-5. Default: 3.
CALL hg_set_query_queue_property('<warehouse_name>', '<query_queue_name>', 'query_priority_when_using_serverless_computing', '<priority>');

Adaptive Serverless Computing

Hologres can automatically identify large tasks and route them to serverless resources, without any manual configuration per query. For details, see Adaptive Serverless Computing.

Automatic retry for large tasks

Define thresholds for "large queries" — such as queries that run beyond a specified duration or cause an OOM error. Hologres then automatically retries those queries on serverless resources. This reduces the load on production services, lowers OOM frequency, and improves system stability. For details, see Large query control.

Set task priority

When multiple SQL statements are queued for serverless resources, Hologres allocates resources by priority. Higher-priority tasks receive resources first, regardless of how many resources they request.

ParameterValid valuesDefaultScope
hg_experimental_serverless_computing_query_priority1–5 (5 = highest)3Session or user level

How priority allocation works:

ConditionBehavior
Higher-priority task is queuedSystem waits for running tasks to finish, then allocates resources to the highest-priority task first
Multiple tasks at the same priorityResources are allocated in queue order
Available resources are insufficient for next taskSystem waits until enough resources are free, even if lower-priority tasks could run on currently available resources

Example: Your instance has 32 cores, with a maximum of 96 serverless cores available. SQL A is running and using 64 cores. The queue contains SQL B (48 cores, priority 5) and SQL C (32 cores, priority 3). Although 32 cores are available immediately, the system waits for SQL A to finish, then allocates 48 cores to SQL B first, because SQL B has higher priority.

Session-level:

SET hg_experimental_serverless_computing_query_priority = 5;
-- Run your task.
RESET hg_experimental_serverless_computing_query_priority;

User-level:

ALTER USER "<role_name>" IN DATABASE <db_name> SET hg_experimental_serverless_computing_query_priority = 5;
-- Revert the configuration.
ALTER USER "<role_name>" IN DATABASE <db_name> RESET hg_experimental_serverless_computing_query_priority;

Combined example — route to serverless and set priority:

SET hg_computing_resource = 'serverless';
SET hg_experimental_serverless_computing_query_priority = 5;

INSERT INTO sink_tbl SELECT * FROM source_tbl;

RESET hg_computing_resource;
RESET hg_experimental_serverless_computing_query_priority;

Verify Serverless Computing

Use EXPLAIN to confirm that an SQL statement is routed to serverless resources before running it.

SET hg_computing_resource = 'serverless';
EXPLAIN INSERT INTO sink_tbl SELECT * FROM source_tbl;
RESET hg_computing_resource;

The output is similar to the following. If Computing Resource: Serverless appears, the statement is routed correctly.

                                        QUERY PLAN
------------------------------------------------------------------------------------------
 Gather  (cost=0.00..5.18 rows=100 width=4)
   ->  Insert  (cost=0.00..5.18 rows=100 width=4)
         ->  Redistribution  (cost=0.00..5.10 rows=100 width=4)
               ->  Local Gather  (cost=0.00..5.10 rows=100 width=4)
                     ->  Decode  (cost=0.00..5.10 rows=100 width=4)
                           ->  Seq Scan on source_tbl  (cost=0.00..5.00 rows=100 width=4)
 Computing Resource: Serverless
 Optimizer: HQO version 2.1.0
(8 rows)

To monitor running and historical serverless tasks, see Monitor and manage Serverless Computing.

What's next