Skip to main content
StarRocks Migration Tool (SMT) is a command-line tool that generates the SQL you need to load data from a source database into the database through Flink. SMT mainly can:
  • Generate statements to create tables in the database based on information of the source database and the target cluster.
  • Generate SQL statements that can be executed in Flink’s SQL client to submit Flink jobs for synchronizing data, which simplifies full or incremental data synchronization in the pipeline. Currently, SMT supports the following source databases:
Download link: https://cdn-thirdparty.starrocks.com/smt.tar.gz?r=2

What SMT does and does not do

SMT generates SQL files and then exits. It reads the table definitions in your source database and writes two kinds of files to the result directory:
  • starrocks-create.*.sql: CREATE TABLE statements, which you run in the database.
  • flink-create.*.sql: Flink SQL that defines a source table and a sink table and submits an INSERT INTO ... SELECT job, which you run in the Flink SQL client.
SMT does not start, run, or connect to Flink, and it does not move any data. You still install and run a Flink cluster with the Flink CDC connector for your source database and the Flink connector for the database, and you run the generated files yourself.

Synchronize data without SMT

SMT is optional. Instead, you can:

Steps to use SMT

The generally involved steps are as follows:
  1. Configure the conf/config_prod.conf file.
  2. Execute starrocks-migration-tool.
  3. After execution, the SQL scripts are generated in the result directory by default. You can then use the SQL scripts in the result directory for metadata or data synchronization.

Configurations of SMT

  • [db]: information to connect the data source. Configure the information to connect the data source corresponding to the database type specified in the type patameter.
  • [other]: additional configurations. It is recommended to specify the actual number of BE nodes in the be_num patameter.
  • flink.starrocks.sink.*: configurations of flink-connector-starrocks. For detailed configurations and description, see configuration description.
  • [table-rule.1]: rule to match tables in the data source. The CREATE TABLE statement is generated based on the regular expressions configured in the rule to match the names of databases and tables in data source. Multiple rules can be configured, and each rule generates a corresponding result file, for example:
    • [table-rule.1] -> result/starrocks-create.1.sql
    • [table-rule.2] -> result/starrocks-create.2.sql
    Each rule needs to contain the configurations of database, table, and flink-connector-starrocks.
  • A separate rule can be configured for a large table that is split into shards in databases. For example, suppose that the two databases edu_db_1 and edu_db_2 contain the tables course_1 and course_2 respectively, and these two tables have the same structure. You can use the following rule to load data from these two tables into one table for analysis.
    This rule will automatically form a many-to-one loading relationship. The default name of the table that will be generated in the database is course__auto_shard, and you can also modify the table name in the related SOL script, such as result/starrocks-create.3.sql.

Synchronize MySQL to the database

Introduction

Flink CDC connector and SMT can synchronize data from MySQL within subsecond. img As shown in the image, SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of MySQL and the database. Flink CDC connector reads the MySQL Binlog and Flink-connector-starrocks writes data to the database .

Steps

  1. Download Flink. Flink 1.11 or later is supported.
  2. Download Flink CDC connector. Make sure that you download the flink-sql-connector-mysql-cdc-xxx.jar corresponding to the version of Flink.
  3. Download Flink-connector-starrocks.
  4. Copy flink-sql-connector-mysql-cdc-xxx.jar and flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
  5. Download smt.tar.gz.
  6. Extract and modify the configuration file of SMT.
  7. Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
  8. Use a SQL script whose prefix is starrocks-create to generate the table in the database.
  9. Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
    After the above command is successfully executed, the Flink job to synchronize data keeps running.
  10. Observe the status of the Flink job.
    If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.

Notes

  • How to enable MySQL binlog?
    1. Modify /etc/my.cnf:
    2. Restart mysqld. You can check whether MySQL binlog is enabled by executing SHOW VARIABLES LIKE 'log_bin';.

Synchronize PostgreSQL to the database

