All Products
Search
Document Center

Hologres:Resource consumption and billing

Last Updated:May 30, 2025

The fees for the Serverless Computing feature of Hologres vary based on the amount of serverless computing resources that are used by big SQL jobs and the usage duration. Big SQL jobs include SQL jobs that generate large CPU or memory overheads. This topic describes how to query the amount of used serverless computing resources and the billing details.

Billing rules

You are charged for the Serverless Computing feature for a SQL job based on CU-H, which is calculated by the number of compute units (CUs) of serverless computing resources that are used by the job multiplied by the usage duration. You are charged on an hourly basis. The system calculates the number of CUs of serverless computing resources that are used by a SQL job in the previous hour and deducts fees every hour. For more information about the unit price of serverless computing resources, see Billing overview.

Important
  • You will be charged for the use of the Serverless Computing feature from July 1, 2024 (UTC+8). You can estimate the cost based on the amount of used serverless computing resources by following the instructions in this topic. You can adjust the resource allocation to jobs to prevent unexpected costs.

  • For more information about the regions and zones in which the Serverless Computing feature is available, see User guide on Serverless Computing.

  • Both hologres.hg_query_log and hologres.hg_serverless_computing_query_log retain data of the past 30 days.

Only SQL jobs that are executed as expected are billed. Failed SQL jobs are not billed.

Query resource consumption

In Hologres V2.1.18 and later, you can calculate the amount of used serverless computing resources based on the hologres.hg_serverless_computing_query_log view and estimate the costs based on the billing formula. For more information about slow query logs, see Query and analyze slow query logs.

Note
  • For queries that are performed by using serverless computing resources in versions earlier than Hologres V2.2.7, slow query logs record only failed queries and the queries that take more than 100 milliseconds. In Hologres V2.2.7 and later, slow query logs record all queries that are performed by using serverless computing resources.

  • Slow query logs record the resource consumption of each SQL statement. During bill generation, data aggregation and unit conversion may be required. Therefore, the actual resource consumption may be slightly different from the resource consumption in slow query logs.

Permissions

To estimate the consumption of serverless computing resources and the costs based on slow query logs, you must be granted the required permissions. This section describes the required permissions for different operations and how to grant the permissions.

  • Query the total amount of data that is scanned in all databases on an instance

    • Method 1: Assign the superuser role to a user. Sample statement:

      -- Replace Account ID with your Alibaba Cloud account ID. For a RAM user, prefix the account ID with p4_. 
      ALTER USER "Account ID" SUPERUSER;
    • Method 2: Add a user to the pg_read_all_stats user group. Sample statement:

      Note

      Users who are assigned the superuser role and users who belong to the pg_read_all_stats user group have permissions to view the total amount of data that is scanned in all databases. You can add an ordinary user to the user group as a superuser.

      GRANT pg_read_all_stats TO "Account ID";-- Use the standard PostgreSQL authorization model to grant related permissions to the user.
      CALL spm_grant('pg_read_all_stats', 'Account ID');  -- Use the simple permission model (SPM) to grant related permissions to the user.
      CALL slpm_grant('pg_read_all_stats', 'Account ID'); -- Use the schema-level permission model (SLPM) to grant related permissions to the user.
  • Query the amount of data that is scanned in the current database on an instance

    • Use the SPM or SLPM to add a user to the db_admin user group. Users who are assigned the db_admin role have permissions to view the amount of data that is scanned in the current database.

      CALL spm_grant('<db_name>_admin', 'Account ID'); -- Use the SPM to grant related permissions to the user.
      CALL slpm_grant('<db_name>.admin', 'Account ID'); -- Use the SLPM to grant related permissions to the user.
    • Ordinary users can query only the amount of data that is scanned in their queries in the database.

Note

For more information about permissions, see Permission management overview.

Query the resource consumption of a single SQL statement

To query the consumption details of serverless computing resources, execute the following SQL statement:

SELECT
    *,
    queue_time_ms, -- The queuing duration for an SQL statement to wait for serverless computing resources, in milliseconds.
    serverless_allocated_cores, -- The number of CUs of serverless computing resources that are allocated to an SQL statement. 
    serverless_resource_used_time_ms, -- The duration for which an SQL statement occupies serverless computing resources, in milliseconds.
    (serverless_allocated_cores::DECIMAL(38, 4)) * (serverless_resource_used_time_ms::DECIMAL(38, 4)) AS serverless_cums
FROM
    hologres.hg_serverless_computing_query_log;

Query resource consumption in a specific period of time

To query the amount of serverless computing resources that are consumed in a specific period of time by successfully executed tasks, execute the following SQL statement:

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';-- The specified period of time.

Estimate resource consumption

