pgsql: Fix assertion when decoding XLOG_PARAMETER_CHANGE on promoted pr

From: Masahiko Sawada <msawada(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix assertion when decoding XLOG_PARAMETER_CHANGE on promoted pr
Date: 2025-02-24 22:04:23
Message-ID: E1tmgYp-000WBF-0E@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix assertion when decoding XLOG_PARAMETER_CHANGE on promoted primary.

When a standby replays an XLOG_PARAMETER_CHANGE record that lowers
wal_level below logical, we invalidate all logical slots in hot
standby mode. However, if this record was replayed while not in hot
standby mode, logical slots could remain valid even after promotion,
potentially causing an assertion failure during WAL record decoding.

To fix this issue, this commit adds a check for hot_standby status
when restoring a logical replication slot on standbys. This check
ensures that logical slots are invalidated when they become
incompatible due to insufficient wal_level during recovery.

Backpatch to v16 where logical decoding on standby was introduced.

Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAD21AoABoFwGY_Rh2aeE6tEq3HkJxf0c6UeOXn4VV9v6BAQPSw%40mail.gmail.com
Backpatch-through: 16

Branch
------
REL_16_STABLE

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

Modified Files
--------------
src/backend/replication/slot.c | 29 +++++++++++++----
.../recovery/t/035_standby_logical_decoding.pl | 38 ++++++++++++++++++++++
2 files changed, 61 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Masahiko Sawada 2025-02-24 22:04:27 pgsql: Fix assertion when decoding XLOG_PARAMETER_CHANGE on promoted pr
Previous Message Masahiko Sawada 2025-02-24 22:04:19 pgsql: Fix assertion when decoding XLOG_PARAMETER_CHANGE on promoted pr