Help Center/ Data Replication Service/ Real-Time Migration/ Task Management/ Data Comparison (Comparing Migration Items)
Updated on 2024-07-11 GMT+08:00

Data Comparison (Comparing Migration Items)

This section describes how to compare migration items to check if there are any differences between source and destination databases. By comparing migration objects, you can determine the proper time for service migration to minimize the service downtime.

Figure 1 Migration comparison process

Comparison Scenarios

You can compare migration objects with different dimensions:

  • Object-level comparison: It helps you compare databases, indexes, tables, views, stored procedures and functions, and sorting rules of tables. You are advised to perform the comparison after a full migration is complete.
  • Data-level comparison is classified into row comparison and value comparison.
    • Row comparison: It helps you compare the number of rows in the tables to be migrated. This comparison method is recommended because it is fast.
    • Value comparison: It helps you check whether data in the migrated table is consistent. The comparison process is relatively slow.
  • Account comparison: It compares usernames and permissions of the source and destination databases.
  • Periodic comparison: DRS periodically compares the number of rows or objects in the source database table with those in the destination database table and displays the comparison results. To compare rows or objects periodically, enable comparison policy.

When you check data consistency, compare the number of rows first. If the number of rows are inconsistent, you can then compare the data in the table to determine the inconsistent data.

Table 1 Supported comparison methods

Migration Direction

Data Flow

Object-level Comparison

Row Comparison

Value Comparison

Dynamic Comparison

Account-level Comparison

To the cloud

MySQL->MySQL

Supported

Supported

Supported

Supported

Supported

To the cloud

MySQL->GaussDB(for MySQL)

Supported

Supported

Supported

Supported

Supported

To the cloud

MySQL->DDM

Supported

Supported

Not supported

Not supported

Not supported

To the cloud

MongoDB->DDS

Supported

Supported

Supported

Not supported

Supported

To the cloud

MongoDB->GeminiDB Mongo

Supported

Supported

Supported

Not supported

Not supported

To the cloud

MySQL schema and logic table -> DDM

Supported

Supported

Not supported

Not supported

Not supported

To the cloud

Redis->GeminiDB Redis

Not supported

Not supported

Not supported

Not supported

Not supported

To the cloud

Cluster Redis -> GeminiDB Redis

Not supported

Not supported

Not supported

Not supported

Not supported

From the cloud

MySQL->MySQL

Supported

Supported

Supported

Supported

Supported

From the cloud

DDS->MongoDB

Supported

Supported

Supported

Not supported

Not supported

From the cloud

GeminiDB Redis->Redis

Not supported

Not supported

Not supported

Not supported

Not supported

From the cloud

GeminiDB Redis->Redis

Not supported

Not supported

Not supported

Not supported

Not supported

Comparison Restrictions

  • You can manually create a comparison task only when the task is in the incremental phase.
  • During a comparison, the comparison items are case sensitive. If one of the source or destination database is case insensitive and the other one is case sensitive, the comparison result may be inconsistent.
  • When a full migration task is complete, DRS automatically creates object-level and row comparison tasks. If operations are performed on data in the source database during data comparison, the comparison results may be inconsistent.
  • If DDL operations were performed on the source database, you need to compare the objects again to ensure the accuracy of the comparison results.
  • If data in the destination database is modified separately, the comparison results may be inconsistent.
  • If the encoding of the source database character type is abnormal, the database driver will convert the character type to an abnormal code point during DRS migration or comparison. As a result, the values may be consistent but the bytes may be inconsistent.
  • Currently, only tables with primary keys support value comparison. For tables that do not support value comparison, you can compare rows. Therefore, you can compare data by row or value based on scenarios.
  • The DRS task cannot be suspended during value comparison. Otherwise, the comparison task may fail.
  • Some data types do not support value comparison. For details, see Which of the Following Data Types Are Not Supported By Value Comparison?
  • To prevent resources from being occupied for a long time, DRS limits the comparison duration. If the comparison duration exceeds the threshold, the comparison task stops automatically.
    • When a full migration task is complete, DRS automatically creates object-level and row comparison tasks. The comparison duration limits to 30 minutes. After the threshold, the comparison tasks automatically stop and the full migration task stops.
    • For a row comparison task manually created in the incremental phase, if the source database is a relational database, the row comparison duration limits to 60 minutes. If the source database is a non-relational database, for example, MongoDB, the row comparison duration limits to 30 minutes.
  • To avoid occupying resources, the comparison results of DRS tasks can be retained for a maximum of 60 days. After 60 days, the comparison results are automatically cleared.
  • For a migration task from MySQL, virtual columns in the source database do not support value comparison. During the comparison, virtual columns are filtered out.

