Real-time data synchronization from RDS PostgreSQL to Fluss

Updated at:

This topic describes how to create a data ingestion YAML job in Realtime Compute for Apache Flink to merge two order tables from ApsaraDB RDS for PostgreSQL into Alibaba Cloud Fluss, and how to verify the synchronization of full data, INSERT, UPDATE, and DELETE operations, and new columns.

Background information

The synchronization relationship is as follows:

image

This example uses a primary key table to store the latest state of each order instead of keeping all historical changes. The two source tables have the same schema, and orderkey is unique across both tables. Amounts use NUMERIC(12,2) to avoid representing money as floating-point numbers.

Prerequisites

Item

Requirement in this example

Realtime Compute for Apache Flink

A workspace is created. Use VVR 11.9 or later, with a version that the console marks as recommended or stable.

RDS PostgreSQL

Use the primary instance. This example uses PostgreSQL 16. Do not use a read-only instance.

Alibaba Cloud Fluss

A dedicated Alibaba Cloud Fluss cluster is activated.

Network

RDS, Flink, and Fluss reside in the same region and the same VPC. The RDS whitelist is configured to allow access from the Flink execution environment.

Permissions

The operator has the required console permissions. The Fluss account has the permissions to create, read, and write the target database and tables.

Demo data

The source schema demo_fluss and the target table fluss.orders are dedicated to this procedure and isolated from production data.

Note: schema-change.enabled requires VVR 11.9 or later. This example uses this parameter to enable schema change inference for PostgreSQL tables.

Create variables

In the Flink development console, choose Security Services > Variable Management and create the following variables. Set the password to the ciphertext type. The YAML job and the SQL statements then reference it through ${secret_values.variable_name}.

Variable

Value

pg_hostname

The internal endpoint of the RDS PostgreSQL primary instance, without the port.

pg_username

The RDS synchronization account used later in this topic.

pg_password

The password of the RDS account.

fluss_bootstrap_servers

The server address list on the Fluss cluster details page. Keep the actual ports and separate multiple addresses with commas (,).

fluss_username

The administrator account of the Fluss cluster, or an authorized Fluss user account.

fluss_password

The access password of the Fluss user. This is not the RDS password or an AccessKey secret.

For more information about how to use variables, see Manage variables.

Step 1: Prepare the RDS PostgreSQL data source

1. Create the instance, database, and account

In the RDS console, create or select a PostgreSQL 16 primary instance, and create a database named orders. Configure internal network access and the whitelist.

Follow the ApsaraDB RDS configuration steps in Configure a PostgreSQL database:

  • Set wal_level to logical. This parameter change requires an instance restart, so schedule the effective time in advance. For a production instance, assess the change before you adjust the parameter.

  • Check the available capacity of max_replication_slots and max_wal_senders.

  • This example uses a privileged RDS account to create tables and run the synchronization. Create an account in the console or use an existing privileged account, and then store its credentials in the variables.

Important: In a production environment, grant the minimum required permissions. Make sure that the synchronization account can read data, perform logical replication, and manage the required publications. SELECT permission alone is not enough to complete all operations.

After you connect to the orders database, run the following checks:

SELECT version();
SHOW wal_level;
SHOW max_replication_slots;
SHOW max_wal_senders;

wal_level must be logical. During the incremental snapshot phase, each job requires up to "actual source parallelism + 1" replication slots. Reserve free slots based on the source parallelism at which the job actually runs. When multiple jobs run at the same time, add up their requirements and leave capacity for other replication tasks.

2. Create the two order tables and insert initial data

Use the privileged account described above to connect to the orders database, and run the following SQL statement once in a new demo schema:

CREATE SCHEMA demo_fluss;

CREATE TABLE demo_fluss.orders_1 (
    orderkey BIGINT PRIMARY KEY,
    custkey BIGINT NOT NULL,
    order_status VARCHAR(16),
    total_price NUMERIC(12,2),
    order_date DATE,
    order_priority VARCHAR(16),
    clerk VARCHAR(32),
    ship_priority INTEGER,
    comment VARCHAR(128)
);

CREATE TABLE demo_fluss.orders_2 (
    orderkey BIGINT PRIMARY KEY,
    custkey BIGINT NOT NULL,
    order_status VARCHAR(16),
    total_price NUMERIC(12,2),
    order_date DATE,
    order_priority VARCHAR(16),
    clerk VARCHAR(32),
    ship_priority INTEGER,
    comment VARCHAR(128)
);

