All Products
Search
Document Center

Tablestore:Create a global table

Last Updated:Feb 05, 2026

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

Precautions

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

Prerequisites

  • You must 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.

    Important

    If you initialize the client with the AccessKey of a Resource Access Management (RAM) user, you must ensure that the RAM user has permissions to create global tables. For more information about the required `Action` definitions, see Tablestore API operations.

Method description

public CreateGlobalTableResponse createGlobalTable(CreateGlobalTableRequest createGlobalTableRequest) throws TableStoreException, ClientException

Parameters of CreateGlobalTableRequest

  • baseTable (Required) BaseTable: The base table. By default, you can write data 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. When you use the multi-active mode, set this parameter to `true` as needed.

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

  • serveMode (Optional) ServeMode: The service mode. Valid values:

    • PRIMARY_SECONDARY (Default): Active-passive mode. The primary region is read-write, and the secondary regions are read-only. Data is synchronized from the primary region to the secondary regions. This mode is suitable for scenarios such as local reads, disaster recovery and backup, and remote hot standby.

    • PEER_TO_PEER: Multi-active mode. All regions are read-write. Conflicts are resolved at the row or column level based on the Last Write Wins (LWW) principle, which uses the latest timestamp to determine the winner. This mode is suitable for scenarios that require low-latency reads and writes across multiple regions.

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());
}

Create a global table in multi-active 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. In multi-active mode, you can set this to true or false as needed.
            true          
    ));

    // Set the service mode to multi-active (PEER_TO_PEER).
    req.setServeMode(GlobalTableTypes.ServeMode.PEER_TO_PEER);

    // 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());
}