Tip With Flink CDC 3.5 or later, a Flink CDC pipeline can synchronize PostgreSQL to the database without SMT, and creates the tables itself. For a step-by-step guide, see Realtime synchronization from PostgreSQL.

Introduction

Flink CDC connector and SMT can synchronize data from PostgreSQL within subsecond. SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of PostgreSQL and the database. Flink CDC connector reads the WAL of PostgreSQL and Flink-connector-starrocks writes data to the database .

Steps

  1. Download Flink. The version of Flink is supported to be 1.11 or later.
  2. Download Flink CDC connector. Make sure that you download the flink-sql-connector-postgres-cdc-xxx.jar corresponding to the version of Flink.
  3. Download Flink StarRocks connector.
  4. Copy flink-sql-connector-postgres-cdc-xxx.jar and flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
  5. Download smt.tar.gz.
  6. Extract and modify the configuration file of SMT.
  7. Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
  8. Use a SQL script whose prefix is starrocks-create to generate the table in the database.
  9. Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
    After the above command is successfully executed, the Flink job to synchronize data keeps running.
  10. Observe the status of the Flink job.
    If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.

Notes

  • For PostgreSQL v9.*, a special flink-cdc configuration as shown below is required (It is recommended to use PostgreSQL v10.* or later. Otherwise, you need to install WAL decoding plugins):
  • How to enable PostgreSQL WAL?
    Specify replica identity FULL for the tables that need to be synchronized.
    After making these changes, restart PostgreSQL .

Synchronize Oracle to the database

Introduction

Flink CDC connector and SMT can synchronize data from Oracle within subsecond. SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of Oracle and the database. Flink CDC connector reads the logminer of Oracle and Flink-connector-starrocks writes data to the database.

Steps

  1. Download Flink. The version of Flink is supported to be 1.11 or later.
  2. Download Flink CDC connector. Make sure that you download the flink-sql-connector-oracle-cdc-xxx.jar corresponding to the Flink version.
  3. Download Flink StarRocks connector.
  4. Copy flink-sql-connector-oracle-cdc-xxx.jar and flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
  5. Download smt.tar.gz.
  6. Extract and modify the configuration file of SMT.
  7. Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
  8. Use a SQL script whose prefix is starrocks-create to generate the table in the database.
  9. Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
    After the above command is successfully executed, the Flink job to synchronize data keeps running.
  10. Observe the status of the Flink job.
    If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.

Notes

  • Synchronize Oracle using logminer:
  • The database configurations in the [table-rule.1] does not support regular expression, so the complete database names need to be specified.
  • Because Oracle12c supports CDB mode, SMT internally automatically determines whether CDB is enabled and modifies the flink-cdc configuration correspondingly. However, users need to pay attention to whether the c## prefix needs to be added to the configuration of [db].user to avoid issues of insufficient permission.

Synchronize Hive to the database

Introduction

This guide explains how to use SMT to synchronize Hive data to the database. During synchronization, a Duplicate table in the database is created and a Flink job keeps running to synchronize data.

Steps

Preparations

The supported authentication methods are as follows:
  • nosasl, zk: do not need to specify the user and password.
  • none, none_http, ldap: specify the user and password.
  • kerberos, kerberos_http: perform the following steps:
    • Execute kadmin.local on the Hive cluster and check list_principals to find the corresponding principal name. For example when the principal name is hive/emr-header-1.cluster-49148@EMR.49148.COM, the user needs to be set as hive/emr-header-1.cluster-49148, and the password is left empty.
    • Execute kinit -kt /path/to/keytab principal on the machine where SMT is executed and execute klist to see if the correct token is generated.

Data synchronization

  1. Execute starrocks-migrate-tool.
  2. Use a SQL script whose prefix is starrocks-create to generate the table in the database.
  3. In flink/conf/, create and edit the file sql-client-defaults.yaml:
  4. Download the dependency package (flink-sql-connector-hive-xxxx) from the Hive page of the corresponding version of Flink and place it in the flink/lib directory.
  5. Start the Flink cluster and execute flink/bin/sql-client.sh embedded < result/flink-create.all.sql to start data synchronization.

