Hologres Serverless Computing charges for large SQL jobs—those with high CPU or memory overhead—based on the compute resources consumed and the duration of use. This page explains how to view your Serverless Computing resource consumption, estimate costs before enabling the feature, set daily usage limits, and configure alerts to avoid unexpected charges.
How billing works
Serverless Computing measures resource usage in Compute Unit·Hour (CU·H): the number of Compute Units (CUs) allocated to a SQL job multiplied by the actual usage duration. Billing is processed hourly—each hour, the system aggregates all Serverless Computing usage from the previous hour and charges you accordingly. For current unit pricing, see Billing overview.
-
Billing for Serverless Computing began on
2024-07-01(UTC+8). This document provides guidance on how to monitor your Serverless Computing resource consumption, estimate your bills, and adjust resource allocation to jobs to prevent unexpected costs. -
For a list of supported regions and zones, see Serverless Computing User Guide.
-
Both
hologres.hg_query_logandhologres.hg_serverless_computing_query_logretain data for the past 30 days.
Billing for Serverless Computing began on 2024-07-01 (UTC+8). Only successfully executed SQL jobs are billed. Failed executions incur no charge.
Key constraints:
-
For a list of supported regions and zones, see Serverless Computing user guide.
-
Both
hologres.hg_query_logandhologres.hg_serverless_computing_query_logretain data for the past 30 days.
Query resource consumption
Starting with Hologres V2.1.18, query the hologres.hg_serverless_computing_query_log view to calculate Serverless Computing resource consumption and estimate costs. For details about slow query logs, see View and analyze slow query logs.
Before Hologres V2.2.7, slow query logs recorded all failed Serverless Computing jobs and successful jobs that ran for longer than 100 milliseconds. Starting with V2.2.7, logs include all Serverless Computing jobs. Slow query logs record resource consumption per SQL statement; during billing, data aggregation and unit conversions may cause minor discrepancies.
Prerequisites
To query Serverless Computing resource consumption from slow query logs, you need one of the following permission levels.
To view data scan volume across all databases in an instance:
-
Option 1 — Superuser permission:
-- Replace "Alibaba Cloud account ID" with the actual username. -- For RAM users, prepend the account ID with "p4_". ALTER USER "Alibaba Cloud account ID" SUPERUSER; -
Option 2 — pg_read_all_stats group membership (regular users who need full log access must contact a Superuser for authorization):
GRANT pg_read_all_stats TO "Alibaba Cloud account ID"; -- Standard PostgreSQL authorization model CALL spm_grant('pg_read_all_stats', 'Alibaba Cloud account ID'); -- SPM CALL slpm_grant('pg_read_all_stats', 'Alibaba Cloud account ID'); -- SLPM
To view data scan volume for the current database only:
-
Enable the simple permission model (SPM) or the schema-level simple permission model (SLPM), then add the user to the
db_admingroup:CALL spm_grant('<db_name>_admin', 'Alibaba Cloud account ID'); -- SPM CALL slpm_grant('<db_name>.admin', 'Alibaba Cloud account ID'); -- SLPM -
Regular users can query their own data scan volume within databases associated with their account.
For more information, see Permission management overview.
Query resource consumption for a single SQL statement
The following query returns detailed resource consumption for each Serverless Computing job, including the CUs allocated and the time the job spent waiting in the queue.
SELECT
*,
queue_time_ms, -- Time the SQL spent waiting in the Serverless Computing queue (ms)
serverless_allocated_cores, -- Number of CUs allocated to this SQL job
serverless_resource_used_time_ms, -- Duration the SQL actually used Serverless Computing resources (ms)
(serverless_allocated_cores::DECIMAL(38, 4)) * (serverless_resource_used_time_ms::DECIMAL(38, 4)) AS serverless_cums
FROM
hologres.hg_serverless_computing_query_log;
The serverless_cums column shows the raw CU·millisecond value for each job. Divide by 1000 * 60 * 60 to convert to CU·H.
Query total resource consumption over a time range
The following query calculates total CU·H consumed by all successfully executed Serverless Computing jobs within a specified time window. Adjust the query_end range to match the period you want to analyze.
SELECT
(SUM((serverless_allocated_cores::DECIMAL(38, 4)) * (serverless_resource_used_time_ms::DECIMAL(38, 4))) / 1000 / 60 / 60)::bigint AS serverless_cuh
FROM
hologres.hg_serverless_computing_query_log
WHERE
status = 'SUCCESS'
AND serverless_allocated_cores IS NOT NULL
AND serverless_resource_used_time_ms IS NOT NULL
AND query_end BETWEEN '2024-05-01 00:00:00' AND '2024-05-31 24:00:00'; -- Specify time range
The result is the estimated Serverless Computing resource consumption for that period in CU·H.
Estimate resource consumption before enabling Serverless Computing
If Serverless Computing is not yet enabled, run your SQL jobs using instance resources first, then estimate Serverless consumption using the cpu_time_ms field in hologres.hg_query_log:
SELECT cpu_time_ms FROM hologres.hg_query_log WHERE query_id = 'xxx';
Apply the formula cpu_time_ms / 1000 / 60 / 60 to get an approximate CU·H value.
This method provides only a rough estimate. Instance resources are shared with other workloads, while Serverless resources are isolated—and their capacity differs. For a more accurate estimate, run key SQL jobs directly with Serverless Computing as described in the Serverless Computing user guide. These test runs do not affect other tasks on your instance.
Set a daily usage limit
Starting from Hologres V3.1.5, set a daily CU·H cap to prevent unexpected charges. Only Superusers can configure these limits.
Hologres aggregates and updates instance-level Serverless Computing usage every 10 minutes. Enforcement of the daily limit may lag by up to 10 minutes.
Configure the daily limit
-- Set limit for a database
ALTER DATABASE <db_name> SET hg_serverless_computing_daily_max_cuh_usage_threshold = <value>;
-- Set limit for a user
ALTER USER <user_name> SET hg_serverless_computing_daily_max_cuh_usage_threshold = <value>;
| Parameter | Description |
|---|---|
| Default value | -1 (no limit) |
| Unit | CU·H |
Hologres tracks daily usage based on the default time zone of the database. To check the database time zone, run the following commands in the same session:
-- Reset time zone to avoid influence from client or user settings
RESET timezone;
-- Show the database's default time zone
SHOW timezone;
When to set a limit:
-
If Serverless Computing is already part of your regular workload, review the output of Query total resource consumption over a time range to determine an appropriate daily cap.
-
If you are new to Serverless Computing, wait until your workload stabilizes before setting a daily limit.
Configure behavior when the limit is exceeded
By default, when the daily limit is reached, SQL jobs automatically fall back to using instance resources rather than Serverless Computing. Before executing each SQL statement, Hologres compares the current daily Serverless usage against the configured limit for the user or database. If the limit is reached, the statement runs on instance resources instead.
To disable automatic fallback and fail queries immediately when the limit is exceeded, run the following commands (Superuser only):
-- Set at database level
ALTER DATABASE <db_name> SET hg_serverless_computing_enable_fallback_when_exceed_cuh_threshold = false;
-- Set at user level
ALTER USER <user_name> SET hg_serverless_computing_enable_fallback_when_exceed_cuh_threshold = false;
Behavior when the limit is exceeded:
| Parameter value | What happens |
|---|---|
true (default) |
SQL jobs automatically fall back to instance resources. |
false |
SQL jobs fail immediately. The following error is returned: serverless computing is not available due to exceeding cuh usage threshold, please adjust the threshold or turn off serverless computing for current query |
Monitor costs and set alerts
Cost Analysis
You can use the module in Expenses and Costs to monitor and analyze the billing of Hologres compute resources.
-
Log on to Expenses and Costs. In the navigation pane on the left, click .
-
On the Cost Analysis page, in the section on the right, select Billing Item. Then, select a Cost Type and Time Granularity as needed.
-
In the Filter Conditions section on the right, select the appropriate Billing Item based on your resource type.
For more information, see Cost Analysis.
Spending alerts
Use Expenses and Costs to manage budgets and set alerts for pay-as-you-go spending on specific products in specific regions. For more information, see Expense Alerts.
Single SQL execution duration alert
Hologres supports monitoring for Serverless Computing metrics. Create alert rules based on your business needs to avoid unexpected charges.
For example, for the metric Longest duration among running Serverless Computing queries, the following alert rule is recommended:
Warning: The longest duration among running Serverless Computing queries is >= 3,600,000 milliseconds for 5 consecutive periods (1 period = 1 minute).
For more information, see Monitoring and alerting best practices.
What's next
-
For an overview of Serverless Computing, see Serverless Computing overview.
-
For usage instructions, see Serverless Computing user guide.