This topic describes how to synchronize data from an ApsaraDB RDS for SQL Server instance to an AnalyticDB for PostgreSQL instance by using Data Transmission Service (DTS). The data synchronization feature allows you to transfer and analyze data with ease.

Prerequisites

Usage notes

  • DTS uses read and write resources of the source and destination databases during full data migration. This may increase the loads of the database servers. If the database performance is unfavorable, the specification is low, or the data volume is large, database services may become unavailable. For example, DTS occupies a large amount of read and write resources in the following cases: a large number of slow SQL queries are performed on the source database, the tables have no primary keys, or a deadlock occurs in the destination database. Before you migrate data, evaluate the impact of data migration on the performance of the source and destination databases. We recommend that you migrate data during off-peak hours. For example, you can migrate data when the CPU utilization of the source and destination databases is less than 30%.
  • To ensure that the latency of data synchronization is accurate, DTS adds a heartbeat table to the source database. The name of the heartbeat table is dts_log_heart_beat.
  • In this scenario, DTS supports schema synchronization for the following types of objects: schema, table, view, function, and procedure.
    Warning ApsaraDB RDS for SQL Server and AnalyticDB for PostgreSQL are heterogeneous databases. The data types that they support do not have one-to-one correspondence. We recommend that you evaluate the impact of data type conversion on your business. For more information, see Data type mappings for schema synchronization.
  • DTS does not synchronize data of the following types: TIMESTAMP, CURSOR, ROWVERSION, HIERACHYID, SQL_VARIANT, SPATIAL GEOMETRY, SPATIAL GEOGRAPHY, and TABLE.

Billing

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

SQL operations that can be synchronized

  • DDL operation: ADD COLUMN
    Note DTS does not migrate transactional DDL operations.
  • DML operations: INSERT, UPDATE, and DELETE

Permissions required for database accounts

DatabaseRequired permissionAuthorization method
ApsaraDB RDS for SQL Server instancePermissions of the source database owner Modify the permissions of a standard account on an ApsaraDB RDS for SQL Server instance
AnalyticDB for PostgreSQL instance
  • LOGIN permission
  • SELECT, CREATE, INSERT, UPDATE, and DELETE permissions on the destination tables
  • CONNECT and CREATE permissions on the destination database
  • CREATE permission on the destination schemas
  • COPY permission (the permission to perform memory-based batch copy operations)
Note You can use the initial account of the AnalyticDB for PostgreSQL instance.
Manage users and permissions

