All Products
Search
Document Center

Hologres:User guide for table groups and shard counts

Last Updated:Dec 26, 2025

In scenarios that require real-time data processing or large-scale data collection, such as real-time analytics and log collection, you may encounter a high volume of concurrent read and write requests. You can specify an appropriate table group and shard count to implement data distribution and load balancing. This practice optimizes query performance and improves data storage and computing efficiency.

Recommendations for setting table groups and shard counts

Hologres lets you flexibly specify shards and table groups. Compared to similar products, Hologres provides a more flexible and user-friendly method for customizing schemas to suit specific scenarios. This feature helps you meet your business requirements. A good understanding of your business lets you take full advantage of the high performance that Hologres offers. Follow these basic rules when you set table groups:

  • Unless it is necessary, do not create a new table group. Use the default table group instead. For more information about instance specifications, see Instance management.

  • For large instances with more than 256 cores, you can create multiple table groups as needed to balance workloads.

    • If the data volume is large, create a separate table group with a large shard count.

    • If you have many tables with small data volumes, create a separate table group with a small shard count. This reduces query startup overhead.

  • Tables that need to be joined (Local Join) must be in the same table group.

  • Do not set a separate table group for each table.

  • When you set the shard count, consider the number of workers and future scale-outs. Set the shard count to a multiple of the number of workers to balance resource allocation.

  • You cannot modify the shard count of an existing table group. To change the shard count, you must create a new table group.

  • Do not set the shard count too high. Otherwise, computing resources may fail to be allocated, which causes extra overhead. In Hologres V2.0 and later, an upper limit is set by default on the shard count of a single table group and the total shard count of an instance. This prevents resource allocation failures caused by an excessive shard count. If the total shard count exceeds the limit, an error too many shards in this instance is reported. The upper limits are determined by the following rules:

    • Maximum shard count for a single table group = Default shard count for a single table group × 2

    • Maximum total shard count for an instance = Default shard count for a single table group × 8

    • To adjust the upper limits, you can use the following GUC parameter to remove them. However, this is not recommended. If you set the shard count too high, computing resources may fail to be allocated.

      set hg_experimental_enable_shard_count_cap =off;
    • The following table lists the upper limits on shard counts.

      Instance type

      Default number of compute nodes

      Default shard count (for V0.10.31 and later)

      Maximum shard count for a single table group (for V2.0 and later)

      Maximum total shard count for an instance (for V2.0 and later)

      32 Core

      2

      20

      40 (20 × 2)

      160 (20 × 8)

      64 Core

      4

      40

      80 (40 × 2)

      320 (40 × 8)

      96 Core

      6

      60

      120 (60 × 2)

      480 (60 × 8)

      128 Core

      8

      80

      160 (80 × 2)

      640 (80 × 8)

      160 Core

      10

      80

      160 (80 × 2)

      640 (80 × 8)

      192 Core

      12

      80

      160 (80 × 2)

      640 (80 × 8)

      256 Core

      16

      120

      240 (120 × 2)

      960 (120 × 8)

      384 Core

      24

      160

      320 (160 × 2)

      1280 (160 × 8)

      512 Core

      32

      160

      320 (160 × 2)

      1280 (160 × 8)

      ......

      ......

      M

      M × 2

      M × 8

Permissions

  • To create a table group, modify the default table group, delete a table group, or migrate a table to another table group (resharding), you must have Superuser permissions for the instance. A Superuser can run the following statement to grant Superuser permissions to a regular user.

    -- Replace "Alibaba Cloud account ID" with the actual username. If you use a RAM user, add the prefix "p4_" to the account ID.
    ALTER USER "Alibaba Cloud account ID" SUPERUSER; 
  • To place a new table into a specified table group, the user account must have permission to create tables.

Get table group metadata

  1. View the default table group.

    SELECT * FROM hologres.hg_table_group_properties
    WHERE tablegroup_name IN (
      SELECT tablegroup_name FROM hologres.hg_table_group_properties
      WHERE property_key = 'is_default_tg' AND property_value = '1'
    );

    Result:

    Note

    In the result, is_default_tg indicates whether the table group is the default, and shard_count indicates the shard count of the table group.

    tablegroup_name |   property_key   | property_value
    -----------------+------------------+----------------
     test_tg_default | tg_version       | 1
     test_tg_default | table_num        | 1               
     test_tg_default | is_default_tg    | 1               
     test_tg_default | shard_count      | 3
     test_tg_default | replica_count    | 1
     test_tg_default | created_manually | 0
    (6 rows)
  2. View the table groups in the current database.

    SELECT tablegroup_name
    FROM hologres.hg_table_group_properties GROUP BY tablegroup_name;

    Result:

    tablegroup_name
    -----------------
     test_tg_default
    (1 row)
  3. View the shard count of a table group.

    SELECT property_value AS shard_count
    FROM hologres.hg_table_group_properties
    WHERE property_key = 'shard_count' AND tablegroup_name ='<tg_name>';

    Result:

    shard_count
    -------------
     3
    (1 row)
  4. View the tables in a table group.

    SELECT table_namespace AS schema_name, table_name
    FROM hologres.hg_table_properties
    WHERE property_key = 'table_group' AND property_value = '<tg_name>';

    Result:

    schema_name | table_name
    -------------+------------
     public      | a
    (1 row)
  5. View the table group to which a table belongs.

    SELECT property_value AS table_group_name
    FROM hologres.hg_table_properties
    WHERE property_key = 'table_group' AND table_name = '<table_name>';

    Result:

    table_group_name
    ------------------
     test_tg_default
    (1 row)

Create a table group

If you have a new service or need to create a table group with a new shard count, you can use the following statement.

Note
  • After you create a new table group, the original tables and data remain in the original table group. They are not automatically migrated to the new table group.

  • The original table group is removed only after you migrate or delete all of its tables and data.

CALL HG_CREATE_TABLE_GROUP ('<new_tg_name>', <shard_count>);

Parameters:

Parameter

Type

Description

new_tg_name

Text

The name of the new table group.

shard_count

INT4

The shard count for the table group.

Example:

-- Create a new table group named tg_8 with a shard count of 8.
CALL HG_CREATE_TABLE_GROUP ('tg_8', 8);

Modify the default table group

After you create a database, a default table group with a default shard count is created in the instance. For more information, see Instance management. If a database has multiple table groups and you want to change the default one, you can use the following statement. After the change, new tables are stored in the new default table group.

Note

You can run the following statement to modify the default table group in Hologres V0.9 and later. If your instance is an earlier version, you must upgrade it first.

CALL HG_UPDATE_DATABASE_PROPERTY ('default_table_group', '<tg_name>');

Description:

Parameter

Type

Description

tg_name

TEXT

The name of the default table group. After you set this parameter, the shard count of this table group is used.

Example:

-- Set the new table group as the default. New tables will use this table group by default (for V0.9 and later).
CALL HG_UPDATE_DATABASE_PROPERTY ('default_table_group', 'tg_8');

Place a new table into a specified table group

You can use the following statements to explicitly place a new table into a specified table group.

BEGIN;
CREATE TABLE table_name (
    col type,
  ....
);
CALL SET_TABLE_PROPERTY('table_name', 'table_group', '<tg_name>');
COMMIT;

Parameters:

Parameter

Type

Description

table_name

TEXT

The name of the new table.

tg_name

TEXT

The name of the specified table group. After you set this parameter, the shard count of this table group is used.

Example:

-- Create a table named tbl1 and associate it with the table group named tg_8.
BEGIN;
CREATE TABLE tbl1 (
    col1 text
);
CALL SET_TABLE_PROPERTY('tbl1', 'table_group', 'tg_8');
COMMIT;

Migrate a table to a new table group (resharding)

In Hologres, shards improve data processing concurrency. A proper shard count helps improve query and write performance. In most cases, the default shard count for a Hologres instance is sufficient, and you do not need to modify it manually.

After an instance is scaled out, for example, from 32 cores to 128 cores, the shard count of existing databases does not change by default. We recommend that you increase the shard count for the databases to achieve better performance. If you create a new database in the instance, the default shard count for the current instance type is used. For more information about instance types and shards, see Instance management.

