Fix xmin advancement during fast_forward decoding.
authorAmit Kapila <[email protected]>
Mon, 28 Apr 2025 05:04:45 +0000 (10:34 +0530)
committerAmit Kapila <[email protected]>
Mon, 28 Apr 2025 05:04:45 +0000 (10:34 +0530)
commit1f63b3626a52e596398c7a04a42081a773b12d76
tree49ea656afdf3a4bace8f37169193160617fbb933
parentbb1bc9fa962ed72a521ee129c20c089f9d507f97
Fix xmin advancement during fast_forward decoding.

During logical decoding, we advance catalog_xmin of logical too early in
fast_forward mode, resulting in required catalog data being removed by
vacuum. This mode is normally used to advance the slot without processing
the changes, but we still can't let the slot's xmin to advance to an
incorrect value.

Commit f49a80c481 fixed a similar issue where the logical slot's
catalog_xmin was getting advanced prematurely during non-fast-forward
mode. During xl_running_xacts processing, instead of directly advancing
the slot's xmin to the oldest running xid in the record, it allowed the
xmin to be held back for snapshots that can be used for
not-yet-replayed transactions, as those might consider older txns as
running too. However, it missed the fact that the same problem can happen
during fast_forward mode decoding, as we won't build a base snapshot in
that mode, and the future call to get_changes from the same slot can miss
seeing the required catalog changes leading to incorrect reslts.

This commit allows building the base snapshot even in fast_forward mode to
prevent the early advancement of xmin.

Reported-by: Amit Kapila <[email protected]>
Author: Zhijie Hou <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: shveta malik <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Backpatch-through: 13
Discussion: https://postgr.es/m/CAA4eK1LqWncUOqKijiafe+Ypt1gQAQRjctKLMY953J79xDBgAg@mail.gmail.com
Discussion: https://postgr.es/m/OS0PR01MB57163087F86621D44D9A72BF94BB2@OS0PR01MB5716.jpnprd01.prod.outlook.com
contrib/test_decoding/expected/oldest_xmin.out
contrib/test_decoding/specs/oldest_xmin.spec
src/backend/replication/logical/decode.c