PostgreSQL offline synchronization

This article provides implementation ideas, configuration examples, and verification methods for PostgreSQL offline synchronization scenarios, which can be used as a reference for actual project configuration.

Implement offline synchronization of data from the result table to the target table in PostgreSQL

Case

Offline synchronization of data in t_source to t_target in PostgreSQL

solution

Create a Flink SQL job type and add the following dependencies

20250120164839

CREATE TABLE from_table
(
    username STRING,
    age      INT
) WITH (
      'connector' = 'jdbc',
      'url' = 'jdbc:postgresql://localhost:54302/isxcode_db',
      'driver' = 'org.postgresql.Driver',
      'table-name' = 't_source',
      'username' = 'root',
      'password' = 'root123',
      'scan.fetch-size' = '1'
      );

CREATE TABLE target_table
(
    username STRING,
    age      INT
) WITH (
      'connector' = 'jdbc',
      'url' = 'jdbc:postgresql://localhost:54302/isxcode_db',
      'driver' = 'org.postgresql.Driver',
      'table-name' = 't_sink',
      'username' = 'root',
      'password' = 'root123',
      'sink.buffer-flush.max-rows' = '1');

INSERT INTO target_table
select *
from from_table;
Configuration itemsDescription
connectorConnection method
urlDatabase connection url
driverData source driven
table-nametable name
usernameData source account
passwordAccount password
scan.fetch-sizeHow much data does each operation
sink.buffer-flush.max-rowsHow many pieces of data are merged into one transaction?