jackc / pglogrepl

PostgreSQL logical replication library for Go.
MIT License
319 stars 59 forks source link

For update message, the OldTuple is nil #38

Closed zhanghaiyang9999 closed 1 year ago

zhanghaiyang9999 commented 1 year ago

I used the example code to test the logic replication, Insert and Delete operations are good, but the Update operation is incorrect, the OldTuple is nil for the Update event. @jackc BTW: the test table has primary key. image

JordanP commented 1 year ago

Could you try setting ALTER TABLE mytable REPLICA IDENTITY FULL; ? You should understand the impact before doing that in prod though.

zhanghaiyang9999 commented 1 year ago

@JordanP Thanks, if I executed the sql "ALTER TABLE mytable REPLICA IDENTITY FULL", the OldTuple is not nil, But my test table has primary key, I think the identify FULL just for the table that has not the primary key case.

JordanP commented 1 year ago

@zhanghaiyang9999 not exactly. This page says

In the case of DEFAULT, old tuple data is only identified with the primary key of the table. This data is written into WAL only when at least one column of the primary key is updated. Columns that are not part of the primary key do not have their old value written.

Whereas with FULL:

In the case of FULL, all the column values are written to WAL all the time. This is the most verbose, and as well the most resource-consuming mode. Be careful here particularly for heavily-updated tables.
zhanghaiyang9999 commented 1 year ago

Thanks @JordanP for the detail. I have another issue, the pglogrepl can't capture one of my test tables changes such as insert, update and delete. but all the other test tables worked well, except this one table. I can't confirm this is the pglogrepl issue or the postgresql issue.