MCPcopy Create free account
hub / github.com/apache/cloudberry / execute_extension_script

Function execute_extension_script

src/backend/commands/extension.c:870–1159  ·  view source on GitHub ↗

* Execute the appropriate script file for installing or updating the extension * * If from_version isn't NULL, it's an update * * If stmt isn't NULL, it means that there already has been a Gang of type GANGTYPE_PRIMARY_WRITER, * and the BEGIN phase of stmt has been executed in every QE in this Gang. */

Source from the content-addressed store, hash-verified

868 * and the BEGIN phase of stmt has been executed in every QE in this Gang.
869 */
870static void
871execute_extension_script(Node *stmt,
872 Oid extensionOid, ExtensionControlFile *control,
873 const char *from_version,
874 const char *version,
875 List *requiredSchemas,
876 const char *schemaName, Oid schemaOid)
877{
878 bool switch_to_superuser = false;
879 char *filename;
880 Oid save_userid = 0;
881 int save_sec_context = 0;
882 int save_nestlevel;
883 StringInfoData pathbuf;
884 ListCell *lc;
885 StringInfoData search_path_buffer;
886
887 AssertState(Gp_role != GP_ROLE_EXECUTE);
888 AssertImply(Gp_role == GP_ROLE_DISPATCH, stmt != NULL &&
889 (nodeTag(stmt) == T_CreateExtensionStmt || nodeTag(stmt) == T_AlterExtensionStmt) &&
890 is_begin_state(stmt));
891
892 /*
893 * Enforce superuser-ness if appropriate. We postpone these checks until
894 * here so that the control flags are correctly associated with the right
895 * script(s) if they happen to be set in secondary control files.
896 */
897 if (control->superuser && !superuser())
898 {
899 if (extension_is_trusted(control))
900 switch_to_superuser = true;
901 else if (from_version == NULL)
902 ereport(ERROR,
903 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
904 errmsg("permission denied to create extension \"%s\"",
905 control->name),
906 control->trusted
907 ? errhint("Must have CREATE privilege on current database to create this extension.")
908 : errhint("Must be superuser to create this extension.")));
909 else
910 ereport(ERROR,
911 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
912 errmsg("permission denied to update extension \"%s\"",
913 control->name),
914 control->trusted
915 ? errhint("Must have CREATE privilege on current database to update this extension.")
916 : errhint("Must be superuser to update this extension.")));
917 }
918
919 filename = get_extension_script_filename(control, from_version, version);
920
921 /*
922 * If installing a trusted extension on behalf of a non-superuser, become
923 * the bootstrap superuser. (This switch will be cleaned up automatically
924 * if the transaction aborts, as will the GUC changes below.)
925 */
926 if (switch_to_superuser)
927 {

Callers 2

CreateExtensionInternalFunction · 0.85
ApplyExtensionUpdatesFunction · 0.85

Calls 15

is_begin_stateFunction · 0.85
superuserFunction · 0.85
extension_is_trustedFunction · 0.85
GetUserIdAndSecContextFunction · 0.85
SetUserIdAndSecContextFunction · 0.85
NewGUCNestLevelFunction · 0.85
set_config_optionFunction · 0.85
initStringInfoFunction · 0.85
appendStringInfoStringFunction · 0.85
get_namespace_nameFunction · 0.85
appendStringInfoFunction · 0.85

Tested by

no test coverage detected