ALTER TABLE demo_fluss.orders_1 REPLICA IDENTITY FULL;
ALTER TABLE demo_fluss.orders_2 REPLICA IDENTITY FULL;

INSERT INTO demo_fluss.orders_1 VALUES
    (1, 101, 'NEW', 100.00, DATE '2026-10-01', 'NORMAL', 'clerk-01', 0, 'first order'),
    (2, 102, 'NEW', 200.00, DATE '2026-10-02', 'NORMAL', 'clerk-02', 0, 'second order'),
    (3, 101, 'DONE', 150.00, DATE '2026-10-03', 'HIGH', 'clerk-01', 1, 'third order');

INSERT INTO demo_fluss.orders_2 VALUES
    (11, 101, 'NEW', 80.00, DATE '2026-10-01', 'NORMAL', 'clerk-03', 0, 'fourth order'),
    (12, 103, 'NEW', 120.00, DATE '2026-10-02', 'NORMAL', 'clerk-03', 0, 'fifth order'),
    (13, 102, 'DONE', 300.00, DATE '2026-10-03', 'HIGH', 'clerk-02', 1, 'sixth order');

CREATE PUBLICATION rds_pg_fluss_pub
FOR TABLE demo_fluss.orders_1, demo_fluss.orders_2;

REPLICA IDENTITY FULL makes update and delete events carry the complete row image from before the change. The publication covers only the two source tables in this example.

Verify the initial data, the replica identity, and the publication scope:

SELECT orderkey, custkey, order_status, total_price
FROM demo_fluss.orders_1
UNION ALL
SELECT orderkey, custkey, order_status, total_price
FROM demo_fluss.orders_2
ORDER BY orderkey;

SELECT relname, relreplident
FROM pg_class
WHERE oid IN (
    'demo_fluss.orders_1'::regclass,
    'demo_fluss.orders_2'::regclass
);

SELECT pubname, schemaname, tablename
FROM pg_publication_tables
WHERE pubname = 'rds_pg_fluss_pub';

The result must contain 6 orders. The relreplident value of both tables must be f, and the publication must include both tables.

Step 2: Configure Alibaba Cloud Fluss and the query catalog

1. Obtain the connection information

Create a cluster by following Create a Stream Storage cluster for Apache Fluss. On the cluster details page, copy the actual server address list.

Obtain the access credentials and grant permissions on the target database and tables by following User management. Alibaba Cloud Fluss uses SASL/PLAIN authentication, so specify the actual Fluss user and the corresponding access password.

2. Create a catalog for queries

In the Flink workspace, go to Data Management and create a built-in Fluss catalog named fluss_catalog:

Parameter

Value

catalog name

fluss_catalog

cluster

The Alibaba Cloud Fluss cluster used in this example. After you select it, confirm that the server addresses are filled in correctly.

bootstrap.servers

${secret_values.fluss_bootstrap_servers}

default-database

fluss

client.security.sasl.username

${secret_values.fluss_username}

client.security.sasl.password

${secret_values.fluss_password}

Select a creation method that supports credential configuration. If the console shows the password-free method by default, switch to a method that accepts access credentials. The password-free method of the query catalog is independent of the authentication settings of the data ingestion YAML job, so you must still specify the authentication parameters in the YAML.

Alternatively, in a session cluster that runs VVR 11.9 or later, go to Development > Data Query and run the following SQL statement with password authentication. Use either the console or SQL to create the catalog, and create a catalog with a given name only once:

CREATE CATALOG fluss_catalog WITH (
    'type' = 'fluss',
    'bootstrap.servers' = '${secret_values.fluss_bootstrap_servers}',
    'default-database' = 'fluss',
    'client.security.protocol' = 'SASL',
    'client.security.sasl.mechanism' = 'PLAIN',
    'client.security.sasl.username' = '${secret_values.fluss_username}',
    'client.security.sasl.password' = '${secret_values.fluss_password}'
);

USE CATALOG fluss_catalog;
SHOW DATABASES;

Confirm that the target database fluss exists. If it does not, run the following statement with an account that has database creation permissions:

USE CATALOG fluss_catalog;
CREATE DATABASE IF NOT EXISTS fluss;

In this example, the ingestion job creates the fluss.orders primary key table, so you do not need to create the table in advance. If a table with the same name already exists, verify its primary key, field types, and data ownership first. When the existing table contains production data, use a separate demo target table to avoid deleting or overwriting production data.

For more information about catalog configuration, see Manage a Fluss Catalog.

Step 3: Create and start the data ingestion job

1. Create a YAML draft

