Updated on 2024-09-25 GMT+08:00

Data Comparison (Comparing DR Items)

Comparison Scenarios

DR item comparison: You can compare DR items to check data consistency between the service database and DR database. Currently, you can compare the following items during DR:

  • Object-level comparison: compares databases, events, indexes, tables, views, stored procedures, functions, and triggers.
  • 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 synchronized. This comparison method is recommended because it is fast.
    • Value comparison: It helps you check whether data in the synchronized table is consistent. The comparison process is relatively slow.

    To ensure that the comparison results are valid, compare data during off-peak hours by select Start at a specified time or compare cold data that is infrequently modified.

  • Account comparison: It compares usernames and permissions of the source and destination databases.

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

DR Direction

Data Flow

Object-level Comparison

Row Comparison

Value Comparison

Dynamic Comparison

Account-level Comparison

Current cloud as standby

MySQL->MySQL

Supported

Supported

Supported

Supported

Supported

Current cloud as active

MySQL->MySQL

Supported

Supported

Supported

Supported

Supported

Current cloud as standby

MySQL->GaussDB(for MySQL)

Supported

Supported

Supported

Supported

Supported

Current cloud as standby

DDM -> DDM

Supported

Supported

Not supported

Not supported

Not supported

Current cloud as active

DDM -> DDM

Supported

Supported

Not supported

Not supported

Not supported

Current cloud as standby

GaussDB(for MySQL)->GaussDB(for MySQL)

Supported

Supported

Supported

Supported

Supported

Current cloud as active

GaussDB(for MySQL)->GaussDB(for MySQL)

Supported

Supported

Supported

Supported

Supported

Dual-Active DR

MySQL->MySQL

Supported

Supported

Supported

Not supported

Supported

Dual-Active DR

GaussDB(for MySQL)->GaussDB(for MySQL)

Supported

Supported

Supported

Not supported

Supported

Constraints

  • During a comparison, the comparison items are case sensitive. If one of the service or DR database is case insensitive and the other one is case sensitive, the comparison result may be inconsistent.
  • If DDL operations were performed on the service database, you need to compare the objects again to ensure the accuracy of the comparison results.
  • If data in the DR database is modified separately, the comparison results may be inconsistent.
  • If the encoding of the service database character type is abnormal, the database driver will convert the character type to an abnormal code point during DRS disaster recovery 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 row comparison duration. If the row comparison duration exceeds the threshold, the row comparison task stops automatically. If the service database is a relational database, the row comparison duration is limited within 60 minutes. If the service database is a non-relational database, the row comparison duration is limited within 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.
  • If you want to compare values and the DRS task you create supports value comparison, select a large specification for your DRS instance when creating the DRS task.
  • For a DR task from MySQL or GaussDB(for 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 DR task has been started.

Procedure

  1. On the Disaster Recovery Management page, click the target DR task in the Task Name/ID column.
  2. On the Disaster Recovery Comparison tab, compare the service and DR databases.

    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 1 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.

      On the Data-Level Comparison tab, click Create Comparison Task. In the displayed dialog box, specify Comparison Method, Comparison Type, Comparison Time, and Object. Then, click OK.

      Figure 2 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.
        • Currently, only MySQL and GaussDB(for MySQL) support the comparison mode.
        • New tables cannot be created in the service database during dynamic comparison. If you want to create a table in the service database, cancel the dynamic comparison first. After the new table is created and real-time DR is performed, 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 DR tasks support data filtering and comparison.

        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.
      • Data-level comparison cannot be performed for tasks in initialization.
    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 3 Viewing the data-level comparison result
    4. 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 service and DR databases, and click View Details in the Operation column to view detailed comparison results.
      Figure 4 Row comparison details
      Figure 5 Value comparison details
      • You can also view comparison details of canceled comparison tasks.
      • 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.
    5. Check the database accounts and permissions. Click the Account-Level Comparison tab to view the comparison results of database accounts and permissions.
      Figure 6 Account-level comparison
      • Account comparison cannot be performed for tasks in the initialization phase.