From 6db46eed2c2d99beb1defc4470c598cfe796cb3a Mon Sep 17 00:00:00 2001 From: Hou Zhijie Date: Wed, 6 Dec 2023 11:38:00 +0800 Subject: [PATCH] Forbid the use of invalidated slot in streaming replication --- src/backend/replication/walsender.c | 9 +++++++++ src/test/recovery/t/019_replslot_limit.pl | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 3bc9c82389..53073dddaa 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -703,6 +703,15 @@ StartReplication(StartReplicationCmd *cmd) (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot use a logical replication slot for physical replication"))); + if (MyReplicationSlot->data.invalidated == RS_INVAL_WAL_REMOVED) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("cannot use replication slot \"%s\" for physical replication", + NameStr(MyReplicationSlot->data.name)), + errdetail("This slot has been invalidated because it exceeded the maximum reserved size."))); + + Assert(MyReplicationSlot->data.invalidated == RS_INVAL_NONE); + /* * We don't need to verify the slot's restart_lsn here; instead we * rely on the caller requesting the starting point to use. If the diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl index 7d94f15778..7c350e86f7 100644 --- a/src/test/recovery/t/019_replslot_limit.pl +++ b/src/test/recovery/t/019_replslot_limit.pl @@ -236,7 +236,7 @@ my $failed = 0; for (my $i = 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i++) { if ($node_standby->log_contains( - "requested WAL segment [0-9A-F]+ has already been removed", + "cannot use replication slot \"rep1\" for physical replication", $logstart)) { $failed = 1; -- 2.31.1