All Products
Search
Document Center

Data Transmission Service:Synchronize data from an RDS PostgreSQL instance to an ApsaraDB for ClickHouse cluster

Last Updated:Nov 20, 2025

You can use Data Transmission Service (DTS) to synchronize data from a PostgreSQL database to an ApsaraDB for ClickHouse cluster. This topic uses an RDS PostgreSQL instance as an example to describe this procedure.

Prerequisites

  • You have created an ApsaraDB for ClickHouse cluster. The storage space of the cluster must be larger than the data volume that you want to synchronize.

    Note

    For the supported versions of the source and destination databases, see Synchronization solution overview.

  • You have set the wal_level parameter of the source RDS PostgreSQL instance to logical. For more information, see Set Instance Parameters.

Precautions

Source database limits

  • Bandwidth: The server that hosts the source database must have an outbound bandwidth of 100 Mbit/s or higher. Otherwise, the data synchronization speed is affected.

  • Synchronization objects:

    • The tables to be synchronized must have primary keys or UNIQUE constraints, and the values in the columns that have UNIQUE constraints must be unique. Otherwise, data may be duplicated in the destination database.

      Note

      If the destination table was not created by DTS (that is, you did not select Schema Synchronization for Synchronization Types), you must ensure that the destination table has the same primary key or non-null unique constraint as the corresponding source table. Otherwise, duplicate data may appear in the target database.

    • The name of the database to be synchronized cannot contain a hyphen (-), such as dts-testdata.

    • DTS does not support synchronization of tables that use the TimescaleDB extension or tables that have cross-schema inheritance relationships.

    • If you want to synchronize data at the table level and need to edit the objects, such as mapping table and column names, and the number of tables in a single synchronization task exceeds 5,000, we recommend that you split the tables into multiple tasks or configure a task to synchronize the entire database. Otherwise, a request error may be reported after you submit the task.

  • WAL logs:

    • You must enable WAL. Set the wal_level parameter to logical.

    • For an incremental synchronization task, DTS requires that the WAL logs of the source database be retained for more than 24 hours. For a task that performs both full and incremental synchronization, DTS requires that the WAL logs of the source database be retained for at least 7 days. You can change the retention period to more than 24 hours after the initial full data synchronization is complete. Otherwise, the DTS task may fail because DTS cannot obtain the WAL logs. In extreme cases, data inconsistency or loss may occur. Issues that are caused by a WAL log retention period shorter than the required period are not covered by the DTS SLA.

  • Restrictions:

    • If you perform DDL operations with non-standard syntax on the synchronization objects, the synchronization task may fail or data may be lost.

    • If you perform a major version upgrade on the source database while the synchronization instance is running, the instance fails and cannot be recovered. You must reconfigure the synchronization instance.

    • Due to the limits of logical replication in the source database, if a single piece of data to be synchronized exceeds 256 MB after an incremental change during the runtime of the synchronization instance, the instance may fail and cannot be recovered. You must reconfigure the synchronization instance.

    • During schema synchronization and initial full data synchronization, do not perform DDL operations to change the schemas of databases or tables. Otherwise, the data synchronization task fails.

  • To ensure that sync tasks run properly and to prevent logical subscription interruptions during primary/standby switchovers, the source RDS for PostgreSQL instance must support and enable Logical Replication Slot Failover.

  • If the source database has long-running transactions and the instance includes an incremental synchronization task, the Write-Ahead Logging (WAL) logs that are generated before the long-running transactions are committed cannot be cleared and may accumulate. This may cause insufficient disk space in the source database.

