Migrate from RDS for MySQL to AnalyticDB for PostgreSQL

更新时间:
复制 MD 格式

Data Transmission Service (DTS) supports data migration from an ApsaraDB RDS for MySQL instance to AnalyticDB for PostgreSQL.

Supported source databases

You can migrate data from the following types of MySQL source databases to an AnalyticDB for PostgreSQL instance.

  • ApsaraDB RDS for MySQL instances

  • Self-managed MySQL databases:

    • A self-managed database with a public IP address

    • A self-managed database on an ECS instance

    • A self-managed database connected via Database Gateway

    • A self-managed database connected via CEN

    • A self-managed database connected via Express Connect, VPN Gateway, or Smart Access Gateway

Note

This topic uses an ApsaraDB RDS for MySQL instance as an example to illustrate the configuration procedure. The procedure is similar for other types of source databases.

Prerequisites

  • You have created a destination AnalyticDB for PostgreSQL instance. For details, see Create an instance.

  • The destination AnalyticDB for PostgreSQL instance's storage space must exceed the storage space used by the source ApsaraDB RDS for MySQL instance.

Usage notes

Note
  • During schema migration, DTS migrates foreign keys from the source database to the destination database.

  • During full data migration and incremental data migration, DTS temporarily disables constraint checks and foreign key cascading operations at the session level. If cascading update or delete operations occur in the source database while the task is running, data inconsistency may occur.

Type

Description

Limitations on the source database

  • Tables to be migrated must have a primary key or a unique constraint with unique fields to prevent data duplication in the destination database.

  • If your table-level migration involves editing objects, such as by using column mapping, a single data migration task is limited to 1,000 tables. Exceeding this limit causes an error when you submit the task. To work around this, split the tables into multiple tasks or migrate the entire database.

  • If you need incremental migration, enable binary logging:

    • Set binlog_format to ROW and binlog_row_image to FULL. Otherwise, the precheck fails and the task cannot start.

      Important

      If your self-managed MySQL source is a dual-master cluster—where each instance acts as both master and slave—enable the log_slave_updates parameter. This ensures DTS can read all binary logs.

    • For RDS for MySQL instances, retain local binary logs for at least three days (seven days recommended). For self-managed MySQL databases, retain local binary logs for at least seven days. If DTS cannot access binary logs, the task fails. In extreme cases, data inconsistency or data loss may occur. Issues caused by binary log retention periods shorter than DTS requires are not covered under the DTS SLA.

      Note

      To set the retention period for local binary logs on an RDS for MySQL instance, see Automatically delete local logs.

  • During the migration, do not perform DDL operations to modify primary keys or add comments, such as ALTER TABLE table_name COMMENT='table_comment';. Otherwise, the DDL operation fails.

  • If the data to be migrated from the source database contains the DATETIME value 0000-00-00 00:00:00, the data migration task may fail.

    Note

    DTS converts this date value to null when migrating it to the destination database. You can temporarily change the data in the source database to 0001-01-01 00:00:00 or set the corresponding column in the destination database to allow null values.

  • Operations not allowed on the source database:

    • Do not run DDL operations that change database or table schemas during schema migration or full migration. Otherwise, the migration task fails.

      Note

      During full migration, DTS queries the source database. This creates metadata locks that may block DDL operations on the source database.

    • If you run only full migration, do not write new data to the source instance. Otherwise, source and destination data become inconsistent. To keep data consistent in real time, select schema migration, full migration, and incremental migration.

  • DTS does not migrate data generated by changes that do not write to binary logs. Examples include data restored from physical backups or created by cascade operations.

    Note

    If this occurs, re-run full migration after your business allows it.

  • If your source MySQL database is version 8.0.23 or later and contains invisible hidden columns, DTS cannot read those columns. This may cause data loss.

    Note

    Run ALTER TABLE <table_name> ALTER COLUMN <column_name> SET VISIBLE; to make the hidden column visible. For more information, see Invisible Columns.

Other limitations

  • Migration object requirements:

    • Only table-level migration is supported.

    • Migration of data of the following types is not supported: VARBIT, GEOMETRY, ARRAY, UUID, TSQUERY, TSVECTOR, TXID_SNAPSHOT, and POINT.

    • Migration of prefix indexes is not supported and may cause the data migration to fail.

    • Migration of partitions, views, procedures, functions, triggers, foreign keys, and indexes is not supported.

  • If your source database uses temporary-table-mode online DDL operations—including multi-table merge scenarios—or adds function-based indexes to unique key columns, data loss or task failure may occur on the destination database.

  • If a table to be migrated has a primary key, the primary key column in the destination table must be the same as that in the source table. If a table to be migrated does not have a primary key, the primary key column in the destination table must be the same as the distribution key.

  • The unique key of the destination table, including the primary key column, must contain all columns of the distribution key.

  • Before you migrate data, evaluate the performance of the source and destination databases. We recommend that you migrate data during off-peak hours. Otherwise, the initial full data synchronization increases the load on both the source and destination databases by consuming their read and write resources.

  • The concurrent INSERT operations during initial full data synchronization cause table fragmentation, making the table space in the destination database larger than in the source.

  • If you migrate one or more tables instead of the entire database, do not use tools like pt-online-schema-change to perform online DDL operations on the migration objects in the source database. Otherwise, the migration fails.

    You can use Data Management (DMS) to perform online DDL changes. For more information, see Perform lock-free DDL operations.

  • During DTS migration, do not write data from other sources to the destination database. Otherwise, data inconsistency between the source and destination databases will occur. For example, if you use DMS to perform an online DDL change while data from other sources is being written to the destination database, data loss may occur in the destination database.

  • The destination table cannot be an append-optimized (AO) table.

  • If you use column mapping for a partial table migration or if the source and destination table schemas are inconsistent, any data in source columns that do not exist in the destination table will be lost.

  • If your RDS for MySQL instance has Always-Encrypted enabled, full migration is not supported.

    Note

    RDS for MySQL instances with Transparent Data Encryption (TDE) enabled support schema migration, full migration, and incremental migration.

  • If a task fails, DTS support staff will attempt to restore it within eight hours. During restoration, they may restart the task or adjust its parameters.

    Note

    Only DTS task parameters are modified—not database parameters. Parameters that may be adjusted include those listed in Modify instance parameters.

Special cases

  • For self-managed MySQL sources:

    • A master–standby switchover on the source database causes the migration task to fail.

    • DTS calculates latency by comparing the timestamp of the last record migrated to the destination database with the current time. If no DML operations run on the source for a long time, latency reporting becomes inaccurate. If latency appears too high, run a DML operation on the source to update the latency value.

      Note

      If you select full-database migration, create a heartbeat table. Update or write to it every second.

    • DTS periodically runs CREATE DATABASE IF NOT EXISTS `test` on the source database to advance the binary log offset.

    • If your source is Amazon Aurora MySQL or another clustered MySQL instance, ensure the domain name or IP address configured for the task—and its DNS resolution—always points to a read–write (RW) node. Otherwise, the migration task may fail.

  • For RDS for MySQL sources:

    • If you need incremental migration, RDS for MySQL instances that do not record transaction logs—such as RDS for MySQL 5.6 read-only instances—are not supported as sources.

    • DTS periodically runs CREATE DATABASE IF NOT EXISTS `test` on the source database to advance the binary log offset.

Billing

Migration type

Instance configuration fee

Internet traffic fee

Schema migration and full data migration

Free of charge.

When the Access Method parameter of the destination database is set to Public IP Address, you are charged for Internet traffic. For more information, see Billing overview.

Incremental data migration

Charged. For more information, see Billing overview.

Migration types

  • Schema migration

    DTS migrates the schemas of migration objects from the source database to the destination database.

    Note

    In schema migrations between heterogeneous databases, data types may not map perfectly. We recommend you carefully evaluate the business impact of data type mapping. For more information, see Data type mapping for heterogeneous databases.

  • Full data migration

    DTS migrates all existing data for the migration objects from the source database to the destination database.

  • Incremental data migration

    After a full data migration, DTS replicates incremental data updates from the source database to the destination database. This enables a smooth data migration for your self-managed applications, minimizing service interruption.

SQL operations for incremental migration

Operation type

SQL statement

DML

INSERT, UPDATE, and DELETE

Note

The system automatically converts an UPDATE statement to a REPLACE INTO statement when writing to the destination AnalyticDB for PostgreSQL instance. If an UPDATE statement modifies a primary key, the system converts it into DELETE and INSERT statements.

DDL

ALTER TABLE

Warning

If the data type of a column in the source table changes during data migration, the data migration task reports an error and stops. Follow these steps to fix the issue manually.

  1. Suppose a data migration task to the destination AnalyticDB for PostgreSQL instance fails due to a data type change in a source table, such as the customer table.

  2. In your AnalyticDB for PostgreSQL instance, create a new table, such as customer_new, with the same schema as the customer table.

  3. Run an INSERT INTO ... SELECT command to copy data from customer to customer_new. Ensure that the data in the two tables is consistent.

  4. Rename or delete the failed table customer, and then rename customer_new to customer.

  5. In the DTS console, restart the data migration task.

Database account permissions

Database

Schema migration

Full migration

Incremental migration

ApsaraDB RDS for MySQL

SELECT permission

SELECT permission

REPLICATION SLAVE, REPLICATION CLIENT, and SELECT permissions on the objects to be migrated. DTS automatically grants these permissions to the database account.

AnalyticDB for PostgreSQL

read and write permissions

To learn how to create and authorize a database account, see the following topics:

Procedure

  1. Navigate to the migration task list page for the destination region using one of the following methods.

    From the DTS console

    1. Log on to the Data Transmission Service (DTS) console.

    2. In the navigation pane on the left, click Data Migration.

    3. In the upper-left corner of the page, select the region where the migration instance is located.

    From the DMS console

    Note

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

    1. Log on to the Data Management (DMS) console.

    2. In the top menu bar, choose Data + AI > Data Transmission (DTS) > Data Migration.

    3. To the right of Data Migration Tasks, select the region where the migration instance is located.

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

  3. Configure the source and destination databases.

    Section

    Parameter

    Description

    N/A

    Task Name

    DTS automatically generates a task name. We recommend that you specify a descriptive name for easy identification. The name does not need to be unique.

    Source Database

    Database Type

    Select MySQL.

    Connection Type

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region where the source ApsaraDB RDS for MySQL instance is located.

    Cross-account

    This example shows data migration within a single Alibaba Cloud account. For this scenario, select No.

    RDS Instance ID

    Select the ID of the source ApsaraDB RDS for MySQL instance.

    Database Account

    Enter the database account of the source ApsaraDB RDS for MySQL instance. For more information about the required permissions, see Permissions required for database accounts.

    Database Password

    Enter the password for the database account.

    Connection Method

    Select Non-encrypted or SSL-encrypted based on your database requirements. If you set this parameter to SSL-encrypted, you must enable SSL encryption for the RDS for MySQL instance beforehand. For more information, see Quickly enable SSL encryption using a cloud certificate.

    Destination Database

    Database Type

    Select AnalyticDB for PostgreSQL.

    Connection Type

    Select Alibaba Cloud Instance.

    Instance Region

    Select the region where the destination AnalyticDB for PostgreSQL instance is located.

    Instance ID

    Select the ID of the destination AnalyticDB for PostgreSQL instance.

    Database Name

    Enter the name of the destination database on the AnalyticDB for PostgreSQL instance.

    Database Account

    Enter the initial account of the destination AnalyticDB for PostgreSQL instance.

    Note

    You can also enter an account that has the RDS_SUPERUSER permission. For more information, see User permission management.

    Database Password

    Enter the password for the database account.

  4. After you complete the configuration, click Test Connectivity and Proceed at the bottom of the page.

    Note
    • Ensure that the IP address segment of the DTS service is 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 (the Access Method is not Alibaba Cloud Instance), you must also click Test Connectivity in the CIDR Blocks of DTS Servers dialog box that appears.

  5. Configure the task objects.

    1. On the Configure Objects page, configure the objects that you want to migrate.

      Parameter

      Description

      Migration Types

      • If you only need to perform a full migration, select both Schema Migration and Full Data Migration.

      • To perform a migration with no downtime, select Schema Migration, Full Data Migration, and Incremental Data Migration.

      Note
      • If you do not select Schema Migration, you must ensure that a database and tables to receive the data exist in the destination database. You can also use the object name mapping feature in the Selected Objects box as needed.

      • If you do not select Incremental Data Migration, do not write new data to the source instance during data migration to ensure data consistency.

      Select DDL and DML to Sync at the Instance Level

      Select the SQL operations that you want to incrementally migrate at the instance level. For more information about supported operations, see Supported SQL operations for incremental migration.

      Note

      To select SQL operations at the database or table level, right-click a migration object in the Selected Objects section and select the desired SQL operations in the dialog box.

      Processing Mode of Conflicting Tables

      • Precheck and Report Errors: Checks whether tables with the same names exist in the destination database. If no tables with the same names exist, the precheck is passed. If tables with the same names exist, an error is reported during the precheck, and the data migration task does not start.

        Note

        If a table in the destination database has the same name but cannot be easily deleted or renamed, you can change the name of the table in the destination database. For more information, see Object name mapping.

      • Ignore Errors and Proceed: Skips the check for tables with the same names.

        Warning

        Selecting Ignore Errors and Proceed may cause data inconsistency and business risks. For example:

        • If the table schemas are consistent and a record in the destination database has the same primary key value as a record in the source database:

          • During full migration, DTS keeps the record in the destination database. The record from the source database is not migrated.

          • During incremental migration, DTS does not keep the record in the destination database. The record from the source database overwrites the record in the destination database.

        • If the table schemas are inconsistent, only some columns of data may be migrated, or the migration may fail. Proceed with caution.

      Storage Engine Type

      Select a storage engine for the destination tables based on your business requirements. The default value is Beam.

      Note

      This parameter is available only if the destination AnalyticDB for PostgreSQL instance has a kernel version of v7.0.6.6 or later and you selected Migration Types for the Schema Migration parameter.

      Source Objects

      In the Source Objects box, click the objects to migrate, and then click Right arrow to move them to the Selected Objects box.

      Note

      The granularity for selecting migration objects is schema, table, and column. If you select only tables or columns as migration objects, other objects such as views, triggers, and stored procedures are not migrated to the destination database.

      Selected Objects

      Note
      • To select SQL operations at the database or table level, right-click a migration object in the Selected Objects section and select the desired SQL operations in the dialog box.

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

      • If you rename an object by using the name mapping feature, migration of dependent objects may fail.

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

      Parameter

      Description

      Dedicated Cluster for Task Scheduling

      By default, DTS schedules tasks on a shared cluster. You do not need to select one. If you want more stable tasks, you can purchase a dedicated cluster to run DTS migration tasks.

      Retry Time for Failed Connections

      After the migration task starts, if the connection to the source or destination database fails, DTS reports an error and immediately begins to retry the connection. The default retry duration is 720 minutes. You can customize the retry time to a value from 10 to 1440 minutes. We recommend that you set the duration to more than 30 minutes. If DTS reconnects to the source and destination databases within the specified duration, the migration task automatically resumes. Otherwise, the task fails.

      Note
      • For multiple DTS instances that share the same source or destination, the network retry time is determined by the setting of the last created task.

      • Because you are charged for the task during the connection retry period, we recommend that you customize the retry time based on your business needs, or release the DTS instance as soon as possible after the source and destination database instances are released.

      Retry Time for Other Issues

      After the migration task starts, if a non-connectivity issue, such as a DDL or DML execution exception, occurs in the source or destination database, DTS reports an error and immediately begins to retry the operation. The default retry duration is 10 minutes. You can customize the retry time to a value from 1 to 1440 minutes. We recommend that you set the duration to more than 10 minutes. If the related operations succeed within the specified retry duration, the migration task automatically resumes. Otherwise, the task fails.

      Important

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

      Enable Throttling for Full Data Migration

      During full migration, DTS consumes read and write resources on the source and destination databases, which may increase the database load. If required, you can enable throttling for the full migration task. You can set Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s) to reduce the load on the destination database.

      Note
      • This configuration item is available only if you select Full Data Migration for Migration Types.

      • You can also adjust the full migration speed after the migration instance is running.

      Enable Throttling for Incremental Data Migration

      If required, you can also choose to set speed limits for the incremental migration task. You can set RPS of Incremental Data Migration and Data migration speed for incremental migration (MB/s) to reduce the load on the destination database.

      Note
      • This configuration item is available only if you select Incremental Data Migration for Migration Types.

      • You can also adjust the incremental migration speed after the migration instance is running.

      Enclose Object Names in Quotation Marks

      Specify whether to enclose object names in quotation marks.

      • Select Yes: If the source database meets the following requirements, DTS automatically encloses the names of schemas, tables, or columns in single (') or double (") quotation marks during schema migration and incremental data migration.

        • The source database is case-sensitive, and object names use mixed case.

        • A source table name starts with a non-alphabetic character or contains characters other than letters, digits, or the supported special characters.

          Note

          Only the following special characters are supported: underscores (_), number signs (#), and dollar signs ($).

        • The names of the schemas, tables, or columns that you want to migrate are keywords, reserved words, or invalid characters in the destination database.

      • Select No: DTS does not enclose object names in quotation marks.

      Whether to delete SQL operations on heartbeat tables of forward and reverse tasks

      Choose whether DTS writes heartbeat SQL information to the source database while the instance is running.

      • Yes: Does not write heartbeat SQL information to the source database. The DTS instance may display latency.

      • No: Writes heartbeat SQL information to the source database. This may interfere with source database operations like physical backups and cloning.

      Environment Tag

      You can select an environment tag to identify the instance based on your business requirements. In this example, you do not need to configure this parameter.

      Configure ETL

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

      Monitoring and Alerting

      Select whether to set alerts and receive alert notifications based on your business needs.

      • No: Does not set an alert.

      • Yes: Configure alerts by setting an alert threshold and an alert contact. If a migration fails or the latency exceeds the threshold, the system sends an alert notification.

    3. Click Next: Data Validation to configure a data validation task.

      For more information about the data validation feature, see Configure data validation.

    4. Optional: Configure table and column fields. Specify the Primary Key Column and Distribution Key for the tables to be migrated to the destination AnalyticDB for PostgreSQL instance. For more information, see CREATE TABLE.

      Note

      This step is available only if you select Schema Migration when you configure the migration objects.

  6. Save the task and run a precheck.

    • To view the parameters for configuring this instance when you call the API operation, move the pointer over the Next: Save Task Settings and Precheck button and click Preview OpenAPI parameters in the bubble that appears.

    • If you do not need to view or have finished viewing the API parameters, click Next: Save Task Settings and Precheck at the bottom of the page.

    Note
    • Before the migration task starts, DTS performs a precheck. The task starts only after it passes the precheck.

    • If the precheck fails, click View Details next to the failed check item, fix the issue based on the prompt, and then run the precheck again.

    • If a warning is reported during the precheck:

      • For check items that cannot be ignored, click View Details next to the failed item, fix the issue based on the prompt, and then run the precheck again.

      • For check items that can be ignored, you can click Confirm Alert Details, Ignore, OK, and Precheck Again to skip the alert item and run the precheck again. If you choose to ignore a warning, it may cause issues such as data inconsistency and pose risks to your business.

  7. Purchase the instance.

    1. When the Success Rate is 100%, click Next: Purchase Instance.

    2. On the Purchase page, select the link specification for the data migration instance. For more information, see the following table.

      Category

      Parameter

      Description

      New Instance Class

      Resource Group Settings

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

      Instance Class

      DTS provides migration specifications with different performance levels. The link specification affects the migration speed. You can select a specification based on your business scenario. For more information, see Data migration link specifications.

    3. After the configuration is complete, read and select Data Transmission Service (Pay-as-you-go) Service Terms.

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

      You can view the progress of the migration task on the Data Migration Tasks list page.

      Note
      • If the migration task does not include incremental migration, it stops automatically after the full migration is complete. After the task stops, its Status changes to Completed.

      • If the migration task includes incremental migration, it does not stop automatically. The incremental migration task continues to run. While the incremental migration task is running, the Status of the task is Running.