Impact on Databases

  • Object comparison: System tables of the source and destination databases are queried, occupying about 10 sessions. The database is not affected. However, if there are a large number of objects (for example, hundreds of thousands of tables), the database may be overloaded.
  • Row comparison: The number of rows in the source and destination databases is queried, which occupies about 10 sessions. The SELECT COUNT statement does not affect the database. However, if a table contains a large amount of data (hundreds of millions of records), the database will be overloaded and the query results will be returned slowly.
  • Value comparison: All data in the source and destination databases is queried, and each field is compared. The query pressure on the database leads to high I/O. The query speed is limited by the I/O and network bandwidth of the source and destination databases. Value comparison occupies one or two CPUs, and about 10 sessions.
  • Account comparison: The accounts and permissions of the source and destination databases are queried, which does not affect the database.

Estimated Comparison Duration

  • Object comparison: Generally, the comparison results are returned within several minutes based on the query performance of the source database. If the amount of data is large, the comparison may take dozens of minutes.
  • Row comparison: The SELECT COUNT method is used. The query speed depends on the database performance.
  • Value comparison: If the database workload is not heavy and the network is normal, the comparison speed is about 5 MB/s.
  • Account comparison: The results are returned with the object-level comparison results. If the number of objects is small, the results are returned in several minutes.

Prerequisites

  • You have logged in to the DRS console.
  • A migration task has been started.

Creating a comparison task

You can follow the comparison process or select a comparison method based on your service scenario. The following operations describe how to compare migration items by following the recommended migration process.

  1. On the Online Migration Management page, click the target migration task name in the Task Name/ID column.
  2. On the Migration Comparison tab, compare objects of the source and destination databases.

    You can also select the migration task on the Online Migration Management page and click View to go to the Migration Comparison page.

    1. Check the integrity of the database object.
      Click Validate Objects. On the Object-Level Comparison tab, click Compare. Wait for a while and click , and view the comparison result of each comparison item.
      Figure 2 Comparing objects

      Locate a comparison item you want to view and click View Details in the Operation column.

    2. After the check is complete, compare the number of rows and values.
      If you only need to compare the number of rows of all migration objects, you can select a specified migration task on the Online Migration Management page and click Compare in the Operation column to create a comparison task.
      1. In the Before You Start pane, click Validate All Rows/Values.
      2. In the displayed Create Comparison Task dialog box, specify Comparison Type, Comparison Method, Comparison Time, and Object. Then, click OK.
        Figure 3 Creating a comparison task
        • Comparison Type: compares rows and values.
        • Comparison Method: DRS provides static and dynamic comparison methods.
          • Static: All data in the source and destination databases is compared. The comparison task ends as the comparison is completed. Static comparison can only be performed when there are no ongoing services.
          • Dynamic: All data in the source database is compared with that in the destination database. After the comparison task is complete, incremental data in the source and destination databases is compared in real time. A dynamic comparison can be performed when data is changing.
          • The comparison mode can only be changed for MySQL.
          • During database-level migration, tables cannot be created in the source database during dynamic comparison. If you want to create a table in the source database, cancel the dynamic comparison first. After the new table is created and migrated, restart the dynamic comparison.

        • Comparison Time: You can select Start upon task creation or Start at a specified time. There is a slight difference in time between the source and destination databases during synchronization. Data inconsistency may occur. You are advised to compare migration items during off-peak hours for more accurate results.
        • Filter Data: After this function is enabled, objects can be compared based on the configured filtering criteria.

          Only MySQL-to-MySQL migration tasks support data filtering and comparison. To use this function, submit a service ticket. In the upper right corner of the management console, choose Service Tickets > Create Service Ticket.

          After enabling Filter Data, add filtering criteria for the table objects to be compared.

          In the Filtering Criteria area, enter the filtering criteria, and click Verify.
          • Standard SQL statements can be used to filter records. Each expression cannot contain packages, functions, variables, or constants specific to a database engine.
          • Enter the part following WHERE in the SQL statement (excluding WHERE and semicolons), for example, sid > 3 and sname like "G %".
          • Implicit conversion rules are not supported. Enter filtering criteria of a valid data type. For example, if column c of an Oracle database uses characters of the varchar2 type, the filtering criteria must be set to c > '10' instead of c > 10.
          • Filter criteria cannot be configured for large objects, such as CLOB, BLOB, and BYTEA.
          • You are not advised to set filter criteria for fields of approximate numeric types, such as FLOAT, DECIMAL, and DOUBLE.
          • Do not use fields containing special characters as a filter condition.
          • Objects whose database names, schema names, or table names are case insensitive cannot be filtered and compared.
          • Currently, condition-based filtering is not supported when there are more than 50,000 tables in a database.

          After the verification is successful, click Generate Processing Rule. The rule is displayed.

          Click OK.

        • Object: You can select objects to be compared based on the scenarios.

        When you select an object, the spaces before and after the object name are not displayed. If there are two or more consecutive spaces in the middle of the object name, only one space is displayed.

      3. After the comparison creation task is submitted, the Data-Level Comparison tab is displayed. Click to refresh the list and view the comparison result of the specified comparison type.
        Figure 4 Viewing the data-level comparison result

        To view the comparison details, locate the target comparison type and click View Results in the Operation column. On the displayed page, locate a pair of source and destination databases, and click View Details in the Operation column to view detailed comparison results.

        Figure 5 Row comparison details
        Figure 6 Value comparison details
        • You can cancel a running task at any time and view the comparison report of a canceled comparison task.
        • You can sort the row comparison results displayed on the current page in ascending or descending order based on the number of rows in the source database table or the destination database table.
        • If a negative number is displayed in the differences column, the number of rows in the destination database table is greater than that in the source database table. If a positive number is displayed in the differences column, the number of rows in the source database table is greater than that in the destination database table.
    3. Compare database accounts and permissions. Click the Account-Level Comparison tab to view the comparison results of database accounts and permissions.
      Figure 7 Account-level comparison
      • Full migration tasks do not support account-level comparisons.
    4. Perform a double check before the cutover.

      Click Double Check During Cutover. In the displayed Create Comparison Task dialog box, specify Comparison Type, Comparison Time, and Object. Then, click OK.

      For details about how to view comparison details, see 2.b.

    5. Stop the migration task.

      After the service system is successfully migrated to the destination database, stop the migration task to prevent operations in the source database from being synchronized to the destination database to overwrite the data. This operation only deletes the replication instance, and the migration task is still in the task list. You can view or delete the task. DRS will not charge for this task after you stop it.

      Generally, stopping a task can ensure the integrity of special objects because triggers and events are migrated when a task is being stopped. Only in some cases, such as network disconnections, a task may fail to be stopped. If a task fails to be stopped multiple times, you can select Forcibly stop task to reduce the waiting time. If you forcibly stop a task, triggers and events may not be completely migrated and you need to manually migrate them.