Other limits

  • A single data synchronization task can synchronize data from only one database. To synchronize data from multiple databases, you must configure a separate data synchronization task for each database.

  • The time-related data types in ApsaraDB for ClickHouse have range limitations. If you synchronize time data that is outside this range, the synchronized data in ApsaraDB for ClickHouse is incorrect. For more information, see Time information.

  • All selected columns of the Partition Key parameter must be non-empty fields. Otherwise, a synchronization task fails.

    Note

    The partition key supports only fields of the BIGINT, INT, TIMESTAMP, DATETIME, and DATE data types.

  • The number of databases to be synchronized cannot exceed the ApsaraDB for ClickHouse limit of 256.

  • The names of the databases, tables, and columns to be synchronized must comply with the ApsaraDB for ClickHouse naming conventions. For more information, see Object naming convention limits.

  • During the schema synchronization phase, DTS adds the _sign, _is_deleted, and _version fields to the destination table. If you do not select Schema Synchronization when you configure the Synchronization Types, you must manually create a table on the destination instance to receive data and add these fields to the table. For information about the table creation requirements and field details, see Table and field information.

  • In the following three scenarios, you must run the ALTER TABLE schema.table REPLICA IDENTITY FULL; command on the table to be synchronized in the source database before you write data to the table. This ensures data consistency. During the execution of this command, we recommend that you do not perform table locking operations. Otherwise, the table may be locked. If you skip the related check item in the precheck, DTS automatically runs this command when the instance is initialized.

    • When the instance runs for the first time.

    • When you synchronize data at the schema level, and a new table is created in the schema to be synchronized or a table to be synchronized is rebuilt using the RENAME command.

    • When you use the feature of modifying synchronization objects.

    Note
    • In the command, replace schema and table with the schema name and table name of the data to be synchronized.

    • We recommend that you perform this operation during off-peak hours.

  • DTS creates the following temporary tables in the source database to obtain the DDL statements of incremental data (the DDL statements are not written to the destination database), the schemas of incremental tables, and heartbeat information. Do not delete these temporary tables from the source database during data synchronization. Otherwise, the DTS task may become abnormal. The temporary tables are automatically deleted after the DTS instance is released.

    public.dts_pg_class, public.dts_pg_attribute, public.dts_pg_type, public.dts_pg_enum, public.dts_postgres_heartbeat, public.dts_ddl_command, public.dts_args_session, and public.aliyun_dts_instance.

  • During data synchronization, DTS creates a replication slot with the dts_sync_ prefix in the source database to replicate data. DTS can obtain the incremental logs of the source database within 15 minutes from this replication slot.

    Note
    • DTS automatically deletes the replication slot after the instance is released. If you change the password of the database account or delete the IP address of the DTS server from the whitelist of the source database during data synchronization, the replication slot cannot be automatically deleted. In this case, you must manually delete the replication slot from the source database to prevent it from occupying disk space and making the ApsaraDB RDS for PostgreSQL instance unavailable.

    • When the synchronization task is released or fails, DTS automatically clears the replication slot. If a primary/secondary failover occurs on the ApsaraDB RDS for PostgreSQL instance, you must log on to the secondary database to manually clear the replication slot.

    Amazon slot查询信息

  • During initial full data synchronization, DTS consumes some read and write resources of the source and destination databases. This may increase the database load. Before you synchronize data, evaluate the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours, for example, when the CPU load of both databases is below 30%.

  • Initial full data synchronization runs concurrent INSERT operations, which causes table fragmentation in the destination database. As a result, the storage space that is occupied by the tables in the destination database is larger than that in the source database after the initial full data synchronization is complete.

  • During synchronization, if a data source other than DTS writes data to the destination database, data inconsistency may occur between the source and destination databases. In some cases, the synchronization instance may even fail.

  • DTS verifies data content. DTS does not verify metadata such as sequences. You must verify the metadata on your own.

  • If an instance fails, DTS helpdesk will try to recover the instance within 8 hours. During the recovery process, operations such as restarting the instance and adjusting parameters may be performed.

    Note

    When parameters are adjusted, only the parameters of the DTS instance are modified. The parameters of the database are not modified. The parameters that may be modified include but are not limited to those described in Modify instance parameters.

  • When you synchronize a partitioned table, you must include both the parent table and its child tables in the synchronization objects. Otherwise, data inconsistency may occur for the partitioned table.

    Note

    The parent table of a PostgreSQL partitioned table does not directly store data. All data is stored in the child tables. The synchronization task must include the parent table and all its child tables. Otherwise, data in the child tables may be missed during synchronization, which leads to data inconsistency between the source and destination databases.

