aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/worker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/replication/logical/worker.c')
-rw-r--r--src/backend/replication/logical/worker.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index ef2a6beb361..61009fa8cda 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -207,6 +207,7 @@
#include "utils/rls.h"
#include "utils/syscache.h"
#include "utils/timeout.h"
+#include "utils/usercontext.h"
#define NAPTIME_PER_CYCLE 1000 /* max sleep time between cycles (1s) */
@@ -2395,6 +2396,7 @@ apply_handle_insert(StringInfo s)
LogicalRepRelMapEntry *rel;
LogicalRepTupleData newtup;
LogicalRepRelId relid;
+ UserContext ucxt;
ApplyExecutionData *edata;
EState *estate;
TupleTableSlot *remoteslot;
@@ -2423,6 +2425,9 @@ apply_handle_insert(StringInfo s)
return;
}
+ /* Make sure that any user-supplied code runs as the table owner. */
+ SwitchToUntrustedUser(rel->localrel->rd_rel->relowner, &ucxt);
+
/* Set relation for error callback */
apply_error_callback_arg.rel = rel;
@@ -2452,6 +2457,8 @@ apply_handle_insert(StringInfo s)
/* Reset relation for error callback */
apply_error_callback_arg.rel = NULL;
+ RestoreUserContext(&ucxt);
+
logicalrep_rel_close(rel, NoLock);
end_replication_step();
@@ -2530,6 +2537,7 @@ apply_handle_update(StringInfo s)
{
LogicalRepRelMapEntry *rel;
LogicalRepRelId relid;
+ UserContext ucxt;
ApplyExecutionData *edata;
EState *estate;
LogicalRepTupleData oldtup;
@@ -2569,6 +2577,9 @@ apply_handle_update(StringInfo s)
/* Check if we can do the update. */
check_relation_updatable(rel);
+ /* Make sure that any user-supplied code runs as the table owner. */
+ SwitchToUntrustedUser(rel->localrel->rd_rel->relowner, &ucxt);
+
/* Initialize the executor state. */
edata = create_edata_for_relation(rel);
estate = edata->estate;
@@ -2619,6 +2630,8 @@ apply_handle_update(StringInfo s)
/* Reset relation for error callback */
apply_error_callback_arg.rel = NULL;
+ RestoreUserContext(&ucxt);
+
logicalrep_rel_close(rel, NoLock);
end_replication_step();
@@ -2702,6 +2715,7 @@ apply_handle_delete(StringInfo s)
LogicalRepRelMapEntry *rel;
LogicalRepTupleData oldtup;
LogicalRepRelId relid;
+ UserContext ucxt;
ApplyExecutionData *edata;
EState *estate;
TupleTableSlot *remoteslot;
@@ -2736,6 +2750,9 @@ apply_handle_delete(StringInfo s)
/* Check if we can do the delete. */
check_relation_updatable(rel);
+ /* Make sure that any user-supplied code runs as the table owner. */
+ SwitchToUntrustedUser(rel->localrel->rd_rel->relowner, &ucxt);
+
/* Initialize the executor state. */
edata = create_edata_for_relation(rel);
estate = edata->estate;
@@ -2761,6 +2778,8 @@ apply_handle_delete(StringInfo s)
/* Reset relation for error callback */
apply_error_callback_arg.rel = NULL;
+ RestoreUserContext(&ucxt);
+
logicalrep_rel_close(rel, NoLock);
end_replication_step();
@@ -3211,7 +3230,8 @@ apply_handle_truncate(StringInfo s)
relids,
relids_logged,
DROP_RESTRICT,
- restart_seqs);
+ restart_seqs,
+ true);
foreach(lc, remote_rels)
{
LogicalRepRelMapEntry *rel = lfirst(lc);