This topic describes how to use OceanBase Migration Service (OMS) to migrate data from a PostgreSQL database to a MySQL tenant of OceanBase Database.
Background
You can create a data migration project in the OMS console to migrate the existing business data and incremental data from a PostgreSQL database to a MySQL tenant of OceanBase Database through schema migration, full migration, and incremental synchronization.
The PostgreSQL database supports the following modes: primary database only, standby database only, and primary/standby databases. The following table describes the data migration operations supported by each mode.
| Mode | Supported operations |
|---|---|
| Primary database only | Schema migration, full migration, incremental synchronization, full verification, and reverse incremental migration |
| Standby database only | Schema migration, full migration, and full verification |
| Primary/Standby databases | Primary database: incremental synchronization and reverse incremental migration Standby database: schema migration, full migration, and full verification |
Prerequisites
You have created a corresponding schema in the destination MySQL tenant of OceanBase Database. OMS allows you to migrate tables and columns. Therefore, you must create a corresponding schema in the destination database before migration.
You have created dedicated database users in the source PostgreSQL database and the destination MySQL tenant of OceanBase Database for data migration and granted the corresponding privileges to the users. For more information, see Create a database user.
Limits
PostgreSQL 10.x is supported.
OMS allows you to migrate tables with primary keys and tables with NOT NULL unique keys from a PostgreSQL database to a MySQL tenant of OceanBase Database.
When you use OMS to migrate data from a PostgreSQL database to a MySQL tenant of OceanBase Database, DDL synchronization is not supported.
OMS does not support triggers in the destination database.
When you migrate partitioned tables from a PostgreSQL database, note the following limits:
The parent table and child table must have the same schema.
The parent table and child table must have the same primary key columns, NOT NULL unique key columns, and partitioning key columns, or the primary key columns or NOT NULL unique key columns must include the partitioning key columns.
The primary keys or NOT NULL unique keys must be unique in the parent table.
OMS does not support the migration of tables in declarative partitioning in the PostgreSQL database.
REPLICA IDENTITY must be set to FULL for all parent tables and child tables to be migrated from the PostgreSQL database.
OMS does not support the migration of unlogged tables and temporary tables in the PostgreSQL database.
The data source identifiers and user accounts must be globally unique in OMS.
OMS allows you to migrate only databases and tables whose names are ASCII codes and do not contain special characters such as .|"'`()=;/&\n.
OMS supports full synchronization of tables whose partition fields are not within the primary keys, but does not support DDL operations that create tables.
Considerations
During reverse incremental migration from a PostgreSQL database to a MySQL tenant of OceanBase Database, if the MySQL tenant is of a version earlier than V3.2.x and contains a multi-partition table that has a globally unique index, data may be lost during migration if you update the value of the partitioning key of the table.
In a reverse incremental migration scenario, if data migration is performed in full-column matching mode for UPDATE and DELETE operations, the following issues may occur:
Poor performance
Due to the absence of primary key indexes, each UPDATE or DELETE operation is performed after a full-table scan.
Data inconsistency
The LIMIT syntax is not supported for UPDATE and DELETE operations in PostgreSQL databases. Therefore, if multiple data records are matched in full-column matching mode, the data at the source may be more than that at the destination after UPDATE or DELETE operations. Assume that the t1 table without a primary key has two columns c1 and c2. Two data records where c1 = 1 and c2 = 2 exist at the source. When you delete only one data record from the source based on the
where c1 = 1 and c2 = 2condition, the two data records that match the condition at the destination will be deleted accordingly, causing data inconsistency between the source and the destination.
OMS supports reverse incremental migration of
tsvectorfields from OceanBase Database to an ApsaraDB RDS for PostgreSQL instance. Thetsvectorfields must be written to OceanBase Database in the supported formats. Here are some examples:Data written to OceanBase Database in the 'a b c' format will be converted into the "'a' 'b' 'c'" format in the ApsaraDB RDS for PostgreSQL instance.
Data written to OceanBase Database in the 'a:1 b:2 c:3' format will be converted into the "'a':1 'b':2 'c':3" format in the ApsaraDB RDS for PostgreSQL instance.
Data written to OceanBase Database in a non-tsvector format such as "'a':cccc" cannot be migrated to the ApsaraDB RDS for PostgreSQL instance. For more information about the supported formats, see 8.11. Text Search Types in PostgreSQL documentation.
In a project for reverse incremental migration from a PostgreSQL database to a MySQL tenant of OceanBase Database of a version earlier than V3.2.x, if the source table is a multi-partition table with a global unique index and you update the values of the partitioning key of the table, data may be lost during migration.
If you change the unique index of the destination, you must restart the Incr-Sync component. Otherwise, the data may be inconsistent.
If the clocks are out of synchronization between the nodes or between the client and the server, a negative delay may occur in incremental synchronization or reverse incremental synchronization.
If you select migration objects based on matching rules, we recommend that you create standard CTAS statements and set object exclusion rules, such as
a.ctas*, to avoid interrupting the data migration project.In a multi-table aggregation scenario:
We recommend that you map objects in the source and destination databases by importing objects and configuring matching rules.
We recommend that you manually create schemas in the destination database. If you use OMS to create schemas, skip failed objects in the schema migration step.
If you skip the "Check the ROW_MOVEMENT parameter of the database" check item of the source primary database during the migration, data inconsistency may occur when you synchronize tables whose
ROW_MOVEMENTisenable.
Data type mappings
| PostgreSQL database | MySQL tenant of OceanBase Database |
|---|---|
| smallint | SMALLINT |
| bigint | BIGINT |
| int | INT |
| numeric [(p, s)] | DECIMAL |
| character | CHAR LONGTEXT |
| character varying | VARCHAR MEDIUMTEXT LONGTEXT |
| time [(p)] [without time zone] | TIME |
| time [(p)] with time zone | TIME |
| timestamp [(p)] with time zone | DATETIME |
| real | FLOAT |
| double precision | DOUBLE |
| smallserial | SMALLINT |
| serial | INT |
| bigserial | BIGINT |
| text | LONGTEXT |
| uuid | VARCHAR(36) |
| boolean | TINYINT(1) |
| json | LONGTEXT JSON (OMS 3.2.2 or later) |
Create a data migration project
Create a migration project.
Log on to the OMS console.
In the left-side navigation pane, click Data Migration.
On the Data Migration page, click Create Migration Project in the upper-right corner.
On the Select Source and Destination page, specify the following parameters.
Parameter Description Migration Project Name We recommend that you set it to a combination of digits and letters. It must not contain any spaces and cannot exceed 64 characters in length. Tag Click the field and select a target tag from the drop-down list. You can click Manage Tags to create, modify, and delete tags. For more information, see Use tags to manage data migration projects. Source If you have created a PostgreSQL data source, select it from the drop-down list. If you have not created a PostgreSQL data source, click Create Data Source in the drop-down list and create one in the dialog box that appears on the right. For more information, see Create a PostgreSQL data source.
You can select a PostgreSQL data source in primary database only mode or primary/standby databases mode. This topic describes how to create a data migration project with a PostgreSQL data source in primary/standby databases mode.Destination If you have created a data source for the MySQL tenant of OceanBase Database, select it from the drop-down list. If you have not created a data source for the MySQL tenant, click Create Data Source in the drop-down list and create one in the dialog box that appears on the right. For more information, see Create a physical data source of OceanBase Database.
Notice
The destination cannot be a MySQL tenant of OceanBase Database V4.0.0.Click Next.
In the dialog box that appears, click OK.
Note that this project supports only tables with a primary key or a non-null unique index and other tables are automatically filtered out.
On the Select Migration Type page, specify related parameters.
Options available for Migration Type include Schema Migration, Full Migration, Incremental Synchronization, Full Verification, and Reverse Incremental Migration.
Migration type Limits Schema Migration The definitions of data objects, such as tables, indexes, constraints, comments, and views, are migrated from the source database to the destination database. Temporary tables are automatically filtered out. Full Migration If you select Full Migration, we recommend that you use the ANALYZEstatement to collect the statistics of the PostgreSQL database before data migration.Incremental Synchronization Incremental Synchronization supports the following DML statements for data synchronization: INSERT,DELETE, andUPDATE. You can select statements based on your business needs. For more information, see DML filtering.
OMS automatically creates publications and slots for incremental synchronization from a PostgreSQL database. However, you need to monitor the usage of the disk for storing archive files. By default, OMS instructs the database to update theconfirmed_flush_lsnvalue of a slot every 10 minutes. The interval can be customized. By default, archive files need to be retained for 48 hours. Therefore, OMS instructs the database to clean up only archived logs that have been retained for more than 48 hours. The retention period can be customized.
If the archived logs cannot be cleared during the migration because slots exist, you need destroy the data migration project and then clear the archived logs.Full Verification - If you select Full Verification, we recommend that you collect the statistics of the PostgreSQL database and the MySQL tenant of OceanBase Database before full verification. For more information about how to collect statistics of a MySQL tenant of OceanBase Database, see Manually collect statistics.
- If you have selected Incremental Synchronization but did not select all DML statements in the DML Synchronization section, OMS does not support full verification.
- OMS supports full data verification of only tables with a unique key.
Reverse Incremental Migration You cannot select Reverse Incremental Migration in the following cases: - Multi-table aggregation and synchronization is enabled.
- Multiple schemas are configured in a rule to match one type of objects.
(Optional) Click Next. If you have selected Reverse Incremental Migration but the ConfigUrl, username, or password is not configured for the data source of the destination MySQL tenant of OceanBase Database, the More about Data Sources dialog box appears, prompting you to configure related parameters. For more information, see Create a physical data source of OceanBase Database.
After you configure the parameters, click Test Connectivity. After the test succeeds, click Save.
Click Next. On the Select Migration Objects page, select the migration objects and migration scope.
You can select one of the following two modes to migrate objects: Specify Objects or Match Rules.
Select Specify Objects. Then select the objects to be migrated on the left and click > to add them to the list on the right. You can select tables and views of one or more databases as the migration objects.
Notice
The names of tables to be migrated, as well as the names of columns in the tables, must not contain Chinese characters.
If the database or table name contains a double dollar sign ($$), you cannot create the migration project.
When you migrate data from a PostgreSQL database to a MySQL tenant of OceanBase Database, OMS allows you to import objects from text, rename object names, set row filters, view column information, and remove a single object or all objects to be migrated.
Operation Steps Import Objects - In the list on the right of the Specify Migration Scope section, click Import Objects in the upper-right corner.
- In the dialog box that appears, click OK.
Notice
This operation will overwrite previous selections. Proceed with caution. - In the Import Objects dialog box, import the objects to be migrated.
You can import CSV files to rename databases/tables and set row filtering conditions. For more information, see Download and import the settings of migration objects. - Click Validate.
- After the validation succeeds, click OK.
Rename OMS allows you to rename the migration objects. For more information, see Rename a database table. Settings OMS allows you to use the WHEREclause to filter rows. For more information, see Use SQL conditions to filter data
You can also view column information of the migration object in the View Column section.Remove/Remove All During data mapping, OMS allows you to remove one or more selected objects to be migrated to the destination. - To remove a single migration object:
In the list on the right of the Specify Migration Scope section, hover the pointer over the target object, and click Remove. - To remove all migration objects:
In the list on the right of the Specify Migration Scope section, click Remove All in the upper-right corner. In the dialog box that appears, click OK.
Select Match Rules. For more information, see Configure matching rules for migration objects.
Click Next. On the Migration Options page, configure the parameters.
Parameter Description Incremental Synchronization Start Timestamp - If you have set the migration type to Full Migration, this parameter is not displayed.
- If you have selected a migration type other than Full Migration, specify a point in time after which the data is to be synchronized. The default value is the current system time. You can select a point in time or enter a timestamp.
Notice
You can select the current time or a point in time earlier than the current time. This parameter is closely related to the retention period of archived logs. Generally, you can start data synchronization from the current timestamp.
Concurrency for Full Migration The value can be Smooth, Normal, or Fast. The quantity of resources to be consumed by a full data migration task varies based on the migration performance.
You can also modify the configurations of the Full-Import component to customize the concurrency.
Notice:
To enable this feature, select Full Migration on the Select Migration Type page.Full Verification Concurrency The value can be Smooth, Normal, or Fast. Different quantities of resources of the source and destination databases are consumed at different concurrencies.
You can also modify the configurations of the Full-Verification component to customize the concurrency.Incremental Record Retention Time The duration that incremental parsed files are cached in OMS. A longer retention period indicates more disk space occupied by the Store component of OMS. Whether to Allow Destination Table to Be Not Empty During Full Migration If destination tables are allowed to be not empty during full migration, full verification is performed in INmode.
Notice:
To enable this feature, select Full Migration on the Select Migration Type page.Whether to Allow Post-indexing You can specify whether to allow post-indexing after full migration is completed. Post-indexing can shorten the time of full migration.
Notice:- To enable this feature, select both Schema Migration and Full Migration on the Select Migration Type page.
- Only non-unique key indexes can be created after the migration is completed.
Click Precheck to start a pre-check on the data migration project.
During the pre-check, OMS checks the read and write privileges of the database users and the network connections of the databases. The data migration project can be started only after it passes all check items. If an error is returned during the pre-check:
You can identify and troubleshoot the problem and then perform the pre-check again.
You can click Skip in the Actions column of the pre-check item with the error. A dialog box will be displayed, prompting the impact caused if you skip this error. If you want to continue, click OK in the dialog box.
Click Start Project. If you do not need to start the project now, click Save to go to the details page of the data migration project. You can start the project later as needed.
OMS allows you to modify the migration objects when the data migration project is running. For more information, see View and modify migration objects. After a data migration project is started, the migration objects will be executed based on the selected migration type. For more information, see the "View migration details" section in the View details of a data migration project topic.