Periodic Comparison

Periodic comparison indicates that DRS periodically compares the number of rows or objects in the source database table with those in the destination database table and displays the comparison results.

  1. On the Online Migration Management page, click the target migration task name in the Task Name/ID column.
  2. Choose Migration Comparison.
  3. Click the Periodic Comparison tab and click Modify Comparison Policy.

    Only MySQL-to-MySQL and MySQL-to-GaussDB(for MySQL) migration tasks support periodic comparison.

  4. In the Modify Comparison Policy dialog box, enable periodic comparison, specify the comparison frequency, time interval, effective time and comparison type, and click Yes.

    • After periodic comparison is enabled, DRS compares the number of rows or objects at the scheduled time. You can view the comparison results on the Data-Level Comparison or Object-Level Comparison tab.
    • After periodic comparison is disabled, only historical comparison results can be viewed.
    • Modifications to the comparison policy settings take effect from the next comparison and do not affect the on-going periodic comparison tasks.
    • During periodic comparison, the source and destination databases will be read. Perform the comparison during off-peak hours.
    • During periodic comparison, ultra-large tables (those with more than 100 million rows) are automatically filtered out. You can use data-level comparison to spot check such large tables. It is not recommended that these large tables be compared periodically.
    Figure 8 Modify Comparison Policy

Quick Comparison

To accelerate and simplify the migration process, DRS provides the quick comparison function. You can directly perform a comparison on the migration task list. This function can be used to compare all migration objects only when incremental migration tasks are in progress.

  1. On the Online Migration Management page, locate the target migration task and click Compare in the Operation column.
  2. On the Create Comparison Task page, select Start upon task creation or Start at a specified time and click Yes to start the comparison task.

Viewing a Comparison Task

  1. On the Online Migration Management page, locate the target migration task and click View in the Operation column.
  2. On the Migration Comparison tab, view the data comparison result.