Run copy commands in worker_merge_files_into_table as superuser

pull/1049/head
Marco Slot 2016-12-16 12:05:08 +01:00
parent 42ff472721
commit dd094bc372
1 changed files with 9 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "catalog/pg_namespace.h"
#include "commands/copy.h"
#include "commands/tablecmds.h"
#include "distributed/metadata_cache.h"
#include "distributed/worker_protocol.h"
#include "executor/spi.h"
#include "nodes/makefuncs.h"
@ -74,6 +75,8 @@ worker_merge_files_into_table(PG_FUNCTION_ARGS)
bool schemaExists = false;
List *columnNameList = NIL;
List *columnTypeList = NIL;
Oid savedUserId = InvalidOid;
int savedSecurityContext = 0;
/* we should have the same number of column names and types */
int32 columnNameCount = ArrayObjectCount(columnNameObject);
@ -101,8 +104,14 @@ worker_merge_files_into_table(PG_FUNCTION_ARGS)
CreateTaskTable(jobSchemaName, taskTableName, columnNameList, columnTypeList);
/* need superuser to copy from files */
GetUserIdAndSecContext(&savedUserId, &savedSecurityContext);
SetUserIdAndSecContext(CitusExtensionOwner(), SECURITY_LOCAL_USERID_CHANGE);
CopyTaskFilesFromDirectory(jobSchemaName, taskTableName, taskDirectoryName);
SetUserIdAndSecContext(savedUserId, savedSecurityContext);
PG_RETURN_VOID();
}