If you have not enabled Serverless Computing but want to execute certain SQL statements using serverless computing resources, you can first use the resources of your Hologres instance to execute them. The cpu_time_ms field in the Hologres system table hologres.hg_query_log indicates the CPU time consumed by SQL tasks. You can query this field and use the formula cpu_time_ms/1000/60/60 to roughly estimate the resource consumption for executing an SQL statement using serverless computing resources. You can execute the following SQL statement to query the cpu_time_ms field:

SELECT cpu_time_ms FROM hologres.hg_query_log WHERE query_id = 'xxx';
Note

The resources of your instance may be affected by other workloads, while serverless computing resources are not. Additionally, the capacities of the two types of resources may differ. Therefore, this method cannot precisely estimate the serverless resource consumption. We recommend that you enable Serverless Computing for specific important SQL tasks to directly use serverless computing resources for resource consumption testing. The testing process will have no impact on other tasks running on this instance.

Cost monitoring and alerting

Daily cumulative usage limit

Starting from Hologres V3.1.5, you can limit the daily usage of serverless computing resources using the following SQL statements. This limit can only be set by a Superuser.

-- Set a limit for a database.
ALTER DATABASE <db_name> SET hg_serverless_computing_daily_max_cuh_usage_threshold = xx;

-- Set a limit for a user.
ALTER USER <user_name> SET hg_serverless_computing_daily_max_cuh_usage_threshold = xx;
  • Limit description

    • The default value is -1, which means no limit is applied.

    • The unit is CU-hours.

    • Hologres aggregates and updates the total usage of serverless computing resources every 10 minutes. Therefore, there may be a delay of up to 10 minutes in enforcing this limit.

    • Before executing an SQL query, Hologres compares the total usage of serverless computing resources for the instance on the current day with the daily usage limit of serverless computing resources for the current user or database. If the limit has been reached, the SQL query will be executed using the instance's own computing resources by default. If the limit has not been reached, the SQL query will use serverless computing resources for execution.

    • Hologres calculates the daily cumulative usage of serverless computing resources based on the natural day in the default time zone of the current database. You can query the default time zone of the current database within the same session using the following commands:

      -- Reset the time zone to avoid being affected by the client's time zone or the user's default time zone.
      RESET timezone;
      
      -- Query the current database's default time zone.
      SHOW timezone;
  • Usage recommendations

    • If you frequently use the Hologres Serverless Computing feature, you can determine an appropriate daily cumulative usage limit by querying resource consumption in a specific period of time.

    • If you have not used the Hologres Serverless Computing feature before, it is recommended to fully utilize it and stabilize production workloads before deciding whether to set a daily cumulative usage limit and what the appropriate threshold should be.

If you do not want SQL queries to automatically fall back to the instance's own computing resources when the serverless computing resource usage limit is exceeded, you can run the following commands to make certain queries directly return an error. The parameter in the commands can only be set by a Superuser.

-- Set the parameter for a database.
ALTER DATABASE <db_name> SET hg_serverless_computing_enable_fallback_when_exceed_cuh_threshold = false;

-- Set the parameter for a user.
ALTER USER <user_name> SET hg_serverless_computing_enable_fallback_when_exceed_cuh_threshold = false;
Note
  • The default value is true, indicating that when the limit is exceeded, SQL queries will automatically fall back to the instance's own computing resources.

  • If you set this parameter to false, SQL queries will directly return the following error when the limit is exceeded: serverless computing is not available due to exceeding cuh usage threshold, please adjust the threshold or trun off serverless computing for current query.

Cost analysis

You can view and analyze the costs of Hologres serverless computing resources on the Cost Analysis page of the Expenses and Costs console.

  1. Log on to the Expenses and Costs console. In the left-side navigation pane, choose Cost Management > Cost Analysis.

  2. On the Cost Trend tab of the Cost Analysis page, select Billing Item from the Category drop-down list, and configure the Cost Type and Time Unit parameters based on your business requirements.

  3. In the Filters section on the right side of the page, click Billing Item, select Serverless computing resources, Hologres (Pay-as-you-go), and then click Apply to view the costs of serverless computing resources within the specified time range.

For more information, see Cost Analysis.

Cost alerting

In the Expenses and Costs console, you can manage budgets and configure alerts for the pay-as-you-go billing items of some services in some regions. For more information, see Cost alerting.

Alerts for the execution duration of a single SQL statement

Hologres provides metrics for the Serverless Computing feature. We recommend that you configure alert rules for the Serverless Computing feature based on your business requirements. This helps prevent unexpected costs.

For example, you can configure the following alert rule for the Serverless Computing Longest Active Query Time metric.

Warn: If the value of this metric is greater than or equal to 3,600,000 milliseconds in 5 consecutive cycles, a warn-level alert is reported. Each cycle lasts for 1 minute.

jiankong.jpg

For more information, see Configure alert rules.

References