ApsaraDB for SelectDB supports four approaches for loading data from a PostgreSQL source: Data Transmission Service (DTS), DataWorks, Flink change data capture (CDC), and catalog. The PostgreSQL source can be a self-managed PostgreSQL database, an ApsaraDB RDS for PostgreSQL instance, or a PolarDB for PostgreSQL cluster.
Compare migration solutions
| Solution | Historical data migration | Incremental data synchronization | Schema migration | Database migration | Incremental synchronization of DDL operations | Data verification |
|---|---|---|---|---|---|---|
| DTS | Yes | Yes | Yes | Yes | Yes | Yes |
| DataWorks | Yes | Yes | Yes | Yes | Yes | No |
| Flink CDC | Yes | Yes | Yes | Yes | Yes | No |
| Catalog | Yes | No | No | No | No | No |
Choose a migration solution
DTS: Best for production workloads that require real-time synchronization, DDL propagation, and end-to-end data verification. DTS handles the full migration lifecycle with minimal manual setup.
DataWorks: Suitable when your team already uses DataWorks for data integration workflows and needs batch synchronization with scheduling support.
Flink CDC: Suitable for teams with existing Flink infrastructure who need fine-grained control over the synchronization pipeline, including customizing parallelism and table filtering.
Catalog: A lightweight option for one-time historical data loads. Use a JDBC catalog to query PostgreSQL data through federated queries, then copy it into SelectDB with
INSERT INTO SELECT.
Prerequisites
Before you begin, make sure that:
The PostgreSQL source and the SelectDB instance can communicate over the network.
If they are in the same virtual private cloud (VPC), no additional network configuration is required.
If they are in different VPCs, configure cross-VPC connectivity. For details, see What do I do if a connection fails to be established between my SelectDB instance and a data source?
The IP address of the PostgreSQL source is added to the IP address whitelist of the SelectDB instance. For details, see Configure an IP address whitelist.
If the PostgreSQL source supports an IP address whitelist, the CIDR block of the SelectDB instance is added to it.
To find the VPC IP address of the SelectDB instance: go to the SelectDB console, open the Instance Details page, and check the Network Information section. For details, see How do I view the IP addresses in the VPC to which my ApsaraDB SelectDB instance belongs?
To find the public IP address of the SelectDB instance: run the
pingcommand against the public endpoint.
Use DTS to migrate data
DTS supports historical data migration, incremental data synchronization, schema migration, DDL operation synchronization, and data verification.
Refer to the following DTS guides based on your PostgreSQL source type:
Data synchronization:
Synchronize data from a PolarDB for PostgreSQL cluster to an ApsaraDB for SelectDB instance
Synchronize data from an ApsaraDB RDS for PostgreSQL instance to an ApsaraDB for SelectDB instance
Data migration:
Use DataWorks to migrate data
Step 1: Add data sources
Add a PostgreSQL data source and a SelectDB data source to DataWorks.
Add a PostgreSQL data source. For details, see PostgreSQL data source.
Add a SelectDB data source. For details, see Add and manage data sources. Use the following parameters when adding the SelectDB data source:
Parameter Description Example Data Source Name A name for this data source connection. selectdb_prodHost Address/IP Address The JDBC URL in jdbc:mysql://<ip>:<port>/<dbname>format. Get the VPC endpoint or public endpoint and the MySQL port from the Network Information section of the Instance Details page in the SelectDB console.jdbc:mysql://selectdb-cn-4xl3jv1****.selectdbfe.rds.aliyuncs.com:9030/test_dbHTTP Connection Address The HTTP endpoint in <ip>:<port>format. Get the VPC endpoint or public endpoint and the HTTP port from the Network Information section of the Instance Details page in the SelectDB console.selectdb-cn-4xl3jv1****.selectdbfe.rds.aliyuncs.com:8080Username The username of the owner account of the SelectDB instance. adminPassword The password of the owner account of the SelectDB instance. —
Step 2: Configure a data synchronization task
Create a batch synchronization task using either the visual editor or the code editor:
Use Flink CDC to migrate data
Flink CDC supports historical data migration, incremental data synchronization, schema migration, and DDL operation synchronization.
Set up the environment
The following steps deploy a Flink standalone cluster of version 1.16.
Download and extract the Flink package.
wget https://archive.apache.org/dist/flink/flink-1.16.3/flink-1.16.3-bin-scala_2.12.tgz tar -zxvf flink-1.16.3-bin-scala_2.12.tgzIf version 1.16.3 is no longer available, download a later version from Apache Flink downloads.
Download the CDC connector and the SelectDB connector into the
lib/directory.Full data synchronization requires Flink 1.15 or later. For other connector versions, see org/apache/doris on Maven.
cd flink-1.16.3/lib/ wget https://repo1.maven.org/maven2/com/ververica/flink-sql-connector-mysql-cdc/2.4.2/flink-sql-connector-mysql-cdc-2.4.2.jar wget https://repo.maven.apache.org/maven2/org/apache/doris/flink-doris-connector-1.16/1.5.2/flink-doris-connector-1.16-1.5.2.jarStart the Flink standalone cluster.
bin/start-cluster.shCreate a SelectDB instance. For details, see Create an instance.
Connect to the SelectDB instance over the MySQL protocol. For details, see Connect to an instance.
Create a test database and table in SelectDB.
CREATE DATABASE test_db; USE test_db; CREATE TABLE employees ( emp_no int NOT NULL, birth_date date, first_name varchar(20), last_name varchar(20), gender char(2), hire_date date ) UNIQUE KEY(`emp_no`) DISTRIBUTED BY HASH(`emp_no`) BUCKETS 1;
Submit a Flink CDC job
The following command submits a Flink CDC job that synchronizes all tables matching the filter from a PostgreSQL source to the SelectDB database db1.
<FLINK_HOME>/bin/flink run \
-Dexecution.checkpointing.interval=10s \
-Dparallelism.default=1 \
-c org.apache.doris.flink.tools.cdc.CdcTools \
lib/flink-doris-connector-1.16-1.5.2.jar \
postgres-sync-database \
--database db1 \
--postgres-conf hostname=127.0.0.1 \
--postgres-conf port=5432 \
--postgres-conf username=postgres \
--postgres-conf password="123456" \
--postgres-conf database-name=postgres \
--postgres-conf schema-name=public \
--postgres-conf slot.name=test \
--postgres-conf decoding.plugin.name=pgoutput \
--including-tables "tbl1|test.*" \
--sink-conf fenodes=selectdb-cn-****.selectdbfe.rds.aliyuncs.com:8080 \
--sink-conf username=admin \
--sink-conf password=****Parameter reference:
| Parameter | Required | Description | Example |
|---|---|---|---|
execution.checkpointing.interval | Yes | Checkpoint interval, which controls synchronization frequency. | 10s |
parallelism.default | No | Parallelism of the Flink job. Increase this value to accelerate synchronization. | 1 |
database | Yes | The target database name in the SelectDB instance. | db1 |
including-tables | No | PostgreSQL tables to synchronize. Separate multiple table names with |. Regular expressions are supported. | table1|tbl.* |
excluding-tables | No | Tables to exclude. Uses the same syntax as including-tables. | tmp.* |
postgres-conf | Yes | Postgres CDC source configuration. The hostname, username, password, table-name, schema-name, and database-name parameters are required. For the full parameter list, see Postgres CDC Connector. | — |
sink-conf | Yes | Doris sink configuration. For details, see Use Flink to import data. | — |
table-conf | No | SelectDB table properties applied when the target table is created. | — |
Use a catalog to migrate data
The catalog approach uses a JDBC catalog to query PostgreSQL data through federated queries, then copies it into SelectDB with INSERT INTO SELECT. This approach is suited for one-time historical data loads.
Do not use Data Management (DMS) to connect to the SelectDB instance for this procedure — the SWITCH statement becomes invalid in DMS sessions. Use a MySQL client instead.Connect to the SelectDB instance. For details, see Connect to an instance.
Create a JDBC catalog for the PostgreSQL source.
Parameters:
Parameter Required Description Example userYes The account used to connect to the PostgreSQL source. rootpasswordYes The password for the account. 123456jdbc_urlYes The JDBC URL for the PostgreSQL source. jdbc:postgresql://127.0.0.1:5432/demodriver_urlYes The filename of the JDBC driver JAR. postgresql-42.5.1.jardriver_classYes The JDBC driver class name. org.postgresql.Driverlower_case_table_namesNo Whether to sync database and table names in lowercase. Default: false.falseonly_specified_databaseNo Whether to migrate only specific databases. Default: false.falseinclude_database_listNo Comma-separated list of databases to migrate. Takes effect only when only_specified_database=true. Database names are case-sensitive. Default:"".db1,db2exclude_database_listNo Comma-separated list of databases to exclude. Takes effect only when only_specified_database=true. Database names are case-sensitive. Default:"".tmp_dbCREATE CATALOG jdbc_postgresql PROPERTIES ( "type"="jdbc", "user"="root", "password"="123456", "jdbc_url" = "jdbc:postgresql://127.0.0.1:5432/demo", "driver_url" = "postgresql-42.5.1.jar", "driver_class" = "org.postgresql.Driver", "checksum" = "20c8228267b6c9ce620fddb39467d3eb" );For the complete catalog configuration reference, see JDBC data source.
Create a table in SelectDB and copy data from the PostgreSQL source using
INSERT INTO SELECT.-- Create the target table CREATE TABLE selectdb_table ... -- Migrate data from the PostgreSQL source INSERT INTO selectdb_table SELECT * FROM jdbc_postgresql.pg_database.pg_table;For details on the
INSERT INTOsyntax, see Use INSERT INTO to import data.