Synchronize RDS PostgreSQL data to DLF Iceberg tables in real time

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 an Iceberg table managed by the new version of Data Lake Formation (DLF), and how to verify full data synchronization, inserts, updates, deletes, and new column synchronization.

Background information

The synchronization relationship is as follows:

image

This example uses the Iceberg REST catalog and fully managed storage of the new version of DLF. The catalog registered in Flink is named dlf_iceberg and is used to access the destination tables.

The two source tables share the same schema, and orderkey is unique across the tables. The destination keeps the latest state of each order instead of all historical changes. Amounts use NUMERIC(12,2) to avoid representing money as floating-point numbers.

This example uses the source schema demo_iceberg. When multiple synchronization jobs access the same RDS database, each job must use a separate publication and replication slot.

Prerequisites

Item

Requirement in this example

Realtime Compute for Apache Flink

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

RDS PostgreSQL

A primary instance. This topic uses PostgreSQL 16. Do not use a read-only instance.

DLF

The new version of DLF is activated, and an Iceberg REST catalog is created, such as pg_iceberg_demo.

Network

RDS, Flink, and DLF reside in the same region. A whitelist is configured for RDS, and DLF has a trust list that allows access from the Flink VPC.

Permissions

DLF API permissions are granted to the Flink service role, and data permissions on the destination catalog are granted.

Demo data

The source schema demo_iceberg and the destination table default.orders are dedicated to this operation and isolated from production data.

YAML writes to DLF REST require VVR 11.6.0 or later, and PostgreSQL schema change inference requires VVR 11.9 or later. This example uses VVR 11.9 or later. Catalog queries run in a session execution environment, and the ingestion job runs in a separate job execution environment.

This example uses DLF fully managed storage. Configure the storage type and redundancy on the DLF creation page. No additional OSS bucket is required. Permissions, network, and authentication settings for other storage types or Internet access differ from this example and must follow the corresponding access method.

Create project variables

Create the following variables in Security Services > Variable Management of the Flink development console:

Variable

Value source

pg_hostname

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

pg_username

The RDS synchronization account described later in this topic

pg_password

The password of the account. Select the encrypted type.

dlf_region

The region ID of the actual DLF catalog, such as cn-hangzhou

dlf_uri

The VPC endpoint of Iceberg REST in that region, including the /iceberg path

dlf_catalog_name

The name of the actual DLF catalog. In this example, it can be pg_iceberg_demo.

dlf_region, dlf_uri, and the actual DLF catalog must belong to the same region. Copy the VPC endpoint from the region access instructions.

For the reference format of project variables, see Variable management.

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, create the orders database, and configure internal access and the whitelist.

Follow the Alibaba Cloud RDS configuration steps in Configure a PostgreSQL database:

  • Set wal_level to logical. This parameter change requires an instance restart, so plan the effective time in advance. Adjust parameters on a production instance only after a change evaluation.

  • Check the available capacity of max_replication_slots and max_wal_senders.

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

Important: In production environments, grant permissions based on the principle of least privilege, and make sure that the synchronization account has the permissions for data reads, logical replication, and the required publication management. The SELECT permission alone is not enough to complete all operations.

After you connect to the orders database, check the following items:

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 needs at most "actual source parallelism + 1" replication slots. Reserve idle slots based on the source parallelism that each job actually runs with. When multiple jobs run at the same time, add up their requirements and leave capacity for other replication tasks.

2. Create the order tables, data, and publication

Use the privileged account to connect to the orders database, and run the following statements once in a new demo schema:

CREATE SCHEMA demo_iceberg;

CREATE TABLE demo_iceberg.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_iceberg.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_iceberg.orders_1 REPLICA IDENTITY FULL;
ALTER TABLE demo_iceberg.orders_2 REPLICA IDENTITY FULL;

INSERT INTO demo_iceberg.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_iceberg.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_iceberg_pub
FOR TABLE demo_iceberg.orders_1, demo_iceberg.orders_2;

Check the data and the publication scope:

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

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

SELECT pubname, schemaname, tablename
FROM pg_publication_tables
WHERE pubname = 'rds_pg_iceberg_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: Create a DLF catalog and configure Flink access

1. Create the actual DLF catalog

Follow Get started with DLF to activate the new version of DLF and create the actual catalog pg_iceberg_demo. Select the storage configuration as required by the page.

The DLF catalog and the Flink catalog in the next step are different concepts:

Name

Value in this example

Purpose

Actual DLF catalog

pg_iceberg_demo

Stores the destination metadata and data resources. Enter this name in warehouse.

Flink built-in catalog

dlf_iceberg

The access entry registered in the Flink workspace. Reused by SQL and YAML.

Iceberg namespace

default

The destination database used in this example

Iceberg table

orders

The merged order table

2. Configure the VPC and identity authorization