Go to Development > Data Ingestion, create a data ingestion draft named, for example, rds-postgres-to-fluss, select an engine of VVR 11.9 or later, and enter the complete configuration:

source:
  type: postgres
  name: RDS PostgreSQL Source
  hostname: ${secret_values.pg_hostname}
  port: 5432
  username: ${secret_values.pg_username}
  password: ${secret_values.pg_password}
  tables: 'orders.demo_fluss.orders_[0-9]+'
  slot.name: rds_pg_fluss_demo
  decoding.plugin.name: pgoutput
  debezium.publication.name: rds_pg_fluss_pub
  debezium.publication.autocreate.mode: disabled
  scan.startup.mode: initial
  schema-change.enabled: true

sink:
  type: fluss
  name: Alibaba Cloud Fluss Sink
  bootstrap.servers: ${secret_values.fluss_bootstrap_servers}
  properties.client.security.protocol: sasl
  properties.client.security.sasl.mechanism: PLAIN
  properties.client.security.sasl.username: ${secret_values.fluss_username}
  properties.client.security.sasl.password: ${secret_values.fluss_password}

route:
  - source-table: 'demo_fluss.orders_[0-9]+'
    sink-table: fluss.orders

pipeline:
  name: RDS PostgreSQL to Alibaba Cloud Fluss

Configuration notes:

  • Set source.type to postgres to use the PostgreSQL data ingestion connector.

  • tables uses the three-part "database.schema.table" format. A single job can connect to only one PostgreSQL database.

  • route.source-table uses the "schema.table" format of the source events to merge the two source tables into fluss.orders.

  • scan.startup.mode: initial reads the full data on the first stateless start and then keeps reading the WAL. On a stateful recovery, the job resumes from the offset stored in the state.

  • slot.name specifies the replication slot that the connector creates. Each job uses its own replication slot, and a slot can be consumed by only one job.

  • debezium.publication.name specifies the publication created in Step 1. debezium.publication.autocreate.mode: disabled disables automatic creation and updates so that the publication keeps covering only the two source tables.

  • The Fluss connection information is configured directly in sink. Client parameters in the YAML use the properties. prefix, whereas catalog SQL parameters do not.

  • Fluss primary key tables support INSERT, UPDATE, and DELETE. Log tables without a primary key support only INSERT.

2. Deploy and start the job

  1. Run a deep check to identify syntax, network, and permission issues.

  2. Click Deploy and confirm the deployment.

  3. Go to O&M Center > Job O&M and open the deployment details.

  4. Enable checkpoints. To make the synchronization results easier to observe, set the checkpoint interval and the minimum time between checkpoints to 10s. In a production environment, adjust these values based on throughput and resource usage.

  5. When you start the new job in this example for the first time, select stateless start. To resume an existing job, use a stateful start so that the processing progress is preserved.

  6. Wait for the full synchronization to finish, confirm that a checkpoint succeeds, and check the job logs for errors.

Note: A session cluster is used for catalog SQL statements and data queries. Data ingestion jobs run in a separate runtime environment and are not deployed to a session cluster.

3. Verify the full data

In Development > Data Query, select batch mode and run the following queries. If the current mode is streaming, switch to batch mode first.

SELECT * FROM `fluss_catalog`.`fluss`.`orders` LIMIT 20;

SELECT COUNT(*) AS row_count
FROM `fluss_catalog`.`fluss`.`orders`;

Expected result: 6 orders with the primary keys 1, 2, 3, 11, 12, 13, which match the source. The row order in the query result may differ.

Step 4: Verify INSERT, UPDATE, DELETE, and schema changes

1. Verify INSERT, UPDATE, and DELETE

After you confirm that the full synchronization result is as expected, run the following SQL statement once in the orders database in RDS:

INSERT INTO demo_fluss.orders_1 VALUES
    (4, 103, 'NEW', 50.00, DATE '2026-10-04', 'NORMAL', 'clerk-04', 0, 'new order');

UPDATE demo_fluss.orders_1
SET order_status = 'DONE', total_price = 220.00
WHERE orderkey = 2;

DELETE FROM demo_fluss.orders_2 WHERE orderkey = 11;

After the data is synchronized, run the batch queries again:

SELECT * FROM `fluss_catalog`.`fluss`.`orders` WHERE orderkey = 4;
SELECT * FROM `fluss_catalog`.`fluss`.`orders` WHERE orderkey = 2;
SELECT * FROM `fluss_catalog`.`fluss`.`orders` WHERE orderkey = 11;
SELECT COUNT(*) AS row_count FROM `fluss_catalog`.`fluss`.`orders`;

