aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/logical.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-04-07 22:19:05 -0700
committerAndres Freund <andres@anarazel.de>2023-04-07 22:19:05 -0700
commit4397abd0a2af955326c0608d63f3716ce5901004 (patch)
treeed9a7a022b746da014567065db69e66e8a88edae /src/backend/replication/logical/logical.c
parent15f8203a5975d6b9b78e2c64e213ed964b50c044 (diff)
downloadpostgresql-4397abd0a2af955326c0608d63f3716ce5901004.tar.gz
postgresql-4397abd0a2af955326c0608d63f3716ce5901004.zip
Prevent use of invalidated logical slot in CreateDecodingContext()
Previously we had checks for this in multiple places. Support for logical decoding on standbys will add other forms of invalidation, making it worth while to centralize the checks. This slightly changes the error message for both the walsender and SQL interface. Particularly the SQL interface error was inaccurate, as the "This slot has never previously reserved WAL" portion was unreachable. Reviewed-by: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com> Reviewed-by: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://postgr.es/m/20230407075009.igg7be27ha2htkbt@awork3.anarazel.de
Diffstat (limited to 'src/backend/replication/logical/logical.c')
-rw-r--r--src/backend/replication/logical/logical.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index c3ec97a0a62..6082d222d5d 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -518,6 +518,22 @@ CreateDecodingContext(XLogRecPtr start_lsn,
errmsg("replication slot \"%s\" was not created in this database",
NameStr(slot->data.name))));
+ /*
+ * Check if slot has been invalidated due to max_slot_wal_keep_size. Avoid
+ * "cannot get changes" wording in this errmsg because that'd be
+ * confusingly ambiguous about no changes being available when called from
+ * pg_logical_slot_get_changes_guts().
+ */
+ if (MyReplicationSlot->data.invalidated == RS_INVAL_WAL_REMOVED)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("can no longer get changes from replication slot \"%s\"",
+ NameStr(MyReplicationSlot->data.name)),
+ errdetail("This slot has been invalidated because it exceeded the maximum reserved size.")));
+
+ Assert(MyReplicationSlot->data.invalidated == RS_INVAL_NONE);
+ Assert(MyReplicationSlot->data.restart_lsn != InvalidXLogRecPtr);
+
if (start_lsn == InvalidXLogRecPtr)
{
/* continue from last position */