pgsql: Fix xmin advancement during fast_forward decoding. - Mailing list pgsql-committers

From Amit Kapila
Subject pgsql: Fix xmin advancement during fast_forward decoding.
Date
Msg-id E1u9I5V-00291P-0e@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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 <amit.kapila16@gmail.com>
Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Backpatch-through: 13
Discussion: https://postgr.es/m/CAA4eK1LqWncUOqKijiafe+Ypt1gQAQRjctKLMY953J79xDBgAg@mail.gmail.com
Discussion: https://postgr.es/m/OS0PR01MB57163087F86621D44D9A72BF94BB2@OS0PR01MB5716.jpnprd01.prod.outlook.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d65485b02b1f476cc14eb6f7a1cb29cd8fd0009f

Modified Files
--------------
contrib/test_decoding/expected/oldest_xmin.out | 41 ++++++++++++++++++++++++++
contrib/test_decoding/specs/oldest_xmin.spec   |  5 ++++
src/backend/replication/logical/decode.c       | 38 ++++++++++++++++--------
3 files changed, 71 insertions(+), 13 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Remove circular #include's between wait_event.h and wait_event_t
Next
From: Alexander Korotkov
Date:
Subject: pgsql: Restore comments in ChangeVarNodesExtended()