Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit174952e

Browse files
Fix assertion when decoding XLOG_PARAMETER_CHANGE on promoted primary.
When a standby replays an XLOG_PARAMETER_CHANGE record that lowerswal_level below logical, we invalidate all logical slots in hotstandby mode. However, if this record was replayed while not in hotstandby 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 statuswhen restoring a logical replication slot on standbys. This checkensures that logical slots are invalidated when they becomeincompatible due to insufficient wal_level during recovery.Backpatch to v16 where logical decoding on standby was introduced.Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>Discussion:https://postgr.es/m/CAD21AoABoFwGY_Rh2aeE6tEq3HkJxf0c6UeOXn4VV9v6BAQPSw%40mail.gmail.comBackpatch-through: 16
1 parentfde7c01 commit174952e

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

‎src/backend/replication/slot.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,12 +2327,29 @@ RestoreSlotFromDisk(const char *name)
23272327
* NB: Changing the requirements here also requires adapting
23282328
* CheckSlotRequirements() and CheckLogicalDecodingRequirements().
23292329
*/
2330-
if (cp.slotdata.database!=InvalidOid&&wal_level<WAL_LEVEL_LOGICAL)
2331-
ereport(FATAL,
2332-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2333-
errmsg("logical replication slot \"%s\" exists, but \"wal_level\" < \"logical\"",
2334-
NameStr(cp.slotdata.name)),
2335-
errhint("Change \"wal_level\" to be \"logical\" or higher.")));
2330+
if (cp.slotdata.database!=InvalidOid)
2331+
{
2332+
if (wal_level<WAL_LEVEL_LOGICAL)
2333+
ereport(FATAL,
2334+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2335+
errmsg("logical replication slot \"%s\" exists, but \"wal_level\" < \"logical\"",
2336+
NameStr(cp.slotdata.name)),
2337+
errhint("Change \"wal_level\" to be \"logical\" or higher.")));
2338+
2339+
/*
2340+
* In standby mode, the hot standby must be enabled. This check is
2341+
* necessary to ensure logical slots are invalidated when they become
2342+
* incompatible due to insufficient wal_level. Otherwise, if the
2343+
* primary reduces wal_level < logical while hot standby is disabled,
2344+
* logical slots would remain valid even after promotion.
2345+
*/
2346+
if (StandbyMode&& !EnableHotStandby)
2347+
ereport(FATAL,
2348+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2349+
errmsg("logical replication slot \"%s\" exists on the standby, but \"hot_standby\" = \"off\"",
2350+
NameStr(cp.slotdata.name)),
2351+
errhint("Change \"hot_standby\" to be \"on\".")));
2352+
}
23362353
elseif (wal_level<WAL_LEVEL_REPLICA)
23372354
ereport(FATAL,
23382355
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

‎src/test/recovery/t/035_standby_logical_decoding.pl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,44 @@ sub wait_until_vacuum_can_remove
345345
\$psql_subscriber{subscriber_stderr},
346346
IPC::Run::timeout($default_timeout));
347347

348+
##################################################
349+
# Test that the standby requires hot_standby to be
350+
# enabled for pre-existing logical slots.
351+
##################################################
352+
353+
# create the logical slots
354+
$node_standby->create_logical_slot_on_standby($node_primary,'restart_test');
355+
$node_standby->stop;
356+
$node_standby->append_conf('postgresql.conf',qq[hot_standby = off]);
357+
358+
# Use run_log instead of $node_standby->start because this test expects
359+
# that the server ends with an error during startup.
360+
run_log(
361+
[
362+
'pg_ctl',
363+
'--pgdata'=>$node_standby->data_dir,
364+
'--log'=>$node_standby->logfile,
365+
'start',
366+
]);
367+
368+
# wait for postgres to terminate
369+
foreachmy$i (0 .. 10 *$PostgreSQL::Test::Utils::timeout_default)
370+
{
371+
lastif !-f$node_standby->data_dir .'/postmaster.pid';
372+
usleep(100_000);
373+
}
374+
375+
# Confirm that the server startup fails with an expected error
376+
my$logfile = slurp_file($node_standby->logfile());
377+
ok($logfile =~
378+
qr/FATAL: .* logical replication slot ".*" exists on the standby, but "hot_standby" = "off"/,
379+
"the standby ends with an error during startup because hot_standby was disabled"
380+
);
381+
$node_standby->adjust_conf('postgresql.conf','hot_standby','on');
382+
$node_standby->start;
383+
$node_standby->safe_psql('postgres',
384+
qq[SELECT pg_drop_replication_slot('restart_test')]);
385+
348386
##################################################
349387
# Test that logical decoding on the standby
350388
# behaves correctly.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp