Updated on 2024-04-11 GMT+08:00

From MySQL to PostgreSQL

Supported Source and Destination Databases

Table 1 Supported databases

Source DB

Destination DB

  • On-premises MySQL databases
  • MySQL databases on an ECS
  • MySQL databases on other clouds
  • RDS for MySQL
  • RDS for PostgreSQL

Prerequisites

  • You have logged in to the DRS console.
  • For details about the DB types and versions supported by real-time synchronization, see Real-Time Synchronization.

Suggestions

  • When a task is being started or in the full synchronization phase, do not perform DDL operations on the source database. Otherwise, the task may be abnormal.
  • To keep data consistency before and after the synchronization, ensure that no data is written to the destination database during the synchronization.
  • The success of database synchronization depends on environment and manual operations. To ensure a smooth synchronization, perform a synchronization trial before you start the synchronization to help you detect and resolve problems in advance.
  • Start your synchronization task during off-peak hours. A less active database is easier to synchronize successfully. If the data is fairly static, there is less likely to be any severe performance impacts during the synchronization.
    • If network bandwidth is not limited, the query rate of the source database increases by about 50 MB/s during full synchronization, and two to four CPUs are occupied.
    • To ensure data consistency, tables to be synchronized without a primary key may be locked for 3s.
    • The data being synchronized may be locked by other transactions for a long period of time, resulting in read timeout.
    • Due to the inherent characteristics of MySQL, in certain scenarios the performance may be negatively affected. For example, if the CPU resources are insufficient and the storage engine is TokuDB, the read speed on tables may be decreased by 10%.
    • When DRS concurrently reads data from a database, it will use about 6 to 10 sessions. The impact of the connections on services must be considered.
    • If you read a table, especially a large table, during the full migration, the exclusive lock on that table may be blocked.
  • Data-Level Comparison

    To obtain accurate comparison results, compare data at a specified time point during off-peak hours. If it is needed, select Start at a specified time for Comparison Time. Due to slight time difference and continuous operations on data, data inconsistency may occur, reducing the reliability and validity of the comparison results.

Precautions

Before creating a synchronization task, read the following notes:

  • You are advised to create an independent database account for DRS task connection to prevent task failures caused by database account password modification.
  • After changing the account passwords for the source or destination databases, modify the connection information in the DRS task as soon as possible to prevent automatic retry after a task failure. Automatic retry will lock the database accounts.
Table 2 Precautions

Type

Restrictions

Database permissions

  • The source database user must have the following minimum permissions.
    • Minimum permission for full synchronization: SELECT.
    • Minimum permission for full and incremental synchronization: SELECT, LOCK TABLES, REPLICATION SLAVE, and REPLICATION CLIENT
  • The destination database user must have the minimum permissions: the default permissions of an RDS PostgreSQL instance account

Synchronization object

  • Only table structures, table data, and indexes can be synchronized. Other database objects such as stored procedures cannot be synchronized.
  • MySQL views support syntax "as select ... from a join b where ..." but PostgreSQL does not, which may lead to the synchronization task to fail.
  • The following data types are not supported: XML, geometry, point, lineString, polygon, geometrycollection, multipoint, multilinestring, multipolygon, and json.
  • Tables with storage engine different to MyISAM and InnoDB cannot be synchronized.

Source database

  • The names of the source databases and tables cannot contain non-ASCII characters, or special characters <'>.`/\"
  • During the incremental synchronization, the binlog of the source MySQL database must be enabled and use the row-based format.
  • During an incremental synchronization, if the session variable character_set_client is set to binary, some data may include garbled characters.
  • If the storage space is sufficient, store the source database binlog for as long as possible. The recommended retention period is three days. If this period is set to 0, the synchronization may fail.
    • If the source database is an on-premises MySQL database, set expire_logs_days to specify the binlog retention period. Set expire_logs_day to a proper value to ensure that the binlog does not expire before data transfer resumes. This ensures that services can be recovered after interruption.
    • If the source database is an RDS for MySQL instance, set the binlog retention period by following the instructions provided in RDS User Guide.
  • GTID must be enabled for the source database. If GTID is not enabled for the source database, primary/standby switchover is not supported. DRS tasks will be interrupted and cannot be restored during a switchover.
  • The server_id value of the source MySQL database must be in the range from 1 to 4294967296.

