PolarDB-X CDC (Public preview)
Learn how to use the PolarDB-X connector.
Background
PolarDB for Xscale (PolarDB-X) is Alibaba Cloud's high-performance, cloud native distributed database, offering high throughput, large storage capacity, low latency, scalability, and ultra-high availability.
This connector requires VVR 11.5 or later and PolarDB-X 2.0 or later.
The PolarDB-X CDC connector supports only source tables. To query a PolarDB-X instance as a dimension table or write to it as a sink table, use the MySQL connector (public preview).
|
Category |
Description |
|
Supported types |
Source table, data ingestion source |
|
Running mode |
streaming mode only |
|
Data format |
N/A |
|
Specific monitoring metrics |
|
|
API type |
SQL, data ingestion YAML jobs |
|
Supports updating or deleting data in the sink table |
No |
Key features
The PolarDB-X CDC connector optimizes Binlog parsing with server-side filtering. It trims irrelevant Binlog data on the PolarDB-X server, which increases throughput and conserves network bandwidth.
On-demand Binlog subscription
With server-side Binlog filtering, the connector sends only required change logs to the client. This reduces network traffic and improves data consumption throughput.
For example, to subscribe only to changes from the db.table1 and db.table2 tables in your PolarDB-X server, configure your Flink SQL job as follows:
CREATE TABLE polardbx_table_foo (
... -- Define the table schema here
) WITH (
'connector' = 'polardbx-cdc',
'database-name' = 'db',
'table-name' = '.*',
..., -- Other parameters
'polardbx.binlog.include.tables' = 'db.table1,db.table2' -- Captures changes from only the specified tables
);
Unlike the MySQL CDC connector, which loads an entire instance's Binlog for client-side filtering, the PolarDB-X CDC connector performs server-side filtering. This capability enables on-demand client subscriptions, significantly reducing network I/O overhead.
Usage limits
Server-side Binlog filtering and table-level subscription require PolarDB-X server version 2.5.0 or later and Log Service component version 5.4.20 or later.
SQL
Syntax
CREATE TABLE polardbx_customer_table(
`id` STRING,
[columnName dataType,]*
PRIMARY KEY(`id`) NOT ENFORCED
) WITH (
'connector' = 'polardbx-cdc',
'hosts' = 'pxc-**************-pub.polarx.rds.aliyuncs.com',
'username' = 'pdx_user',
'password' = 'pdx_password',
'database' = 'full_db',
'collection' = 'customers'
)
WITH parameters
|
Parameter |
Description |
Type |
Required |
Default |
Remarks |
|
connector |
The name of the connector. |
STRING |
Yes |
None |
The value must be |
|
hostname |
The IP address or hostname of the PolarDB-X database. |
STRING |
Yes |
None |
Use the cluster address from the instance connection information. |
|
port |
The port number of the PolarDB-X database. |
INTEGER |
No |
3306 |
None |
|
username |
The username for the PolarDB-X database. |
STRING |
Yes |
None |
None |
|
password |
The password for the PolarDB-X database. |
STRING |
Yes |
None |
None |
|
database-name |
The name of the PolarDB-X database. |
STRING |
Yes |
None |
You can use a regular expression to read data from multiple databases. Note
When using a regular expression, do not use the ^ and $ characters to match the start and end of the string. |
|
table-name |
The name of the PolarDB-X table. |
STRING |
Yes |
None |
You can use a regular expression to read data from multiple tables. Note
When using a regular expression, do not use the ^ and $ characters to match the start and end of the string. |
|
server-time-zone |
The session time zone for the database connection. |
STRING |
No |
The job's runtime environment time zone. |
Specify an IANA time zone identifier, such as |
|
scan.incremental.snapshot.chunk.size |
The number of rows in each chunk for incremental snapshot reads. |
INTEGER |
No |
8096 |
During the snapshot phase, the connector splits a table into chunks and caches them in memory. A smaller chunk size increases the total number of chunks. While this improves fault tolerance granularity, it also increases the risk of out of memory (OOM) errors and reduces throughput. Set an appropriate value to balance performance, fault tolerance, and memory consumption. |
|
scan.snapshot.fetch.size |
The maximum number of rows to fetch at a time when reading a snapshot of the table. |
INTEGER |
No |
1024 |
None |
|
connect.timeout |
The timeout for establishing a connection to the PolarDB-X database. |
DURATION |
No |
30s |
None |
|
connection.pool.size |
The size of the database connection pool. |
INTEGER |
No |
20 |
A database connection pool reuses connections to reduce connection overhead. |
|
connect.max-retries |
The maximum number of retries after a failed connection attempt to the PolarDB-X database. |
INTEGER |
No |
3 |
None |
|
scan.startup.mode |
The startup mode for data consumption. |
STRING |
No |
initial |
Valid values:
Important
For the earliest-offset, specific-offset, and timestamp startup modes, the table schema at startup must match the schema at the specified offset. A schema mismatch will cause the job to fail. Ensure the table schema does not change between the specified Binlog offset and the job startup. |
|
scan.startup.specific-offset.file |
The name of the Binlog file to start from when |
STRING |
No |
None |
This parameter is only used when scan.startup.mode is set to specific-offset. Example: |
|
scan.startup.specific-offset.pos |
The offset within the specified Binlog file when |
INTEGER |
No |
None |
This parameter is only used when scan.startup.mode is set to specific-offset. |
|
scan.startup.specific-offset.gtid-set |
The GTID set to start from when |
STRING |
No |
None |
This parameter is only used when scan.startup.mode is set to specific-offset. Example: |
|
scan.startup.timestamp-millis |
The startup timestamp in milliseconds when |
LONG |
No |
None |
This parameter is only used when scan.startup.mode is set to timestamp. The unit is milliseconds. |
|
scan.startup.specific-offset.skip-events |
The number of Binlog events to skip when reading from a specific offset. |
INTEGER |
No |
None |
This parameter is only used when scan.startup.mode is set to specific-offset. |
|
scan.startup.specific-offset.skip-rows |
The number of row changes to skip when reading from a specific offset. A single Binlog event can contain multiple row changes. |
INTEGER |
No |
None |
This parameter is only used when scan.startup.mode is set to specific-offset. |
|
heartbeat.interval |
The interval at which the source sends a heartbeat event to advance the Binlog offset. |
DURATION |
No |
None |
A heartbeat event advances the source's Binlog offset. This prevents the Binlog from being purged on an idle source. If the Binlog is purged, the job fails and requires a stateless restart to recover. |
|
chunk-meta.group.size |
The size of the chunk metadata. |
INTEGER |
No |
1000 |
If the metadata size exceeds this value, it is split into multiple parts for transmission. |
|
chunk-key.even-distribution.factor.upper-bound |
The upper bound of the chunk distribution factor for even partitioning. |
DOUBLE |
No |
1000.0 |
If the distribution factor is greater than this value, uneven chunking is used. Chunk distribution factor = (MAX(chunk-key) - MIN(chunk-key) + 1) / total number of rows. |
|
chunk-key.even-distribution.factor.lower-bound |
The lower bound of the chunk distribution factor for even partitioning. |
DOUBLE |
No |
0.05 |
If the distribution factor is less than this value, uneven chunking is used. Chunk distribution factor = (MAX(chunk-key) - MIN(chunk-key) + 1) / total number of rows. |
|
scan.newly-added-table.enabled |
Specifies whether to scan for newly added tables that match the capture criteria when restarting from a Checkpoint. |
BOOLEAN |
No |
false |
When enabled, a job restarted from a Checkpoint or Savepoint scans for and synchronizes newly added tables that match the 'table-name' pattern. It also stops tracking tables that no longer match. |
|
scan.incremental.snapshot.chunk.key-column |
Specifies the column used for data chunking during the snapshot phase. |
STRING |
See Remarks |
None |
|
|
scan.incremental.close-idle-reader.enabled |
Specifies whether to close idle readers after the snapshot phase is complete. |
BOOLEAN |
No |
false |
For this setting to take effect, |
|
scan.incremental.snapshot.backfill.skip |
Specifies whether to skip the backfill process during the snapshot reading phase. |
BOOLEAN |
No |
false |
Valid values:
If backfill is skipped, changes made to the table during the snapshot phase are read in the later incremental phase instead of being merged into the snapshot. Important
Skipping backfill can cause data inconsistencies because changes that occur during the snapshot are replayed in the incremental phase. This mode only guarantees at-least-once semantics. |
|
scan.parse.online.schema.changes.enabled |
Specifies whether to attempt to parse DDL events for RDS lock-free changes during the incremental phase. |
BOOLEAN |
No |
false |
Valid values:
This is an experimental feature. Before performing lock-free schema changes in production, create a Savepoint for the Flink job to ensure it can be recovered. |
|
scan.only.deserialize.captured.tables.changelog.enabled |
Specifies whether to deserialize change events only for the specified captured tables during the incremental phase. |
BOOLEAN |
No |
true |
Valid values:
|
|
scan.read-changelog-as-append-only.enabled |
Specifies whether to convert the changelog stream to an append-only stream. |
BOOLEAN |
No |
false |
Valid values:
|
|
scan.parallel-deserialize-changelog.enabled |
Specifies whether to use multiple threads to deserialize change events during the incremental phase. |
BOOLEAN |
No |
false |
Valid values:
|
|
scan.parallel-deserialize-changelog.handler.size |
The number of event handlers to use when deserializing change events in parallel. |
INTEGER |
No |
2 |
None |
|
scan.incremental.snapshot.unbounded-chunk-first.enabled |
Specifies whether to distribute unbounded chunks first during the snapshot reading phase. |
BOOLEAN |
No |
false |
Valid values:
This is an experimental feature. Enabling it can reduce the risk of an out of memory (OOM) error on the TaskManager when synchronizing the last chunk of a snapshot. This setting should be configured before the job's first startup. |
|
polardbx.binlog.ignore.archive-events.enabled |
Specifies whether to ignore archive events (primarily |
BOOLEAN |
No |
false |
|
|
polardbx.binlog.ignore.query-events.enabled |
Specifies whether to ignore |
BOOLEAN |
No |
false |
|
|
polardbx.binlog.include.tables |
Reads Binlog events only from the specified tables. Use commas ( |
STRING |
No |
None |
|
|
polardbx.binlog.exclude.tables |
Ignores Binlog events from the specified tables. Use commas ( |
STRING |
No |
None |
Type mapping
|
PolarDB-X type |
Flink type |
|
TINYINT |
TINYINT |
|
SMALLINT |
SMALLINT |
|
TINYINT UNSIGNED |
|
|
TINYINT UNSIGNED ZEROFILL |
|
|
INT |
INT |
|
MEDIUMINT |
|
|
SMALLINT UNSIGNED |
|
|
SMALLINT UNSIGNED ZEROFILL |
|
|
BIGINT |
BIGINT |
|
INT UNSIGNED |
|
|
INT UNSIGNED ZEROFILL |
|
|
MEDIUMINT UNSIGNED |
|
|
MEDIUMINT UNSIGNED ZEROFILL |
|
|
BIGINT UNSIGNED |
DECIMAL(20, 0) |
|
BIGINT UNSIGNED ZEROFILL |
|
|
SERIAL |
|
|
FLOAT [UNSIGNED] [ZEROFILL] |
FLOAT |
|
DOUBLE [UNSIGNED] [ZEROFILL] |
DOUBLE |
|
DOUBLE PRECISION [UNSIGNED] [ZEROFILL] |
|
|
REAL [UNSIGNED] [ZEROFILL] |
|
|
NUMERIC(p, s) [UNSIGNED] [ZEROFILL] |
DECIMAL(p, s) |
|
DECIMAL(p, s) [UNSIGNED] [ZEROFILL] |
|
|
BOOLEAN |
BOOLEAN |
|
TINYINT(1) |
|
|
DATE |
DATE |
|
TIME [(p)] |
TIME [(p)] [WITHOUT TIME ZONE] |
|
DATETIME [(p)] |
TIMESTAMP [(p)] [WITHOUT TIME ZONE] |
|
TIMESTAMP [(p)] |
TIMESTAMP_LTZ [(p)] |
|
TIMESTAMP [(p)] WITH LOCAL TIME ZONE |
|
|
CHAR(n) |
STRING |
|
VARCHAR(n) |
|
|
TEXT |
|
|
BINARY |
BYTES |
|
VARBINARY |
|
|
BLOB |
Data ingestion
Realtime Compute for Apache Flink 11.6 now supports the PolarDB-X connector as a data source for data ingestion YAML jobs.
Syntax
source:
type: polardbx
name: PolarDB-X Source
hostname: localhost
port: 3306
username: <username>
password: <password>
tables: pdb.order_table
# Ignore archive events in the binlog
polardbx.binlog.ignore.archive-events.enabled: true
# Ignore query events in the binlog
polardbx.binlog.ignore.query-events.enabled: true
# Subscribe only to the binlog for pdb.order_table to save bandwidth.
polardbx.binlog.include.tables: pdb.order_table
sink:
type: values
Parameter
|
Parameter |
Description |
Required |
Type |
Default |
Remarks |
|
type |
The type of the data source. |
Yes |
STRING |
N/A |
The value must be |
|
name |
The name of the data source. |
No |
STRING |
N/A |
N/A |
|
hostname |
The IP address or hostname of the PolarDB-X instance. |
Yes |
STRING |
N/A |
The VPC address is recommended. Note
If your PolarDB-X instance and Realtime Compute for Apache Flink workspace are not in the same VPC, you must establish cross-VPC connectivity or access the instance over the public network. For details, see Workspace Management and Operations and How can a fully-managed Flink cluster access the public network?. |
|
username |
The username to connect to the PolarDB-X database. |
Yes |
STRING |
N/A |
N/A |
|
password |
The password for the specified username. |
Yes |
STRING |
N/A |
N/A |
|
tables |
The PolarDB-X tables to synchronize. |
Yes |
STRING |
N/A |
Note
|
|
tables.exclude |
The tables to exclude from synchronization. |
No |
STRING |
N/A |
Note
A period (.) separates the database name and table name. To match a literal period, you must escape it with a backslash. For example: |
|
port |
The port of the PolarDB-X instance. |
No |
INTEGER |
3306 |
N/A |
|
schema-change.enabled |
Specifies whether to emit schema change events. |
No |
BOOLEAN |
true |
N/A |
|
jdbc.properties.* |
Custom connection parameters for the JDBC URL. |
No |
STRING |
N/A |
You can pass custom connection parameters. For example, to disable SSL, set 'jdbc.properties.useSSL' = 'false'. |
|
debezium.* |
Custom Debezium parameters for reading the binlog. |
No |
STRING |
N/A |
You can pass custom Debezium parameters. For example, set 'debezium.event.deserialization.failure.handling.mode' = 'ignore' to define how the connector handles deserialization errors. |
|
scan.incremental.snapshot.chunk.size |
The size of each chunk, in number of rows. |
No |
INTEGER |
8096 |
A PolarDB-X table is split into multiple chunks for reading. The data in each chunk is cached in memory until it is fully read. A smaller chunk size increases the total number of chunks, which provides finer-grained fault recovery but can increase the risk of OOM and reduce overall throughput. You must balance these trade-offs and configure a reasonable chunk size. |
|
scan.snapshot.fetch.size |
The maximum number of records fetched at once during a full table snapshot. |
No |
INTEGER |
1024 |
N/A |
|
scan.startup.mode |
The startup mode for consuming data. |
No |
STRING |
initial |
Valid values:
Important
For the earliest-offset, specific-offset, and timestamp startup modes, the job fails with an error if the table schema at the startup time is different from the table schema at the time of the specified startup position. In other words, when you use these three startup modes, you must ensure that the schema of the corresponding table does not change between the specified Binlog consumption position and the job startup time. |
|
scan.startup.specific-offset.file |
The binlog filename for the startup position. |
No |
STRING |
N/A |
Required when scan.startup.mode is set to specific-offset. Example format: |
|
scan.startup.specific-offset.pos |
The offset within the specified binlog file to start from. |
No |
INTEGER |
N/A |
Required when scan.startup.mode is set to specific-offset. |
|
scan.startup.specific-offset.gtid-set |
The GTID set for the startup position. |
No |
STRING |
N/A |
Used when scan.startup.mode is set to specific-offset. Example GTID set format: |
|
scan.startup.timestamp-millis |
The timestamp in milliseconds for the startup position. |
No |
LONG |
N/A |
Required when scan.startup.mode is set to timestamp. Important
When you specify a timestamp, the connector locates the correct starting file by reading the first event of each binlog file to check its timestamp. Ensure the target binlog file for the specified timestamp has not been purged from the database and remains readable. |
|
server-time-zone |
The session time zone used by the database. |
No |
STRING |
The time zone of the Flink job's runtime environment (the availability zone of your workspace). |
Example: Asia/Shanghai. This parameter controls how |
|
scan.startup.specific-offset.skip-events |
The number of binlog events to skip when reading from a specific position. |
No |
INTEGER |
N/A |
Used when scan.startup.mode is set to specific-offset. |
|
scan.startup.specific-offset.skip-rows |
The number of row changes to skip when reading from a specific position. A single binlog event can contain multiple row changes. |
No |
INTEGER |
N/A |
Used when scan.startup.mode is set to specific-offset. |
|
connect.timeout |
The maximum time to wait for a database connection before retrying. |
No |
DURATION |
30s |
N/A |
|
connect.max-retries |
The maximum number of retries for a failed database connection. |
No |
INTEGER |
3 |
N/A |
|
connection.pool.size |
The size of the database connection pool. |
No |
INTEGER |
20 |
The connection pool reuses connections to reduce connection overhead. |
|
heartbeat.interval |
The interval at which the source sends a heartbeat event to advance the binlog position. |
No |
DURATION |
30s |
Heartbeat events advance the binlog position for tables that are updated infrequently. Without them, the binlog position might not advance, which can lead to binlog expiration. An expired binlog causes the job to fail, requiring a stateless restart to recover. |
|
scan.incremental.snapshot.chunk.key-column |
Specifies a column to use as the splitting key for chunks during the snapshot phase. |
No |
STRING |
N/A |
You can only select one column from the primary key. |
|
chunk-meta.group.size |
The size of the chunk metadata. |
No |
INTEGER |
1000 |
If the metadata size exceeds this value, it is split into multiple parts for transmission. |
|
chunk-key.even-distribution.factor.lower-bound |
The lower bound of the chunk distribution factor for determining whether to use even chunking. |
No |
DOUBLE |
0.05 |
If the distribution factor is less than this value, uneven chunking is used. Chunk distribution factor = (MAX(chunk-key) - MIN(chunk-key) + 1) / total number of data rows. |
|
chunk-key.even-distribution.factor.upper-bound |
The upper bound of the chunk distribution factor for determining whether to use even chunking. |
No |
DOUBLE |
1000.0 |
If the distribution factor is greater than this value, uneven chunking is used. Chunk distribution factor = (MAX(chunk-key) - MIN(chunk-key) + 1) / total number of data rows. |
|
scan.incremental.close-idle-reader.enabled |
Specifies whether to close idle readers after the snapshot phase is complete. |
No |
BOOLEAN |
false |
For this setting to take effect, you must set |
|
scan.only.deserialize.captured.tables.changelog.enabled |
Specifies whether to deserialize change events only for the specified tables during the incremental phase. |
No |
BOOLEAN |
true |
Valid values:
|
|
scan.parallel-deserialize-changelog.enabled |
Specifies whether to use multiple threads to parse change events during the incremental phase. |
No |
BOOLEAN |
false |
Valid values:
|
|
scan.parallel-deserialize-changelog.handler.size |
The number of event handlers to use when parsing change events in parallel. |
No |
INTEGER |
2 |
N/A |
|
metadata-column.include-list |
The metadata columns to pass to the downstream sink. |
No |
STRING |
N/A |
Available metadata includes Note
The PolarDB-X CDC YAML connector does not require or support adding metadata columns for the database name, table name, or Important
The |
|
scan.newly-added-table.enabled |
When restarting from a checkpoint or savepoint, specifies whether to synchronize newly added tables that match the tables pattern and stop tracking tables that no longer match. |
No |
BOOLEAN |
false |
This setting takes effect only when restarting from a checkpoint or savepoint. |
|
scan.binlog.newly-added-table.enabled |
During the incremental phase, specifies whether to send data for newly matched tables. |
No |
BOOLEAN |
false |
Cannot be enabled at the same time as |
|
scan.incremental.snapshot.chunk.key-column |
Specifies a splitting key column for chunking during the snapshot phase for specific tables. |
No |
STRING |
N/A |
|
|
scan.parse.online.schema.changes.enabled |
During the incremental phase, specifies whether to parse DDL events for ApsaraDB RDS lock-free schema changes. |
No |
BOOLEAN |
false |
Valid values:
This is an experimental feature. Before performing an online lock-free change, we recommend that you create a savepoint for the Flink job to ensure it can be restored if needed. |
|
scan.incremental.snapshot.backfill.skip |
Specifies whether to skip backfill during the snapshot reading phase. |
No |
BOOLEAN |
false |
Valid values:
If backfill is skipped, changes to the table that occur during the snapshot phase are read in the later incremental phase instead of being merged into the snapshot. Important
Skipping backfill can cause data inconsistencies because changes from the snapshot phase may be replayed. This mode provides at-least-once semantics. |
|
treat-tinyint1-as-boolean.enabled |
Specifies whether to treat the |
No |
BOOLEAN |
true |
Valid values:
|
|
treat-timestamp-as-datetime-enabled |
Specifies whether to treat the |
No |
BOOLEAN |
false |
Valid values:
The PolarDB-X When enabled, this parameter converts PolarDB-X |
|
include-comments.enabled |
Specifies whether to synchronize table and column comments. |
No |
BOOLEAN |
false |
Valid values:
Enabling this parameter increases the memory usage of the job. |
|
scan.incremental.snapshot.unbounded-chunk-first.enabled |
Specifies whether to dispatch unbounded chunks first during the snapshot reading phase. |
No |
BOOLEAN |
false |
Valid values:
This is an experimental feature. Enabling it can reduce the risk of an OOM error on the TaskManager when the last chunk is being synchronized. We recommend that you add this parameter before the first startup of the job. |
|
binlog.session.network.timeout |
The network timeout for the binlog connection. |
No |
DURATION |
10m |
If set to |
|
scan.rate-limit.records-per-second |
The maximum number of records the source can emit per second. |
No |
LONG |
N/A |
Use this parameter to limit data reading throughput. This limit applies to both the snapshot and incremental phases. The source's During the snapshot reading phase, you may also need to reduce the number of rows read per batch by decreasing the value of the |
|
include-binlog-meta.enable |
Specifies whether to include raw PolarDB-X binlog metadata, such as GTID and binlog position, in the emitted records. |
No |
BOOLEAN |
false |
Applicable to raw binlog synchronization scenarios, such as replacing an existing Canal-based synchronization pipeline. |
|
polardbx.binlog.ignore.archive-events.enabled |
Specifies whether to ignore archive events (primarily |
No |
BOOLEAN |
false |
|
|
polardbx.binlog.ignore.query-events.enabled |
Specifies whether to ignore |
No |
BOOLEAN |
false |
|
|
polardbx.binlog.include.tables |
A comma-separated list of tables to subscribe to for binlog events. |
No |
STRING |
N/A |
Note
This parameter affects only the incremental (binlog) phase and does not apply to the snapshot phase. |
|
polardbx.binlog.exclude.tables |
A comma-separated list of tables whose binlog events should be ignored. |
No |
STRING |
N/A |
Note
This parameter affects only the incremental (binlog) phase and does not apply to the snapshot phase. |