Follow Compute engine integration with fine-grained access control:

  1. Add the VPC where Flink resides to the trust list in DLF.

  2. Verify the authorization of the Flink service role AliyunStreamAsiDefaultRole. This example uses the AliyunDLFFullAccess policy. In production environments, limit the authorization scope based on the principle of least privilege.

  3. In the actual DLF catalog, grant the service role the data permissions required to create, read, and write the demo tables. Configure RAM API permissions and catalog data permissions separately. Grant the permissions required to run the job to the service role.

This example uses VPC access and service role authentication, so the YAML job requires no long-term AccessKey pair. The authentication method for public REST access differs from this example and must follow the corresponding access method. Complete catalog creation and access verification before you start data ingestion.

3. Register an Iceberg catalog in Flink

Go to Data Development > Data Query, select a session execution environment of VVR 11.9 or later, and run the following SQL:

CREATE CATALOG dlf_iceberg WITH (
    'type' = 'iceberg',
    'catalog-type' = 'rest',
    'uri' = '${secret_values.dlf_uri}',
    'warehouse' = '${secret_values.dlf_catalog_name}',
    'rest.signing-region' = '${secret_values.dlf_region}',
    'io-impl' = 'org.apache.iceberg.rest.DlfFileIO'
);

USE CATALOG dlf_iceberg;
SHOW DATABASES;

According to Manage Iceberg catalogs, a default database is created after you create a DLF-type catalog. Make sure that the database is visible, and that in Data Management you can find the built-in catalog dlf_iceberg.

Note: Enter the name of the actual DLF catalog in warehouse, such as pg_iceberg_demo, instead of an OSS storage path.

The destination default.orders must not exist yet. In this example, the data ingestion job creates a new table based on the source primary key. If a table with the same name already exists, first check its schema, identifier fields, format-version, and the ownership of the historical data. Table creation properties apply only to new tables and do not automatically modify existing tables. If an existing table contains production data, use a separate demo destination table to avoid deleting or overwriting production data.

Step 3: Create and start the data ingestion job

1. Create a YAML draft

Go to Data Development > Data Ingestion, create a draft such as rds-postgres-to-dlf-iceberg, select VVR 11.9 or later, and enter the following 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_iceberg.orders_[0-9]+'
  slot.name: rds_pg_iceberg_demo
  decoding.plugin.name: pgoutput
  debezium.publication.name: rds_pg_iceberg_pub
  debezium.publication.autocreate.mode: disabled
  scan.startup.mode: initial
  schema-change.enabled: true

sink:
  type: iceberg
  name: DLF Iceberg Sink
  using.built-in-catalog: dlf_iceberg

route:
  - source-table: 'demo_iceberg.orders_[0-9]+'
    sink-table: default.orders

pipeline:
  name: RDS PostgreSQL to DLF Iceberg

Configuration description:

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

  • tables uses the three-part "database.schema.table" format, and one job can connect to only one database. route.source-table uses the "schema.table" format to merge the two source tables into default.orders.

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

  • slot.name specifies the replication slot created by the connector. Each job uses a separate replication slot, and one replication slot is 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 and keeps the publication scope limited to the two source tables.

  • using.built-in-catalog reuses the connection parameters of the dlf_iceberg catalog registered in Step 2.

  • The orderkey primary key of the source tables is used as the identifier fields of the destination table. This example creates a non-partitioned table.

  • The destination table must use Iceberg V2 format and have the correct identifier fields to support the update and delete operations in this example.

You can also configure the REST catalog connection parameters directly. In that case, replace the sink section of the preceding YAML with the following configuration:

sink:
  type: iceberg
  name: DLF Iceberg Sink
  catalog.properties.type: rest
  catalog.properties.uri: ${secret_values.dlf_uri}
  catalog.properties.warehouse: ${secret_values.dlf_catalog_name}
  catalog.properties.rest.signing-region: ${secret_values.dlf_region}
  catalog.properties.io-impl: org.apache.iceberg.rest.DlfFileIO

Choose either catalog reuse or direct configuration. Both require the preceding service role authorization, DLF data permissions, and network configuration.

2. Deploy and start the job

  1. Run a deep check to identify syntax, RDS network, DLF permission, and catalog configuration 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 observe the synchronization results more easily, you can set the system checkpoint interval and the minimum interval between two system checkpoints to 10s. In production environments, adjust the values based on throughput and resource usage.

  5. When you start the new job of this example for the first time, select Stateless Start to read full data and then continuously consume the WAL. When you restore an existing job, select a stateful start to preserve the processing progress.

  6. Wait until full synchronization completes, and confirm that the checkpoint succeeds and the Iceberg data commit completes before you query the destination data.

Note: Written data becomes visible after the Iceberg snapshot is committed. After a checkpoint succeeds, still check the commit logs and the destination query results to confirm that the data is committed.

3. Verify full data

