Skip to content

fix: PG CDC failed when encountering changes in PK and UK during the pullback#476

Merged
caiq1nyu merged 3 commits intomainfrom
fix/pg_cdc_pullback_pkuk_changes
Mar 23, 2026
Merged

fix: PG CDC failed when encountering changes in PK and UK during the pullback#476
caiq1nyu merged 3 commits intomainfrom
fix/pg_cdc_pullback_pkuk_changes

Conversation

@caiq1nyu
Copy link
Copy Markdown
Collaborator

fix issues such as the following scenarios:

// source
CREATE TABLE sgiprod.ggbridgeritem (
    bridgeritemid    varchar(21) NOT NULL,
    entitytype       varchar(10),
    entityno         varchar(100),

    CONSTRAINT ggbridgeritem_pkey PRIMARY KEY (bridgeritemid),
    CONSTRAINT uk_ggbridgeritem_businesstype_no UNIQUE (entitytype, entityno)
);

-- LSN: 0001
INSERT INTO fortest.test1 VALUES ('PK1','A','NO1');
INSERT INTO fortest.test1 VALUES ('PK2','B','NO2');
UPDATE fortest.test1 SET entitytype='C', entityno='TEMP' where bridgeritemid='PK1'; 
UPDATE fortest.test1 SET entitytype='A', entityno='NO1' where bridgeritemid='PK2';
UPDATE fortest.test1 SET entitytype='B', entityno='NO2' where bridgeritemid='PK1';
-- LSN: 0002

// target
-- The data is in LSN:0002 state, and CDC is pulled back to LSN:0001.
-- origin sql will be like:
INSERT INTO fortest.test1 VALUES ('PK1','LOG1','A','NO1') ON CONFLICT(bridgeritemid) UPDATE SET entitytype='A', entityno='NO1';
-- which will cause duplicate key value violates unique constraint error

In the current design, this scenario is likely to occur when performing a full load plus an incremental load. This PR will fix it.

@caiq1nyu caiq1nyu merged commit c6a3ebd into main Mar 23, 2026
2 checks passed
@caiq1nyu caiq1nyu deleted the fix/pg_cdc_pullback_pkuk_changes branch March 23, 2026 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant