All Products
Search
Document Center

Tablestore:Create a global table

Last Updated:Jan 09, 2026

This topic describes how to create a global table in Tablestore using the Java SDK.

Precautions

After the creation operation is successful, the system asynchronously synchronizes the data. You can call the `DescribeGlobalTable` operation to check the status of the global table. The global table is created when its status changes to `active`.

Prerequisites

  • Create instances in the source and destination regions.

  • Create a data table in the source region. The table must have the following configurations: time to live (TTL) is set to -1 (data never expires), max versions is set to 1, max version drift is set to unlimited (`Integer.MAX_VALUE`), and row versioning is enabled (`updateFullRow` is `True`).

    Important

    The following limits apply after you enable row versioning:

    • A single row can contain a maximum of 256 columns.

    • You cannot manually specify version numbers when you write data. The system generates them automatically.

    • When you perform an `Update` operation, the system first reads the current row version. This action results in a minor increase in read load.

  • Initialize the client.

Method description

public CreateGlobalTableResponse createGlobalTable(CreateGlobalTableRequest createGlobalTableRequest) throws TableStoreException, ClientException

Parameters of CreateGlobalTableRequest

  • baseTable (Required) BaseTable: The base table. By default, data can be written to the base table. This parameter includes the following subparameters.

    Name

    Type

    Description

    regionId (Required)

    String

    The region ID. For example, `cn-hangzhou`.

    instanceName (Required)

    String

    The instance name.

    tableName (Required)

    String

    The name of the base table. This is also the name of the global table.

  • placements (Required) List<Placement>: The list of placement settings for the table. This parameter includes the following subparameters.

    Name

    Type

    Description

    regionId (Required)

    String

    The region ID. For example, `cn-beijing`.

    instanceName (Required)

    String

    The instance name.

    writable (Required)

    boolean

    Specifies whether the table is writable. The default value is `false`. When you use the active-passive mode, keep the default configuration.

  • syncMode (Required) SyncMode: The data synchronization mode. Currently, only ROW (row-level synchronization) is supported.

  • serveMode (Optional) ServeMode: The service mode. The value must be PRIMARY_SECONDARY (active-passive mode).

Examples

Create a global table in active-passive mode.

private static void createGlobalTableExample(SyncClient client){
    // Construct the request.
    CreateGlobalTableRequest req = new CreateGlobalTableRequest(
            // Configure the base table. The table must already exist.
            new GlobalTableTypes.BaseTable(
                    // The region ID of the base table.
                    "cn-hangzhou",  
                    // The instance name of the base table.   
                    "i-gt-test",  
                    // The name of the base table. This is also the name of the global table.     
                    "t-gt-test-1"
            ),
            // The synchronization mode of the global table. Currently, only the ROW mode (row-level synchronization) is supported.
            GlobalTableTypes.SyncMode.ROW
    );

    // Add associated tables. You can add multiple tables.
    req.addPlacement(new GlobalTableTypes.Placement(
            // The region ID of the associated table.
            "cn-shanghai", 
            // The instance name of the associated table. The instance must already exist.
            // The instance cannot contain a table with the same name as the base table. The system automatically creates the table.     
            "i-dest-test",         
            // Specifies whether the table is writable. false indicates read-only. In active-passive mode, this can only be set to false.
            false
    ));

    // Set the service mode to primary/secondary architecture (PRIMARY_SECONDARY).
    req.setServeMode(GlobalTableTypes.ServeMode.PRIMARY_SECONDARY);

    // Send the request.
    CreateGlobalTableResponse createResp = client.createGlobalTable(req);

    // Print the response.
    System.out.println("Global table creation initiated.");
    System.out.println("RequestId: " + createResp.getRequestId());
    System.out.println("GlobalTableId: " + createResp.getGlobalTableId());
}