Expected results:

Check item

Expected result

orderkey = 4

A new order appears with the amount 50.00.

orderkey = 2

Only the updated record is kept, with the status DONE and the amount 220.00.

orderkey = 11

No record is returned.

Total number of rows

Still 6: one row is added and one row is deleted.

2. Verify new columns

In RDS, add a column with the same name to both source tables, and then update the data:

ALTER TABLE demo_fluss.orders_1 ADD COLUMN quantity BIGINT;
ALTER TABLE demo_fluss.orders_2 ADD COLUMN quantity BIGINT;

UPDATE demo_fluss.orders_1 SET quantity = 100 WHERE orderkey IN (1, 2);
UPDATE demo_fluss.orders_2 SET quantity = 200 WHERE orderkey = 12;
Note: For PostgreSQL pgoutput, a schema change is carried by a relation message that a data change after the DDL triggers. The connector infers the new column from that message. If you run only the DDL, the target table does not synchronize the schema change immediately. When you merge two source tables, wait until the schema information of both tables is synchronized.

Run the queries again in Flink:

SELECT * FROM `fluss_catalog`.`fluss`.`orders` WHERE orderkey = 1;
SELECT * FROM `fluss_catalog`.`fluss`.`orders` WHERE orderkey = 2;
SELECT * FROM `fluss_catalog`.`fluss`.`orders` WHERE orderkey = 12;

The quantity column must appear: orders 1, 2 have 100, and order 12 has 200. Orders that are not updated do not get a backfilled quantity when the column is added.

This example verifies the synchronization of new columns. Fluss supports appending new columns at the end of a table, and the schema change policy used by the job must allow ADD COLUMN events. Physical column drops, renames, column type changes, DROP, and TRUNCATE are out of scope for this example.

FAQ

Symptom

Troubleshooting

The RDS connection fails

Check the internal endpoint, VPC, whitelist, account, and database name. The whitelist must allow only the required access scope.

Only full data is synchronized, with no incremental data

Check wal_level, the publication scope, replication permissions, slot capacity, and the actual consumption status.

The replication slot is already in use

Check whether another job or client occupies a slot with the same name, and use a separate replication slot for the current job. Keep the slots that are still needed for recovery.

Fluss authentication fails

Verify the Fluss user and the corresponding password, and the properties.client.security.* parameters in the YAML.

UPDATE or DELETE results are not as expected

Verify the target primary key, REPLICA IDENTITY FULL on the source, and primary key uniqueness across tables. Log tables without a primary key support only inserts.

New columns are not synchronized

Check the VVR version, schema-change.enabled, pgoutput, and whether a data change followed the DDL.

Important: When multiple source tables are merged into the same target table, the primary key must be unique across the tables. The same primary key in different source tables can cause records to be overwritten or deleted by mistake. When you use a composite primary key, make sure that update and delete events carry all primary key fields.

The synchronization scope of this example covers the two tables that exist when the job starts. To change the scope, update both the table matching configuration and the publication scope, and confirm how the historical data of the new tables is read. The table matching expression does not automatically extend a manually created publication.

Clean up resources

  1. Stop the data ingestion job and the query job in this example. If you need a stateful recovery later, keep the checkpoints or savepoints, the replication slot, and the WAL required for the recovery. Checkpoints and savepoints do not contain WAL data.

  2. After you confirm that the job is no longer needed and does not require recovery, and that the replication slot is not in use, run the following SQL statement to clean up the replication slot and the publication in this example:

SELECT slot_name, plugin, database, active
FROM pg_replication_slots
WHERE slot_name = 'rds_pg_fluss_demo';

SELECT pg_drop_replication_slot(slot_name)
FROM pg_replication_slots
WHERE slot_name = 'rds_pg_fluss_demo' AND NOT active;

DROP PUBLICATION rds_pg_fluss_pub;
  1. Keeping a replication slot after consumption stops can cause the WAL to accumulate, so continue to monitor RDS disk usage. WAL cleanup after a slot is dropped is managed by the database and may not complete immediately.

  2. After you confirm that the data no longer needs to be kept, use the console to clean up the tables, the Fluss cluster, the RDS instance, and the session resources dedicated to this example. Deleting a catalog does not release the storage instance or stop running jobs. Keep the resources that are shared with other workloads.

Note: RDS, Flink, and Fluss resources are billed according to the billing rules of each product. After you finish, check the resource status and release the dedicated resources that are no longer in use.

References