Special cases

  • When the source instance is an ApsaraDB RDS for PostgreSQL instance

    Do not change the endpoint or zone of the ApsaraDB RDS for PostgreSQL instance during data synchronization. Otherwise, the synchronization fails.

  • When the source instance is a self-managed PostgreSQL database

    You must make sure that the values of the max_wal_senders and max_replication_slots parameters are greater than the sum of the number of used replication slots in the current database and the number of DTS instances that you want to create for the self-managed PostgreSQL database.

  • When the source instance is Google Cloud Platform Cloud SQL for PostgreSQL, the Database Account for the source database must be an account with the cloudsqlsuperuser permission. When you select synchronization objects, you must select objects that this account has permission to manage, or grant this account the Owner permission for the objects to be synchronized. For example, you can run the GRANT <owner_of_object_to_sync> TO <source_account_for_task> command to allow this account to perform related operations as the owner of the objects to be synchronized.

    Note

    An account with the cloudsqlsuperuser permission cannot manage data whose owner is another account with the cloudsqlsuperuser permission.

Billing

Synchronization typeTask configuration fee
Schema synchronization and full data synchronizationFree of charge.
Incremental data synchronizationCharged. For more information, see Billing overview.

SQL operations supported by incremental synchronization

Operation type

SQL statements

DML

INSERT, UPDATE, and DELETE

DDL

  • CREATE TABLE

  • TRUNCATE TABLE

  • ALTER TABLE

  • ADD COLUMN

  • MODIFY COLUMN

  • DROP TABLE and DROP COLUMN

Data type mappings

RDS PostgreSQL instances and ApsaraDB for ClickHouse clusters support different data types that do not have a one-to-one mapping. Therefore, during initial schema synchronization, DTS performs type mapping based on the data types supported by the destination database.

Permissions required for database accounts

Database

Required permissions

Creation and authorization method

Source RDS PostgreSQL instance

A privileged account that is the owner of the database to be synchronized.

Create an account and Create a database.

Destination ApsaraDB for ClickHouse cluster

  • Version 22.8 or later: Read and write permissions on the destination database. A privileged account meets the requirements.

  • Version 21.8: Read/Write And Settings and Allow DDL.

Community-Compatible Edition Account Management.