Destination database

  • The destination DB instance is running properly. If the destination DB instance type is RDS primary/standby instance, the replication status must also be normal.
  • The destination DB instance must have sufficient storage space.
  • The time zone of the destination database must be the same as that of the source database.

Precautions

  • In MySQL, different tables in the same database (schema) can have the same index name or constraint name. In PostgreSQL, the index and constraint names are unique in the same schema, and the length is limited. To prevent conflicts between index and constraint names, the original index name in the table is changed to the following format after synchronization: hash value + original index name (which may be truncated) + _key. The hash value is calculated based on the original database name_original table name_original index name. Similarly, the original constraint name in the table is changed to the following format: hash value + original constraint name (which may be truncated) + _key.
  • Objects that have dependencies must be synchronized at the same time to avoid synchronization failure. Common associations: tables or views referenced by views
  • If the source and destination sides are RDS for MySQL instances, tables encrypted using TDE cannot be synchronized.
  • If the source MySQL database does not support TLS 1.2 or is a self-built database of an earlier version (earlier than 5.6.46 or between 5.7.0 and 5.7.28), you need to submit an O&M application for testing the SSL connection.
  • Before creating a DRS task, if concurrency control rules of SQL statements are configured for the source database, the DRS task may fail.
  • If the network is reconnected within 30 seconds, real-time synchronization will not be affected. If the network is interrupted for more than 30 seconds, the synchronization task will fail.
  • The table without a primary key lacks a unique identifier for rows. When the network is unstable, you may need to retry the task several times, or data inconsistency may occur.
  • Different types of indexes synchronized to the destination database will become B-Tree indexes.
  • If the character sets of the source and destination databases are different, data may be inconsistent or synchronization may fail.
  • If the data types are incompatible, the synchronization may fail.
  • The destination table can contain more columns than the source table. However, the following failures must be avoided:
    • Assume that extra columns on the destination cannot be null or have default values. If newly inserted data records are synchronized from the source to the destination, the extra columns will become null, which does not meet the requirements of the destination and will cause the task to fail.
    • Assume that extra columns on the destination must be fixed at a default value and have a unique constraint. If newly inserted data records are synchronized from the source to the destination, the extra columns will contain multiple default values. That does not meet the unique constraint of the destination and will cause the task to fail.
  • Only data that violates the non-null constraint and data of the char or varchar type that exceeds the field length limit can be recorded.
  • The source database cannot be restored.
  • Cascade operations cannot be performed on tables with foreign keys. If the foreign key index of a table is a common index, the table structure may fail to be created. You are advised to use a unique index.
  • Binlogs cannot be forcibly deleted. Otherwise, the synchronization task fails.
  • The source database does not support the reset master or reset master to command, which may cause DRS task failures or data inconsistency.
  • Do not use an imprecise value type as the primary key in the database. This feature affects the synchronization of UPDATE and DELETE statements in the DRS incremental scenario.
  • If tables without primary keys contain large fields (BLOB, TEXT, CLOB, NCLOB, or BYTEA), data of the large fields may be inconsistent during incremental synchronization.
  • If you change the port of the RDS source database and the synchronization task fails, retry the task.
  • During real-time synchronization, if the source is not RDS, the port cannot be changed.
  • During real-time synchronization, the IP address, account, and password cannot be changed.
  • DDL operations are not supported during full synchronization.
  • During incremental synchronization, some DDL operations are supported.
    • DROP_DATABASE, DROP_TABLE, TRUNCATE_TABLE, CREATE_VIEW and DROP_VIEW are not supported.
    • Online DDL is not supported.
    • Table fields can be added, deleted, and modified. For example:
      alter table `ddl_test` add column `c2` varchar(25); 
      alter table `ddl_test` modify column `c1` varchar(50);
      alter table `ddl_test` alter c1 set default 'xxx';
    • Table indexes can be modified. For example:
      alter table `ddl_test` drop primary key; 
      alter table `ddl_test` add primary key(id); 
      alter table `ddl_test` add index  `ddl_test_uk`(id);
      alter table `ddl_test` drop index `ddl_test_uk`;
    • In table-level synchronization, you can add columns, modify columns, and add primary keys and normal indexes.
    • The name of a table, column, or index to be added or modified cannot exceed 63 characters. Otherwise, the task fails.
    • When a DDL operation is performed in the incremental phase, if the destination table is not found, the DDL operation will be ignored.
  • Set the expire_log_day parameter to a proper value to ensure that the binlog does not expire before data transfer resumes. This ensures that services can be recovered after interruption.
  • During a full synchronization, DRS writes large amount of data to the destination PostgreSQL database. As a result, the number of PostgreSQL WAL logs increases sharply, and the PostgreSQL disk space may be used up. You can disable the PostgreSQL log backup function before the full synchronization to reduce the number of WAL logs. After the synchronization is complete, enable the function.
    CAUTION:

    Disabling log backup will affect database disaster recovery. Exercise caution when performing this operation.

  • If the source table to be synchronized has the AUTO_INCREMENT attribute, DRS automatically updates the start value of the PostgreSQL auto-increment sequence corresponding to the integer sequence of the table when the task is complete. The updated value is the maximum value of the sequence plus 10,000.

