This topic describes how to synchronize data from a self-managed SQL Server database that is hosted on Elastic Compute Service (ECS) to an AnalyticDB for PostgreSQL instance by using Data Transmission Service (DTS).

Prerequisites

  • The version of the self-managed SQL Server database is 2008, 2008 R2, 2012, 2014, 2016, or 2017.
    Note If you deploy the SQL Server database in an Always On availability group (AOAG), you must use the synchronous-commit mode.
  • The tables to be synchronized from the self-managed SQL Server database have primary keys or UNIQUE NOT NULL indexes.
  • The available storage space of the AnalyticDB for PostgreSQL instance is larger than the total size of the data in the self-managed SQL Server database.

Precautions

  • DTS uses read and write resources of the source and destination databases during initial full data synchronization. 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 synchronize data, evaluate the impact of data synchronization on the performance of the source and destination databases. We recommend that you synchronize data during off-peak hours. For example, you can synchronize data when the CPU utilization of the source and destination databases is less than 30%.
  • To ensure that the data synchronization task runs as expected, do not frequently back up the source database. We recommend that you retain log files for more than three days. Otherwise, you cannot retrieve log files after they are truncated.
  • To ensure that the delay time of data synchronization is accurate, DTS adds a heartbeat table to the self-managed SQL Server database. The name of the heartbeat table is Source table name_dts_mysql_heartbeat.

Limits

  • DTS does not synchronize the schemas of assemblies, service brokers, full-text indexes, full-text catalogs, distributed schemas, distributed functions, CLR stored procedures, CLR scalar-valued functions, CLR table-valued functions, internal tables, systems, or aggregate functions.
  • DTS does not synchronize data of the following types: TIMESTAMP, CURSOR, ROWVERSION, HIERACHYID, SQL_VARIANT, SPATIAL GEOMETRY, SPATIAL GEOGRAPHY, and TABLE.
  • DTS does not synchronize tables that contain computed columns.

SQL operations that can be synchronized

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

Permissions required for database accounts

Database Required permissions References
Self-managed SQL Server database The permissions of the sysadmin role CREATE USER and GRANT (Transact-SQL)
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.
Create a database account and Manage users and permissions

Before you begin

Before you configure a data synchronization task, configure log settings and create clustered indexes on the self-managed SQL Server database.

  1. Run the following command on the self-managed SQL Server database to change the recovery model to full. You can also change the recovery model by using SQL Server Management Studio (SSMS). For more information, see View or Change the Recovery Model of a Database (SQL Server).
    use master;
    GO
    ALTER DATABASE <database_name> SET RECOVERY FULL WITH ROLLBACK IMMEDIATE;
    GO

    Parameters:

    <database_name>: the name of the source database.

    Example:

    use master;
    GO
    ALTER DATABASE mytestdata SET RECOVERY FULL WITH ROLLBACK IMMEDIATE;
    GO
  2. Run the following command to create a logical backup for the source database. Skip this step if you have already created a logical backup.
    BACKUP DATABASE <database_name> TO DISK='<physical_backup_device_name>';
    GO

    Parameters:

    • <database_name>: the name of the source database.
    • <physical_backup_device_name>: the storage path and file name of the backup file.

    Example:

    BACKUP DATABASE mytestdata TO DISK='D:\backup\dbdata.bak';
    GO
  3. Run the following command to back up the log entries of the source database:
    BACKUP LOG <database_name> to DISK='<physical_backup_device_name>' WITH init;
    GO

    Parameters:

    • <database_name>: the name of the source database.
    • <physical_backup_device_name>: the storage path and file name of the backup file.

    Example:

    BACKUP LOG mytestdata TO DISK='D:\backup\dblog.bak' WITH init;
    GO
  4. Create clustered indexes for the tables that you want to synchronize. For more information, see Create Clustered Indexes.

Procedure

  1. Purchase a data synchronization instance. For more information, see Purchase a DTS instance.
    Note On the buy page, set Source Instance to SQL Server, 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 databases
    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 an instance type based on the deployment of the source database. In this example, select User-Created Database in ECS Instance.
    Note If you select other instance types, you must deploy the network environment for the self-managed database. For more information, see Preparation overview.
    Instance Region The source region that you selected on the buy page. You cannot change the value of this parameter.
    ECS Instance ID Select the ID of the Elastic Compute Service (ECS) instance that hosts the source database.
    Database Type This parameter is set to SQLServer and cannot be changed.
    Port Number Enter the service port number of the source database. The default port number is 3306.
    Database Account Enter the account of the source database. For information about the permissions that are required for the account, see Permissions required for database accounts.
    Database Password Enter the password of the database account.
    Encryption Select Non-encrypted or SSL-encrypted.
    Note The Encryption parameter is available only for regions in mainland China and the China (Hong Kong) region.
    Destination Instance Details Instance Type 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 information about the permissions that are required for the account, see Permissions required for database accounts.
    Database Password Enter the password of the database account.
  7. In the lower-right corner of the page, click Set Whitelist and Next.
    Note DTS automatically adds the CIDR blocks of DTS servers to the whitelists of the source SQL Server database and the destination AnalyticDB for PostgreSQL instance. You must manually add the CIDR blocks of DTS servers to the inbound rule of the ECS instance that hosts the source database. 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. The data synchronization task can be started only after it 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.
      • If you do not need to troubleshoot the issues, you can 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