Procedure

  1. Purchase a data synchronization instance. For more information, see Purchase a DTS instance.
    Note On the buy page, set the Source Instance parameter to SQL Server, the Destination Instance parameter to AnalyticDB for PostgreSQL, and the Synchronization Topology parameter to One-way Synchronization.
  2. Log on to the DTS console.
  3. In the left-side navigation pane, click Data Synchronization.
  4. At the top of the Synchronization Tasks page, select the region where the destination instance resides.
  5. Find the data synchronization instance and click Configure Synchronization Channel in the Actions column.
  6. Configure the source and destination instances.
    Configure the source and destination instances
    SectionParameterDescription
    N/ASynchronization Task NameThe task name that DTS automatically generates. We recommend that you specify a descriptive name that makes it easy to identify the task. You do not need to use a unique task name.
    Source Instance DetailsInstance TypeThe instance type of the source instance. Select RDS Instance.
    Instance RegionThe source region that you selected on the buy page. You cannot change the value of this parameter.
    Instance IDThe ID of the source ApsaraDB RDS for SQL Server instance.
    Database AccountThe database account of the ApsaraDB RDS for SQL Server instance. For information about the permissions that are required for the account, see Permissions required for database accounts.
    Database PasswordThe password of the database account.
    EncryptionSpecifies whether to encrypt the connection to the source instance. Select Non-encrypted or SSL-encrypted. If you want to select SSL-encrypted, you must enable SSL encryption for the ApsaraDB RDS for SQL Server instance before you configure the data synchronization task. For more information, see Configure SSL encryption for an ApsaraDB RDS for SQL Server instance.
    Note The Encryption parameter is available only for regions in the Chinese mainland and the China (Hong Kong) region.
    Destination Instance DetailsInstance TypeThe value of this parameter is fixed to AnalyticDB for PostgreSQL.
    Instance RegionThe destination region that you selected on the buy page. You cannot change the value of this parameter.
    Instance IDThe ID of the destination AnalyticDB for PostgreSQL instance.
    Database NameThe name of the destination database.
    Database AccountThe database account of the destination AnalyticDB for PostgreSQL instance. For information about the permissions that are required for the account, see Permissions required for database accounts.
    Database PasswordThe password of the database account.
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note
    • You do not need to modify the security settings for ApsaraDB instances (such as ApsaraDB RDS for MySQL and ApsaraDB for MongoDB) and ECS-hosted databases. DTS automatically adds the CIDR blocks of DTS servers to the whitelists of ApsaraDB instances or the security group rules of Elastic Compute Service (ECS) instances. For more information, see Add the CIDR blocks of DTS servers to the security settings of on-premises databases.
    • After data synchronization is complete, we recommend that you remove the CIDR blocks of DTS servers from the whitelists or security groups.
  8. Select the synchronization policy and the objects to be synchronized.
    Select the synchronization policy and the objects to be synchronized
    SettingDescription
    Initialize SynchronizationInitial Schema Synchronization, Initial Full Data Synchronization, and Initial Incremental Data Synchronization are selected by default. After the precheck is complete, DTS synchronizes the schemas and data of objects from the source instance to the destination instance. The schemas and data are the basis for subsequent incremental synchronization.
    Processing Mode In Existed Target Table
    • Pre-check and Intercept: checks whether the destination database contains tables that have the same names as tables in the source database. If the destination database does not contain tables that have the same names as tables in the source database, the precheck is passed. Otherwise, an error is returned during precheck and the data synchronization task cannot be started.
      Note If the source and destination databases contain identical table 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 Rename an object to be synchronized.
    • 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, DTS does not synchronize data records that have the same primary keys as data records in the destination database.
      • If the source and destination databases have different schemas, initial data synchronization may fail. In this case, only part of columns are synchronized, or the data synchronization task fails.
    Merge Multi Tables
    • Yes: In online transaction processing (OLTP) scenarios, sharding is implemented to speed up the response to business tables. However, AnalyticDB for PostgreSQL allows you to store a large amount of data in a single table and makes your SQL queries more efficient. You can merge multiple source tables that have the same schema into a single destination table. This feature allows you to synchronize data from multiple tables in the source database to a single table in AnalyticDB for PostgreSQL.
      Note
      • After you select multiple tables from the source database, you must change the names of these tables to the name of the destination table in AnalyticDB for PostgreSQL. To do this, you can use the object name mapping feature. For more information about how to use this feature, see Rename an object to be synchronized.
      • You must add a column named __dts_data_source to the destination table in AnalyticDB for PostgreSQL. This column is used to record the data source. The data type of this column is TEXT. DTS writes column values in the following format: <Data synchronization instance ID>:<Source database name>.<Source schema name>.<Source table name>. Such column values allow DTS to identify each source table. For example, dts********:dtstestdata.testschema.customer1 indicates that the source table is customer1.
      • If you set this parameter to Yes, all the selected source tables in the task are merged into a destination table. If you do not need to merge specific source tables, you can create a separate data synchronization task for these tables.
    • No: the default value.
    Select the operation typesSelect the types of operations that you want to synchronize based on your business requirements. All operation types are selected by default.
    Select the objects to be synchronized

    Select one or more objects from the Available section and click the Rightwards arrow icon to add the objects to the Selected section.

    In this scenario, data synchronization is performed between heterogeneous databases. Therefore, the objects to synchronize are tables, and other objects such as views, triggers, and stored procedures are not synchronized to the destination database.
    Note
    • By default, after an object is synchronized to the destination instance, the name of the object remains unchanged. You can use the object name mapping feature to rename the objects that are synchronized to the destination instance. For more information, see Rename an object to be synchronized.
    • If you set the Merge Multi Tables parameter to Yes, you must change the names of the selected tables to the name of the destination table in the AnalyticDB for PostgreSQL instance. To do this, you can use the object name mapping feature.
    Add quotation marks to the target objectSpecify whether you need to enclose object names in quotation marks. If you select Yes and the following conditions are met, DTS encloses object names in single quotation marks (') or double quotation marks (") during schema synchronization and incremental data synchronization.
    • The business environment of the source database is case-sensitive, and the database name contains both uppercase and lowercase letters.
    • A source table name does not start with a letter and contains characters other than letters, digits, and special characters.
      Note A source table name can contain only the following special characters: underscores (_), number signs (#), and dollar signs ($).
    • The names of the schemas, tables, or columns that you want to synchronize are keywords, reserved keywords, or invalid characters in the destination database.
    Note If you select Yes, after DTS synchronizes data to the destination database, you must specify the object name in quotation marks to query the object.
    Rename Databases and Tables

    You can use the object name mapping feature to rename the objects that are synchronized to the destination instance. For more information, see Object name mapping.

    Retry Time for Failed Connections
    By default, if DTS fails to connect to the source or destination database, DTS retries within the next 720 minutes (12 hours). You can specify the retry time based on your needs. If DTS reconnects to the source and destination databases within the specified time, DTS resumes the data synchronization task. Otherwise, the data synchronization task fails.
    Note When DTS retries a connection, you are charged for the DTS instance. We recommend that you specify the retry time based on your business needs. You can also release the DTS instance at your earliest opportunity after the source and destination instances are released.
  9. Specify the table type, primary key column, and distribution key of the tables that you want to synchronize to the AnalyticDB for PostgreSQL instance.
    Specify the table type, primary key column, and distribution key
    Note For more information about primary key columns and distribution columns, see Define constraints and Define table distribution.
  10. In the lower-right corner of the page, click Precheck.
    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 task fails to pass the precheck, click the Info icon icon next to each failed item to view details.
      • After you troubleshoot the issues based on the causes, run a precheck again.
      • If you do not need to troubleshoot the issues, ignore failed items and run a precheck again.
  11. Close the Precheck dialog box after the following message is displayed: The precheck is passed. Then, the data synchronization task starts.
  12. Wait until the initial synchronization is complete and the data synchronization task is in the Synchronizing state.
    You can view the status of the data synchronization task on the Synchronization Tasks page. View the status of a data synchronization task

FAQ

Q: How do I find the tables that are synchronized to the AnalyticDB for PostgreSQL instance?

A: During schema synchronization, DTS synchronizes tables to the destination database based on the schema of the source database. In this example, you can find the customer and Student tables in the dbo schema of the dtstestdata database in the destination instance, as shown in the following figure. View destination tables in AnalyticDB for PostgreSQL