After an instance is scaled out or scaled in, the shard count of its existing databases does not automatically increase or decrease. You must use statements to set the shard count and then re-import the data.

  • For standard tables and physical partitioned tables, you can use either the `REBUILD` syntax or a built-in stored procedure.

  • For logical partitioned tables, we recommend that you use the `REBUILD` syntax. This syntax can automatically perform sequential execution by partition.

Resharding using the REBUILD syntax

In Hologres V3.1 and later, the `REBUILD` command is supported for modifying table properties, including migrating a table to a different table group. The `REBUILD` syntax can run migration tasks asynchronously and supports real-time monitoring of task progress. For more information, see REBUILD (Beta).

Resharding using a built-in stored procedure

In Hologres V0.10 and later, a resharding command is provided. After you modify the shard count, this command automatically rebalances the data. You can reshard the original tables and data without recreating tables or re-importing data. This simplifies the operations and helps achieve optimal performance.

  • Limits

    • The resharding feature is supported only in Hologres V0.10 and later. You can view your Hologres instance version on the instance details page in the Hologres console. If your instance version is earlier than V0.10, see Common upgrade preparation errors or join the Hologres DingTalk group to provide feedback. For more information, see Obtain online support for Hologres.

    • Currently, resharding is performed at the table level. When you reshard a table, you must stop writing data to it from sources such as Flink and Data Integration. Queries on the table are not affected. In Hologres V1.1 and later, you can run set table readonly to enable automatic failover for real-time write tasks.

    • Resharding consumes CPU resources and increases storage usage during the process. We recommend that you perform resharding during off-peak hours.

    • If binary logging is enabled for a table, disable it before resharding. Enable binary logging again after resharding is complete. For more information, see Subscribe to Hologres binary logs.

    • Resharding is not supported for tables that contain columns with `SERIAL` auto-increment sequences or `DEFAULT` values. An error is reported if you reshard a table with a `SERIAL` column. The `DEFAULT` property is lost after a table with a `DEFAULT` column is resharded.

    • A table cannot have other dependencies, such as views, during resharding. If dependencies exist, you must delete them before resharding. Otherwise, the error "ERROR: resharding table xxx can not executed because other objects depend on it." is reported.

    • In Hologres V2.2.29 and later and V3.0.36 and later, you can reshard tables that have view dependencies. To do this, run the set hg_experimental_hg_insert_overwrite_enable_view=on; command to enable the GUC parameter.

    • Resharding is applicable only to the simple permission model, not the expert permission model. For more information about Hologres permission models, see Hologres permission model.

    • Resharding does not retain the dynamic partitioning property of a table.

    • Only resharding operations in Hologres V2.0 and later retain column `COMMENTS`. If your instance version is earlier than V2.0, you must back up the column `COMMENTS` beforehand and manually set them after resharding is complete.

  • Syntax example

    • If your instance is V2.0.24 or later, we recommend that you use HoloWeb to perform resharding. For more information, see Table Resharding.

    • If your instance version is earlier than V2.0.24, you can use the following commands to migrate business tables to a new table group. If the instance version is earlier than V0.10, you must upgrade it first.

    Note
    • Before migration, you must have a new table group. If you do not have one, create one first. For more information, see Create a table group.

    • When you migrate a table, you must stop writing data to it. Queries are not affected.

    • After all tables in the original table group are migrated, the original table group is automatically deleted. If your business requires multiple table groups, set an appropriate shard count for each one.

    • When you migrate partitioned tables, you only need to perform the operation on the parent table.

    • If your instance is a compute group type and you need to migrate a table from Table Group A to the target Table Group B, you must use the primary compute group W of Table Group B to perform the migration. In addition, compute group W must have access permissions to Table Group A. This means compute group W must be loaded as a follower compute group of Table Group A. For more information about how to grant table group permissions to a compute group, see Authorize a compute group to access data.

    -- Command syntax for V1.1 and later
    CALL HG_MOVE_TABLE_TO_TABLE_GROUP('<table_name>','<new_table_group_name>');
    
    -- Command syntax for V0.10
    CALL HG_UPDATE_TABLE_SHARD_COUNT('<table_name>','<new_table_group_name>');
  • Parameters

    Parameter

    Description

    Example

    table_name

    The name of the table to migrate. Only one table can be migrated at a time. To migrate multiple tables, run the command multiple times. For a partitioned table, you only need to operate on the parent table.

    new_table

    table_group_name

    The name of the new table group.

    new_tg

  • Exception handling

    During table resharding, the table is first set to read-only and then migrated to the new table group using a temporary table. Because resharding tasks involve data import and may take a long time, various exceptions can occur, such as out-of-memory (OOM) errors or manual task termination. In these cases, the original table remains in a read-only state, and a temporary table named <initial_table_name>_xxxxxxxx appears in the database. In such cases, handle the situation as follows:

    • If the version of your Hologres instance is earlier than V2.0.24, upgrade the instance or submit a ticket. For more information about how to upgrade an instance, see Instance upgrades.

    • If your Hologres instance version is V2.0.24 or later:

      • If you are performing resharding in HoloWeb, click Continue or Cancel. For more information, see Table Resharding.

      • If you are resharding by running the preceding commands, follow these steps:

        1. To continue resharding the table, resolve the issue that caused the interruption, and then run the `HG_MOVE_TABLE_TO_TABLE_GROUP` command on the table again.

        2. To cancel resharding and restore the initial state, run the following commands in order:

          -- Cancel the readonly property of the original table.
          CALL set_table_property('<schema_name>.<table_name>','readonly','false');
          
          -- Clear the temporary table.
            -- Get the name of the temporary table (partitioned table).
          SELECT schema_name,target_temp_table_name FROM hologres.hg_resharding_properties WHERE reshard_table_name = <schema_name>.<table_name> AND is_parent_table IS TRUE;
            -- Get the name of the temporary table (non-partitioned table).
          SELECT schema_name,target_temp_table_name FROM hologres.hg_resharding_properties WHERE reshard_table_name = <schema_name>.<table_name> AND is_parent_table IS FALSE AND is_sub_table IS FALSE;
            -- Clear the temporary table.
          DROP TABLE IF EXISTS <schema_name>.<target_temp_table_name>;
          
          -- Clear the system table. The system table records the resharding progress of the current table. If you want to cancel the task, you must clear the corresponding data from the system table.
          CALL hologres.hg_internal_clear_resharding_properties('<schema_name>.<table_name>'); 