Synchronize SQL Server to the database

Introduction

Flink CDC connector and SMT can synchronize data from SQL Server within subsecond. SMT can automatically generate CREATE TABLE statements of the Flink’s source and sink tables based on the cluster information and table structure of SQL Server and the database. Flink CDC connector captures and records row-level changes that occur in the SQL Server database server. The principle is to use the CDC feature provided by SQL Server itself. The CDC capability of SQL Server itself can archive specified changes in the database to specified change tables. The SQL Server CDC connector first reads historical data from the table using JDBC, and then fetches incremental changes from the change tables, thereby achieving full incremental synchronization. Then, Flink-connector-starrocks writes data to the database.

Steps

  1. Download Flink. The version of Flink is supported to be 1.11 or later.
  2. Download Flink CDC connector. Make sure that you download the flink-sql-connector-sqlserver-cdc-xxx.jar corresponding to the Flink version.
  3. Download Flink StarRocks connector.
  4. Copy flink-sql-connector-sqlserver-cdc-xxx.jar, flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
  5. Download smt.tar.gz.
  6. Extract and modify the configuration file of SMT.
  7. Execute starrocks-migrate-tool. All SQL scripts are generated in the result directory.
​ ```Bash ./starrocks−migrate−tool./starrocks-migrate-tool ls result flink-create.1.sql smt.tar.gz starrocks-create.all.sql flink-create.all.sql starrocks-create.1.sql starrocks-external-create.all.sql
  1. Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
    After the above command is successfully executed, the Flink job to synchronize data keeps running.
  2. Observe the status of the Flink job.
    If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.

Notes

  1. Make sure that the Server Agent Service is enabled. Check if the Server Agent Service is running normally.
    Enable the Server Agent Service.
  2. Make sure that CDC for the corresponding database is enabled. ​ Check if CDC for the corresponding database is enabled.
    ​ Enable CDC. ​ :::note ​ When executing this command, make sure that the user serverRole is sysadmin. ​ :::
  3. Make sure that CDC for the corresponding table is enabled.

Synchronize TiDB to the database

Introduction

Flink CDC connector and SMT can synchronize data from TiDB within subsecond. SMT can automatically generate DDL statements for the Flink’s source tables and sink tables based on the cluster information and table structure of TiDB and the database. The Flink CDC connector captures data by directly reading full and incremental data from the underlying TiKV storage. The full data is obtained from ranges partitioned based on keys, and the incremental data is obtained by using the CDC Client provided by TiDB. Subsequently, the data is written to the database through Flink-connector-starrocks.

Steps

  1. Download Flink. The version of Flink is supported to be 1.11 or later.
  2. Download Flink CDC connector. Make sure that you download the flink-sql-connector-tidb-cdc-xxx.jar corresponding to the Flink version.
  3. Download Flink StarRocks connector.
  4. Copy flink-sql-connector-tidb-cdc-xxx.jar, flink-connector-starrocks-xxx.jar to flink-xxx/lib/.
  5. Download smt.tar.gz.
  6. Extract and modify the configuration file of SMT.
  7. Execute starrocks-migrate-tool*. All SQL scripts are generated in the result directory.
  8. Use a SQL script whose prefix is starrocks-create to generate the table in the database.
  9. Use a SQL script whose prefix is flink-create to generate the Flink source and sink tables, and start a Flink job to synchronize data.
​ After the above command is successfully executed, the Flink job to synchronize data keeps running.
  1. Observe the status of the Flink job.
    If the job execution encounters an error, you can view detailed error information in the Flink logs. Also, you can modify the Flink configurations in the file conf/flink-conf.yaml, such as memory and slot.

Notes

For TiDB whose version is before v4.0.0, additional configuration of flink.cdc.pd-addresses is required.