Procedure

  1. On the Data Synchronization Management page, click Create Synchronization Task.
  2. On the Create Synchronization Instance page, specify the task name, description, and the synchronization instance details, and click Create Now.

    • Task information description
      Table 3 Task and recipient description

      Parameter

      Description

      Task Name

      The task name must start with a letter and consist of 4 to 50 characters. It can contain only letters, digits, hyphens (-), and underscores (_).

      Description

      The description consists of a maximum of 256 characters and cannot contain special characters !=<>'&"\

    • Synchronization instance details
      Table 4 Synchronization instance settings

      Parameter

      Description

      Data Flow

      Select To the cloud.

      Source DB Engine

      Select MySQL.

      Destination DB Engine

      Select PostgreSQL.

      Network Type

      Available options: VPC, Public network and VPN or Direct Connect. Public network is used as an example.

      • VPC is suitable for data synchronization between cloud databases of the same account in the same region.
      • Public network is suitable for data synchronization from on-premises or external cloud databases to the destination databases bound with an EIP.
      • VPN or Direct Connect is suitable for synchronization of data between on-premises databases and cloud databases, between cloud databases of different accounts in the same region, or between cloud databases across regions.

      Destination DB Instance

      The RDS PostgreSQL DB instance.

      Synchronization Instance Subnet

      Select the subnet where the synchronization instance is located. You can also click View Subnet to go to the network console to view the subnet where the instance resides.

      By default, the DRS instance and the destination DB instance are in the same subnet. You need to select the subnet where the DRS instance resides and ensure that there are available IP addresses. To ensure that the synchronization instance is successfully created, only subnets with DHCP enabled are displayed.

      Synchronization Mode

      • Full+Incremental

        This synchronization mode allows you to synchronize data in real time. After a full synchronization initializes the destination database, an incremental synchronization parses logs to ensure data consistency between the source and destination databases.

      • Full

        All objects and data in non-system databases are synchronized to the destination database at a time. This mode is applicable to scenarios where service interruption is acceptable.

    If a task fails to be created, DRS retains the task for three days by default. After three days, the task automatically ends.

  3. On the Configure Source and Destination Databases page, wait until the synchronization instance is created. Then, specify source and destination database information and click Test Connection for both the source and destination databases to check whether they have been connected to the synchronization instance. After the connection tests are successful, select the check box before the agreement and click Next.

    Table 5 Self-build on ECS - source database information

    Parameter

    Description

    IP Address or Domain Name

    The IP address or domain name of the source database.

    Port

    The port of the source database. Range: 1 – 65535

    Database Username

    The username for accessing the source database.

    Database Password

    The password for the database username.

    SSL Connection

    SSL encrypts the connections between the source and destination databases. If SSL is enabled, upload the SSL CA root certificate.

    NOTE:
    • The maximum size of a single certificate file that can be uploaded is 500 KB.
    • If SSL is disabled, your data may be at risk.

    The IP address, domain name, username, and password of the source database are encrypted and stored in DRS, and will be cleared after the task is deleted.

    Table 6 Destination database settings

    Parameter

    Description

    DB Instance Name

    The RDS PostgreSQL instance you selected when creating the migration task and cannot be changed.

    Database Username

    The username for accessing the destination database.

    Database Password

    The password for the database username.

    The username and password of the destination database are encrypted and stored in the database and the synchronization instance during the synchronization. After the task is deleted, the username and password are permanently deleted.

  4. On the Set Synchronization Task page, select the synchronization policy and synchronization object, and click Next.

    Table 7 Synchronization Object

    Parameter

    Description

    Flow Control

    You can choose whether to control the flow.

    • Yes

      You can customize the maximum synchronization speed.

      In addition, you can set the time range based on your service requirements. The traffic rate setting usually includes setting of a rate limiting time period and a traffic rate value. Flow can be controlled all day or during specific time ranges. The default value is All day. A maximum of three time ranges can be set, and they cannot overlap.

      The flow rate must be set based on the service scenario and cannot exceed 9,999 MB/s.

    • No
      The synchronization speed is not limited and the outbound bandwidth of the source database is maximally used, which will increase the read burden on the source database. For example, if the outbound bandwidth of the source database is 100 MB/s and 80% bandwidth is used, the I/O consumption on the source database is 80 MB/s.
      NOTE:
      • The flow control mode takes effect only in the full synchronization phase.
      • You can also change the flow control mode after creating a task. For details, see Modifying the Flow Control Mode.

    Synchronization Object Type

    Available options: Table structure, Data, and Index

    • Data is selected by default.
    • If Table structure is selected, the destination database cannot contain tables whose names are the same as the source tables to be synchronized.
    • If Table structure is not selected, the destination database must have tables that match the source tables, and the table structure must be the same as the selected source table structures.

    Incremental Conflict Policy

    The conflict policy refers to the conflict handling policy during incremental synchronization. By default, conflicts in the full synchronization phase are ignored. Select any of the following conflict policies:

    • Ignore

      The system will skip the conflicting data and continue the subsequent synchronization process.

    • Report error

      The synchronization task will be stopped and fail.

    • Overwrite

      Conflicting data will be overwritten.

    Filter DROP DATABASE

    During real-time synchronization, executing DDL operations on the source database may affect the synchronization performance. To reduce the risk of synchronization failure, DRS allows you to filter out DDL operations. Currently, only the delete operations on databases can be filtered by default.

    • If you select Yes, the database deletion operation performed on the source database is not synchronized during data synchronization.
    • If you select No, related operations are synchronized to the destination database during data synchronization.

    Synchronization Object

    The left pane displays the source database objects, and the right pane displays the selected objects. DRS supports table-level synchronization. You can select data for synchronization based on your service requirements.

    If the synchronization objects in source and destination databases have different names, you can map the source object name to the destination one. For details, see Mapping Object Names.

    NOTE:
    • To quickly select the desired database objects, you can use the search function.
    • If there are changes made to the source databases or objects, click in the upper right corner to update the objects to be synchronized.
    • If the object name contains spaces, the spaces before and after the object name are not displayed. If there are multiple spaces between the object name and the object name, only one space is displayed.
    • The name of the selected synchronization object cannot contain spaces.

  5. On the Check Task page, check the synchronization task.

    • If any check fails, review the cause and rectify the fault. After the fault is rectified, click Check Again.
    • If all check items are successful, click Next.

      You can proceed to the next step only when all checks are successful. If there are any items that require confirmation, view and confirm the details first before proceeding to the next step.

  6. On the displayed page, specify Start Time, confirm that the configured information is correct, and click Submit to submit the task.

    Table 8 Task startup settings

    Parameter

    Description

    Start Time

    Set Start Time to Start upon task creation or Start at a specified time based on site requirements.

    NOTE:

    After a synchronization task is started, the performance of the source and destination databases may be affected. You are advised to start a synchronization task during off-peak hours.

  7. After the task is submitted, you can view and manage it on the Data Synchronization Management page.

    • You can view the task status. For more information about task status, see Task Statuses.
    • You can click in the upper-right corner to view the latest task status.
    • By default, DRS retains any task in the Configuration state for three days. After three days, DRS automatically deletes background resources, but the task status remains unchanged. When you configure the task again, DRS applies for resources for the task again. In this case, the IP address of the DRS instance changes.