Delete a table group

You can use the following statement to delete an empty table group. You cannot delete a table group if it contains tables.

CALL HG_DROP_TABLE_GROUP('<tg_name>');

Example:

-- Delete the table group named tg_8.
CALL HG_DROP_TABLE_GROUP('tg_8');

View the skew relationship between shards and workers

An allocation relationship exists between the shard count and the number of workers. For more information, see Relationship between shards and worker compute nodes. If shards are not evenly allocated to workers, worker resource skew can occur, which leads to uneven loads and inefficient resource use. Therefore, Hologres V1.3 provides the worker_info system view to query the relationship among workers, table groups, and shards in the current database. This view helps you troubleshoot skew issues. For more information about how to check for worker resource skew, see View worker skew relationship.

Best practices

Table groups are an advanced feature. In most cases, we do not recommend creating new table groups or modifying shard counts for your business. If you have different business requirements, you can plan them based on our best practices. For more information, see Best practices for setting table groups.

FAQ

Resharding is a complex process that involves multiple steps, such as creating temporary tables, modifying the read-only state of the original table, writing to the target table, changing table names, and recording the synchronization status. If an exception occurs during any step, the system state may become uncertain. You can use the following methods to troubleshoot issues.

The internal error: Get rundown is not allowed in recovering state. error indicates that the table being updated is in a read-only state. You cannot perform `INSERT`, `UPDATE`, or `DELETE` operations on the table. You must exit the read-only state.

  1. Run the following command to retrieve the tables that are currently in a read-only state.

    select * from hologres.hg_table_properties where property_key ='readonly' and property_value='true';
  2. Run the following command to exit the read-only state.

    call set_table_property('<table_name>','readonly','false');

    table_name specifies the name of the table for which you want to exit the read-only state.