diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c index ca53caac2f2f..178a07af7d40 100644 --- a/src/backend/replication/logical/logicalfuncs.c +++ b/src/backend/replication/logical/logicalfuncs.c @@ -113,6 +113,8 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin List *options = NIL; DecodingOutputState *p; + CheckSlotIsInSingleUserMode(); + CheckSlotPermissions(); CheckLogicalDecodingRequirements(); diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 600b87fa9cb6..ce17ff0edbcb 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1442,6 +1442,18 @@ CheckSlotPermissions(void) "REPLICATION"))); } +/* + * Check whether the instance is in single-user mode. + */ +void +CheckSlotIsInSingleUserMode(void) +{ + if (!IsUnderPostmaster) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("replication slots cannot be used in single-user mode"))); +} + /* * Reserve WAL for the currently active slot. * diff --git a/src/backend/replication/slotfuncs.c b/src/backend/replication/slotfuncs.c index 36cc2ed4e440..c02866aaa6d3 100644 --- a/src/backend/replication/slotfuncs.c +++ b/src/backend/replication/slotfuncs.c @@ -17,6 +17,7 @@ #include "access/xlogrecovery.h" #include "access/xlogutils.h" #include "funcapi.h" +#include "miscadmin.h" #include "replication/logical.h" #include "replication/slot.h" #include "replication/slotsync.h" @@ -76,6 +77,8 @@ pg_create_physical_replication_slot(PG_FUNCTION_ARGS) if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); + CheckSlotIsInSingleUserMode(); + CheckSlotPermissions(); CheckSlotRequirements(); @@ -182,6 +185,8 @@ pg_create_logical_replication_slot(PG_FUNCTION_ARGS) if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); + CheckSlotIsInSingleUserMode(); + CheckSlotPermissions(); CheckLogicalDecodingRequirements(); @@ -521,6 +526,8 @@ pg_replication_slot_advance(PG_FUNCTION_ARGS) Assert(!MyReplicationSlot); + CheckSlotIsInSingleUserMode(); + CheckSlotPermissions(); if (XLogRecPtrIsInvalid(moveto)) @@ -618,9 +625,12 @@ copy_replication_slot(FunctionCallInfo fcinfo, bool logical_slot) TupleDesc tupdesc; HeapTuple tuple; + if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "return type must be a row type"); + CheckSlotIsInSingleUserMode(); + CheckSlotPermissions(); if (logical_slot) @@ -898,6 +908,8 @@ pg_sync_replication_slots(PG_FUNCTION_ARGS) char *err; StringInfoData app_name; + CheckSlotIsInSingleUserMode(); + CheckSlotPermissions(); if (!RecoveryInProgress()) diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index eb0b93b11141..079d82b7aabf 100644 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -306,6 +306,7 @@ extern void CheckPointReplicationSlots(bool is_shutdown); extern void CheckSlotRequirements(void); extern void CheckSlotPermissions(void); +extern void CheckSlotIsInSingleUserMode(void); extern ReplicationSlotInvalidationCause GetSlotInvalidationCause(const char *cause_name); extern const char *GetSlotInvalidationCauseName(ReplicationSlotInvalidationCause cause);