Procedure

  1. Use one of the following methods to go to the Data Synchronization page and select the region in which the data synchronization instance resides.

    DTS console

    1. Log on to the DTS console.

    2. In the left-side navigation pane, click Data Synchronization.

    3. In the upper-left corner of the page, select the region in which the data synchronization task resides.

    DMS console

    Note

    The actual operations may vary based on the mode and layout of the DMS console. For more information, see Simple mode and Customize the layout and style of the DMS console.

    1. Log on to the DMS console.

    2. In the top navigation bar, move the pointer over Data + AI and choose DTS (DTS) > Data Synchronization.

    3. From the drop-down list to the right of Data Synchronization Tasks, select the region in which the data synchronization instance resides.

  2. Click Create Task to go to the task configuration page.

  3. Configure the source and destination databases. The following table describes the parameters.

    Category

    Configuration

    Description

    None

    Task Name

    The name of the DTS task. DTS automatically generates a task name. We recommend that you specify a descriptive name that makes it easy to identify the task. You do not need to specify a unique task name.

    Source Database

    Select Existing Connection

    • If you use a database instance that is registered with DTS, select the instance from the drop-down list. DTS automatically populates the following database parameters for the instance. For more information, see Manage database connections.

      Note

      In the DMS console, you can select the database instance from the Select a DMS database instance drop-down list.

    • If you fail to register the instance with DTS, or you do not need to use the instance that is registered with DTS, you must configure the following database information.

    Database Type

    Select PostgreSQL.

    Access Method

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region where the source RDS PostgreSQL instance is located.

    Replicate Data Across Alibaba Cloud Accounts

    In this example, a database of the current Alibaba Cloud account is used. Select No.

    Instance ID

    Select the ID of the source RDS PostgreSQL instance.

    Database Name

    Enter the name of the database in the source RDS PostgreSQL instance that contains the objects to be synchronized.

    Database Account

    Enter the database account for the source RDS PostgreSQL instance. For more information, see Permissions required for database accounts.

    Database Password

    The password that is used to access the database.

    Destination Database

    Select Existing Connection

    • If you use a database instance that is registered with DTS, select the instance from the drop-down list. DTS automatically populates the following database parameters for the instance. For more information, see Manage database connections.

      Note

      In the DMS console, you can select the database instance from the Select a DMS database instance drop-down list.

    • If you fail to register the instance with DTS, or you do not need to use the instance that is registered with DTS, you must configure the following database information.

    Database Type

    Select ClickHouse.

    Access Method

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region where the destination ApsaraDB for ClickHouse cluster resides.

    Replicate Data Across Alibaba Cloud Accounts

    In this example, a database of the current Alibaba Cloud account is used. Select No.

    Cluster Type

    Select the type of the ApsaraDB for ClickHouse cluster as needed.

    Cluster ID

    Select the ID of the destination ApsaraDB for ClickHouse cluster.

    Database Account

    Enter the database account of the destination ApsaraDB for ClickHouse cluster. For more information about the permission requirements, see Permissions required for database accounts.

    Database Password

    The password that is used to access the database.

  4. Click Test Connectivity and Proceed in the lower part of the page.

    Note
    • Make sure that the CIDR blocks of DTS servers can be automatically or manually added to the security settings of the source and destination databases to allow access from DTS servers. For more information, see Add DTS server IP addresses to a whitelist.

    • If the source or destination database is a self-managed database and its Access Method is not set to Alibaba Cloud Instance, click Test Connectivity in the CIDR Blocks of DTS Servers dialog box.

  5. Configure the objects to be synchronized.

    1. In the Configure Objects step, configure the objects that you want to synchronize.

      Configuration

      Description

      Synchronization Types

      The synchronization types. By default, Incremental Data Synchronization is selected. You must also select Schema Synchronization and Full Data Synchronization. After the precheck is complete, DTS synchronizes the historical data of the selected objects from the source database to the destination cluster. The historical data is the basis for subsequent incremental synchronization.

      Processing Mode of Conflicting Tables

      • Precheck and Report Errors: checks whether the destination database contains tables that have the same names as tables in the source database. If the source and destination databases do not contain tables that have identical table names, the precheck is passed. Otherwise, an error is returned during the precheck, and the data synchronization task cannot be started.

        Note

        If the source and destination databases contain tables with identical names and the tables in the destination database cannot be deleted or renamed, you can use the object name mapping feature to rename the tables that are synchronized to the destination database. For more information, see Map object names.

      • Ignore Errors and Proceed: skips the precheck for identical table names in the source and destination databases.

        Warning

        If you select Ignore Errors and Proceed, data inconsistency may occur and your business may be exposed to potential risks.

        • If the source and destination databases have the same schema and a data record in the destination database has the same primary key value or unique key value as a data record in the source database:

          • During full data synchronization, DTS does not synchronize the data record to the destination database. The existing data record in the destination database is retained.

          • During incremental data synchronization, DTS synchronizes the data record to the destination database. The existing data record in the destination database is overwritten.

        • If the source and destination databases have different schemas, data may fail to be initialized. In this case, only some columns are synchronized, or the data synchronization instance fails. Proceed with caution.

      Capitalization of Object Names in Destination Instance

      The capitalization of database names, table names, and column names in the destination instance. By default, DTS default policy is selected. You can select other options to ensure that the capitalization of object names is consistent with that in the source or destination database. For more information, see Specify the capitalization of object names in the destination instance.

      Source Objects

      Select one or more objects from the Source Objects section and click the 向右 icon to add the objects to the Selected Objects section.

      Note

      In the Source Objects box, you can select objects for synchronization at the schema or table level.

      Selected Objects

      • To configure the name of an object to be synchronized in the destination database or specify an object that receives data in the destination database, right-click the object in the Selected Objects section. For more information, see Map object names.

      • To remove a selected object, click the object in the Selected Objects section and then click the image icon to move the object to the Source Objects section.

      Note
      • If you use the object name mapping feature to rename an object, other objects that are dependent on the object may fail to be synchronized.

      • To specify WHERE conditions to filter data, right-click a table in the Selected Objects section. In the dialog box that appears, specify the conditions. For more information, see Specify filter conditions.

      • To select SQL operations for incremental synchronization, right-click an object in the Selected Objects section. In the dialog box that appears, select the SQL operations that you want to synchronize.

    2. Click Next: Advanced Settings to configure advanced settings.

      Configuration

      Description

      Dedicated Cluster for Task Scheduling

      By default, DTS schedules the task to the shared cluster if you do not specify a dedicated cluster. If you want to improve the stability of data synchronization instances, purchase a dedicated cluster. For more information, see What is a DTS dedicated cluster.

      Retry Time for Failed Connections

      The retry time range for failed connections. If the source or destination database fails to be connected after the data synchronization task is started, DTS immediately retries a connection within the time range. Valid values: 10 to 1440. Unit: minutes. Default value: 720. We recommend that you set this parameter to a value greater than 30. If DTS reconnects to the source and destination databases within the specified time range, DTS resumes the data synchronization task. Otherwise, the data synchronization task fails.

      Note
      • If you specify different retry time ranges for multiple data synchronization tasks that have the same source or destination database, the shortest retry time range takes precedence.

      • When DTS retries a connection, you are charged for the DTS instance. We recommend that you specify the retry time range based on your business requirements. You can also release the DTS instance at your earliest opportunity after the source and destination instances are released.

      Retry Time for Other Issues

      The retry time range for other issues. For example, if the DDL or DML operations fail to be performed after the data synchronization task is started, DTS immediately retries the operations within the time range. Valid values: 1 to 1440. Unit: minutes. Default value: 10. We recommend that you set this parameter to a value greater than 10. If the failed operations are successfully performed within the specified time range, DTS resumes the data synchronization task. Otherwise, the data synchronization task fails.

      Important

      The value of the Retry Time for Other Issues parameter must be smaller than the value of the Retry Time for Failed Connections parameter.

      Enable Throttling for Full Data Synchronization

      During full data synchronization, DTS uses the read and write resources of the source and destination databases. This may increase the load on the database servers. You can configure the Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s) parameters for full data synchronization tasks to reduce the load on the destination database server.

      Note

      You can configure this parameter only if Full Data Synchronization is selected for the Synchronization Types parameter.

      Enable Throttling for Incremental Data Synchronization

      Specifies whether to enable throttling for incremental data synchronization. You can enable throttling for incremental data synchronization based on your business requirements. To configure throttling, you must configure the RPS of Incremental Data Synchronization and Data synchronization speed for incremental synchronization (MB/s) parameters. This reduces the load on the destination database server.

      Environment Tag

      You can select an environment tag to identify the instance. In this example, no tag is selected.

      Configure ETL

      Specifies whether to enable the extract, transform, and load (ETL) feature. For more information, see What is ETL? Valid values:

      Monitoring and Alerting

      Specifies whether to configure alerting for the data synchronization instance. If the task fails or the synchronization latency exceeds the specified threshold, alert contacts will receive notifications. Valid values:

    3. Click Next: Configure Database and Table Fields to configure the Type, Primary Key Column, Sort Key, Distribution Key, and Partition Key information for the tables to be synchronized in ClickHouse.

      • By default, these parameters are configured by DTS. To modify the parameters, set the Definition Status parameter to All.

      • Primary Key Column and Sort Key can be composite keys, which means you can select multiple fields from the corresponding drop-down lists as Primary Key Column or Sort Key, and you need to select one or more columns from the Primary Key Column as the Partition Key; the Distribution Key can only be a single field. For more information about primary key columns, sort keys, and partition keys, see CREATE TABLE.

        Note
        • The Partition Key parameter is optional. However, if you configure this parameter, all selected columns of the Partition Key parameter must be non-empty fields. Otherwise, the synchronization task fails.

        • The partition key supports only fields of the BIGINT, INT, TIMESTAMP, DATETIME, and DATE types. For the calculation logic, see Calculation logic of the partition key.

  6. Save the task settings and run a precheck.

    • To view the parameters to be specified when you call the relevant API operation to configure the DTS task, move the pointer over Next: Save Task Settings and Precheck and click Preview OpenAPI parameters.

    • If you do not need to view or have viewed the parameters, click Next: Save Task Settings and Precheck in the lower part of the page.

    Note
    • Before you can start the data synchronization task, DTS performs a precheck. You can start the data synchronization task only after the task passes the precheck.

    • If the data synchronization task fails the precheck, click View Details next to each failed item. After you analyze the causes based on the check results, troubleshoot the issues. Then, rerun the precheck.

    • If an alert is triggered for an item during the precheck:

      • If an alert item cannot be ignored, click View Details next to the failed item and troubleshoot the issue. Then, run a precheck again.

      • If an alert item can be ignored, click Confirm Alert Details. In the View Details dialog box, click Ignore. In the message that appears, click OK. Then, click Precheck Again to run a precheck again. If you ignore the alert item, data inconsistency may occur, and your business may be exposed to potential risks.

  7. Purchase the instance.

    1. Wait until the Success Rate becomes 100%. Then, click Next: Purchase Instance.

    2. On the buy page, configure the Billing Method and Instance Class parameters for the data synchronization task. The following table describes the parameters.

      Section

      Parameter

      Description

      New Instance Class

      Billing Method

      • Subscription: You pay for a subscription when you create a data synchronization instance. The subscription billing method is more cost-effective than the pay-as-you-go billing method for long-term use.

      • Pay-as-you-go: A pay-as-you-go instance is billed on an hourly basis. The pay-as-you-go billing method is suitable for short-term use. If you no longer require a pay-as-you-go data synchronization instance, you can release the instance to reduce costs.

      Resource Group Settings

      The resource group to which the data synchronization instance belongs. Default value: default resource group. For more information, see What is Resource Management?

      Instance Class

      DTS provides instance classes that vary in synchronization speed. You can select an instance class based on your business requirements. For more information, see Instance classes of data synchronization instances.

      Subscription Duration

      If you select the subscription billing method, specify the subscription duration and the number of data synchronization instances that you want to create. The subscription duration can be one to nine months, one year, two years, three years, or five years.

      Note

      This parameter is available only if you select the Subscription billing method.

    3. Read and select Data Transmission Service (Pay-as-you-go) Service Terms.

    4. Click Buy and Start. In the dialog box that appears, click OK.

      You can view the progress of the task in the task list.

Appendix

Time information

Data type

Minimum value

Maximum value

Date

1970-01-01 00:00:00

2149-06-06 00:00:00

Date32

1925-01-01 00:00:00

2283-11-11 00:00:00

DateTime

1970-01-01 08:00:00

2106-02-07 14:28:15

DateTime64

1925-01-01 08:00:00

2283-11-12 07:59:59

Table and field information

Tables

If you do not use the object name mapping feature, make sure that the tables you create meet the following requirements:

Important

If a destination table contains the ENGINE parameter, the parameter must be set to ENGINE = ReplicatedReplacingMergeTree(_version, _is_deleted). Otherwise, data inconsistency may occur.

  • If the destination database is an ApsaraDB for ClickHouse Community-compatible Edition cluster, you must create a local table and a distributed table. The name of the distributed table must be the same as that of the source table. The name of the local table is in the <Distributed table name>+_local format.

  • If the destination database is an ApsaraDB for ClickHouse Enterprise Edition cluster, you must create a table with the same name as the source table.

Fields

Note

You can execute the select * from table_name final where _sign>0; statement to query data that is synchronized to an ApsaraDB for ClickHouse cluster. In this statement, the WHERE clause can be used to filter the deleted data, and the final field behind the table name can be used to filter the data with the same sort keys.

Version

Field

Data type

Default value

Description

ApsaraDB for ClickHouse Community-compatible Edition cluster that runs ClickHouse V23.8 or earlier

_sign

Int8

1

The type of the DML operation. Valid values:

  • INSERT: 1.

  • UPDATE: 1.

  • DELETE: -1.

_version

UInt64

1

The timestamp when data is written to the ClickHouse cluster.

ApsaraDB for ClickHouse Enterprise Edition cluster or ApsaraDB for ClickHouse Community-compatible Edition cluster that runs CLickHouse V23.8 or later

_sign

Int8

1

The type of the DML operation. Valid values:

  • INSERT: 1.

  • UPDATE: 1.

  • DELETE: -1.

_is_deleted

UInt8

0

Specifies whether the data record is deleted. Valid values:

  • Insert: 0.

  • Delete: 1.

  • Update: 0.

_version

UInt64

1

The timestamp when data is written to the ClickHouse cluster.

Calculation logic for partition keys

Data type of source field

Calculation logic of partition key

BIGINT

intDiv(" + tablePartKey + ", 18014398509481984)

INT

intDiv(" + tablePartKey + ", 4194304)

TIMESTAMP

toYYYYMM(" + tablePartKey + ")

DATETIME

DATE