In Data Development > Data Query, select batch mode and run the following queries:

SELECT orderkey, custkey, order_status, total_price
FROM `dlf_iceberg`.`default`.`orders`
ORDER BY orderkey;

SELECT COUNT(*) AS row_count, SUM(total_price) AS total_amount
FROM `dlf_iceberg`.`default`.`orders`;

SELECT orderkey, COUNT(*) AS cnt
FROM `dlf_iceberg`.`default`.`orders`
GROUP BY orderkey
HAVING COUNT(*) > 1;

Expected results: the primary keys are 1, 2, 3, 11, 12, 13, the total row count is 6, the total amount is 950.00, and the duplicate primary key query returns no rows.

Step 4: Verify inserts, updates, deletes, and schema changes

1. Verify INSERT, UPDATE, and DELETE

After you confirm that the full synchronization results meet expectations, run the following SQL once in the orders database of RDS:

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

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

DELETE FROM demo_iceberg.orders_2 WHERE orderkey = 11;

Wait for a successful commit, and then run the batch queries again:

SELECT orderkey, custkey, order_status, total_price
FROM `dlf_iceberg`.`default`.`orders`
ORDER BY orderkey;

SELECT COUNT(*) AS row_count, SUM(total_price) AS total_amount
FROM `dlf_iceberg`.`default`.`orders`;

SELECT orderkey, COUNT(*) AS cnt
FROM `dlf_iceberg`.`default`.`orders`
GROUP BY orderkey
HAVING COUNT(*) > 1;

Check item

Expected result

New order 4

Amount 50.00, with exactly one row

Updated order 2

Only the updated values are kept: status DONE, amount 220.00

Deleted order 11

No row

Total row count

6

Total amount

940.00, that is, 950 + 50 + 20 - 80

Duplicate primary keys

No result

If the query results contain leftover old values, duplicate primary keys, or deletes that did not take effect, check the format version, identifier fields, and write mode of the destination table, and troubleshoot with the commit logs. Append write mode does not apply to the update and delete scenarios in this example.

2. Verify a new column

Add a column with the same name to both source tables in RDS, and then run the updates:

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

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

Wait for the write commit, and then run the following query again in Flink:

SELECT orderkey, quantity
FROM `dlf_iceberg`.`default`.`orders`
WHERE quantity IS NOT NULL
ORDER BY orderkey;

Three rows should be returned: (1,100), (2,100), (12,200). The other orders that were not updated are not automatically backfilled with a quantity because of the new column.

This example verifies new column synchronization. The schema change policy used by the job must allow add-column events. Dropping a physical column, DROP, TRUNCATE, and primary key changes are outside the scope of this example. Schema change synchronization must meet the requirements of both PostgreSQL source capture and Iceberg destination processing.

FAQ

Symptom

Troubleshooting

RDS connection or replication failure

Check the internal network, whitelist, database name, synchronization account, logical replication parameters, publication scope, and replication slot capacity.

DLF 401/403 errors or insufficient permissions

Check the API and data permissions of the job service role, the authorization of the destination catalog, and the VPC trust list.

Catalog not found

Distinguish the actual DLF catalog from the Flink catalog name. Confirm that warehouse is set to the DLF catalog name and that the regions match.

Checkpoints succeed but new data is not visible

Check the Iceberg snapshot commit status and the error logs, and then run the query again.

Duplicates after updates or deletes that do not take effect

Check the format version and identifier fields of the destination table, and the write mode of the connector.

Validation failure on an existing destination table

Verify and back up the schema and data of the existing table, and use a new demo destination table if necessary.

New column not synchronized

Check the VVR version, pgoutput, schema-change.enabled, data changes after the DDL, schema synchronization of both sources, and the destination commit status.

Important: When multiple source tables are merged into the same destination table, the primary keys must be unique across the tables. The same primary key in different source tables can cause records to be overwritten or deleted by mistake. Iceberg identifier fields do not enforce database-style uniqueness constraints, so multiple write jobs must jointly ensure consistent primary keys and write semantics.

The synchronization scope of this example covers the two tables that exist when the job starts. When you adjust the scope, also check the table matching configuration and the publication scope, and confirm how the historical data of newly added tables is read. A table matching expression does not automatically extend a manually created publication.

Clean up resources

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

  2. After you confirm that the jobs are no longer used and do not need to be restored, and that the replication slot is not occupied, run the following SQL to clean up the replication slot and publication of this example:

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

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

DROP PUBLICATION rds_pg_iceberg_pub;
  1. Keeping a replication slot after consumption stops can cause WAL accumulation. Continue to monitor RDS disk usage. Keep the replication slots and publications that other jobs still use.

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

Note: DLF, managed storage, RDS, and Flink resources are billed according to the billing rules of each service. After you finish, check the resource status and release the dedicated resources that are no longer used in time.

References