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

  • An ApsaraDB RDS for SQL Server instance is created. The version of the instance is 2012, 2016, or 2017. For more information, see Create an ApsaraDB RDS for SQL Server instance.
  • An AnalyticDB for PostgreSQL instance is created. For more information, see Create an instance.
  • The source tables in the ApsaraDB RDS for SQL Server instance contain primary keys.
  • The destination tables in the AnalyticDB for PostgreSQL instance contain primary keys or unique indexes.

Precautions

  • 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 delay time 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 initial 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. Their data types 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 initial schema synchronization.
  • DTS does not synchronize data of the following types: TIMESTAMP, CURSOR, ROWVERSION, HIERACHYID, SQL_VARIANT, SPATIAL GEOMETRY, SPATIAL GEOGRAPHY, and TABLE.

SQL operations that can be synchronized

  • Data definition language (DDL) operation: ADD COLUMN
  • Data manipulation language (DML) operations: INSERT, UPDATE, and DELETE

Permissions required for database accounts

Database Required permissions Topics about how to create and authorize a database account
ApsaraDB RDS for SQL Server instance The owner permission on the source database Modify the permissions of a standard account on an ApsaraDB RDS for SQL Server instance
AnalyticDB for PostgreSQL instance
  • The LOGIN permission
  • The SELECT, CREATE, INSERT, UPDATE, and DELETE permissions on the destination tables
  • The CONNECT and CREATE permissions on the destination database
  • The CREATE permission on the destination schemas
  • The 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 Source Instance to SQLServer, set Target Instance to AnalyticDB for PostgreSQL, and set Synchronization Topology 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.
    Select a region
  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
    Section Parameter Description
    N/A Synchronization Task Name DTS automatically generates a task name. We recommend that you specify an informative name for easy identification. You do not need to use a unique task name.
    Source Instance Details Instance Type Select RDS Instance.
    Instance Region The source region that you selected on the buy page. You cannot change the value of this parameter.
    Instance ID Select the ID of the source ApsaraDB RDS for SQL Server instance.
    Database Account Enter the database account of the ApsaraDB RDS for SQL Server instance. For more information about the permissions that are required for the account, see Permissions required for database accounts.
    Database Password Enter the password of the source database account.
    Encryption Select Non-encrypted or SSL-encrypted. If you want to select SSL-encrypted, you must enable SSL encryption for the RDS instance before you configure the data synchronization task. For more information, see Configure SSL encryption on an ApsaraDB RDS for SQL Server instance.
    Note The Encryption parameter is available only for regions in mainland China and the China (Hong Kong) region.
    Destination Instance Details Instance Type The value of this parameter is set to AnalyticDB for PostgreSQL and cannot be changed.
    Instance Region The destination region that you selected on the buy page. You cannot change the value of this parameter.
    Instance ID Select the ID of the destination AnalyticDB for PostgreSQL instance.
    Database Name Enter the name of the destination database.
    Database Account Enter the database account of the destination AnalyticDB for PostgreSQL instance. For more information about the permissions that are required for the account, see Permissions required for database accounts.
    Database Password Enter the password of the destination database account.
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note DTS adds the CIDR blocks of DTS servers to the whitelists of the source ApsaraDB RDS for SQL Server instance and the destination AnalyticDB for PostgreSQL instance. This ensures that DTS servers can connect to the source and destination instances.
  8. Select the synchronization policy and the objects to be synchronized.
    Select the synchronization policy and the objects to be synchronized
    Parameter Description
    Initial Synchronization Initial Schema Synchronization, Initial Full Data Synchronization, and Initial Incremental Data Synchronization are selected by default. After the precheck, DTS synchronizes the schemas and data of the required 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 source and destination databases do not contain identical table names, the precheck is passed. Otherwise, an error is returned during precheck and the data synchronization task cannot be started.
      Note You can use the object name mapping feature to change the names of the tables that are synchronized to the destination database. You can use this feature if the source and destination databases contain identical table names and the tables in the destination database cannot be deleted or renamed. For more information, see Specify the name of an object in the destination instance.
    • Ignore: skips the precheck for identical table names in the source and destination databases.
      Warning If you select Ignore, data consistency is not guaranteed 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 specific columns are synchronized or the data synchronization task fails.
    Merge Multi Tables
    • Yes: In OLTP scenarios, sharding is implemented to speed up the response to business tables. However, AnalyticDB for PostgreSQL allows you to store a large volume 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 Specify the name of an object in the destination instance.
      • 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 specifies the column values based on 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 of the selected source tables in the task are merged into the destination table. If you do not need to merge specific source tables, you can create a separate data synchronization task for these tables.
    • No is selected by default.
    Synchronization Type Select 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 Right arrow icon to move the objects to the Selected section.

    You can select tables or databases as the objects to be synchronized.

    Note
    • You can select a single database or multiple tables in the database. To synchronize data from multiple databases, you must create a data synchronization task for each database.
    • 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 change the names of the objects that are synchronized to the destination instance. For more information, see Specify the name of an object in the destination instance.
    • 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 AnalyticDB for PostgreSQL. To do this, you can use the object name mapping feature.
    Enclose object names in quotation marks Specify 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 or double quotation marks when DTS synchronizes schemas and incremental data.
    • The business environment of the source database is case-sensitive but 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.
  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 keys, 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, you can click the Info icon icon next to each failed item to view details. You can troubleshoot the issues based on the causes 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 can I find the tables that are synchronized to the AnalyticDB for PostgreSQL instance?

A: During initial 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, as shown in the following figure.View destination tables in AnalyticDB for PostgreSQL