PostgreSQL Source Code git master
Loading...
Searching...
No Matches
extension.h File Reference
Include dependency graph for extension.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ObjectAddress CreateExtension (ParseState *pstate, CreateExtensionStmt *stmt)
 
void RemoveExtensionById (Oid extId)
 
ObjectAddress InsertExtensionTuple (const char *extName, Oid extOwner, Oid schemaOid, bool relocatable, const char *extVersion, Datum extConfig, Datum extCondition, List *requiredExtensions)
 
ObjectAddress ExecAlterExtensionStmt (ParseState *pstate, AlterExtensionStmt *stmt)
 
ObjectAddress ExecAlterExtensionContentsStmt (AlterExtensionContentsStmt *stmt, ObjectAddress *objAddr)
 
Oid get_extension_oid (const char *extname, bool missing_ok)
 
charget_extension_name (Oid ext_oid)
 
Oid get_extension_schema (Oid ext_oid)
 
bool extension_file_exists (const char *extensionName)
 
ObjectAddress AlterExtensionNamespace (const char *extensionName, const char *newschema, Oid *oldschema)
 

Variables

PGDLLIMPORT charExtension_control_path
 
PGDLLIMPORT bool creating_extension
 
PGDLLIMPORT Oid CurrentExtensionObject
 

Function Documentation

◆ AlterExtensionNamespace()

ObjectAddress AlterExtensionNamespace ( const char extensionName,
const char newschema,
Oid oldschema 
)
extern

Definition at line 3122 of file extension.c.

3123{
3125 Oid nspOid;
3126 Oid oldNspOid;
3129 ScanKeyData key[2];
3138
3140
3141 nspOid = LookupCreationNamespace(newschema);
3142
3143 /*
3144 * Permission check: must own extension. Note that we don't bother to
3145 * check ownership of the individual member objects ...
3146 */
3150
3151 /* Permission check: must have creation rights in target namespace */
3153 if (aclresult != ACLCHECK_OK)
3155
3156 /*
3157 * If the schema is currently a member of the extension, disallow moving
3158 * the extension into the schema. That would create a dependency loop.
3159 */
3161 ereport(ERROR,
3163 errmsg("cannot move extension \"%s\" into schema \"%s\" "
3164 "because the extension contains the schema",
3165 extensionName, newschema)));
3166
3167 /* Locate the pg_extension tuple */
3169
3170 ScanKeyInit(&key[0],
3174
3176 NULL, 1, key);
3177
3179
3180 if (!HeapTupleIsValid(extTup)) /* should not happen */
3181 elog(ERROR, "could not find tuple for extension %u",
3182 extensionOid);
3183
3184 /* Copy tuple so we can modify it below */
3187
3189
3190 /*
3191 * If the extension is already in the target schema, just silently do
3192 * nothing.
3193 */
3194 if (extForm->extnamespace == nspOid)
3195 {
3197 return InvalidObjectAddress;
3198 }
3199
3200 /* Check extension is supposed to be relocatable */
3201 if (!extForm->extrelocatable)
3202 ereport(ERROR,
3204 errmsg("extension \"%s\" does not support SET SCHEMA",
3205 NameStr(extForm->extname))));
3206
3208
3209 /* store the OID of the namespace to-be-changed */
3210 oldNspOid = extForm->extnamespace;
3211
3212 /*
3213 * Scan pg_depend to find objects that depend directly on the extension,
3214 * and alter each one's schema.
3215 */
3217
3218 ScanKeyInit(&key[0],
3222 ScanKeyInit(&key[1],
3226
3228 NULL, 2, key);
3229
3231 {
3235
3236 /*
3237 * If a dependent extension has a no_relocate request for this
3238 * extension, disallow SET SCHEMA. (XXX it's a bit ugly to do this in
3239 * the same loop that's actually executing the renames: we may detect
3240 * the error condition only after having expended a fair amount of
3241 * work. However, the alternative is to do two scans of pg_depend,
3242 * which seems like optimizing for failure cases. The rename work
3243 * will all roll back cleanly enough if we do fail here.)
3244 */
3245 if (pg_depend->deptype == DEPENDENCY_NORMAL &&
3246 pg_depend->classid == ExtensionRelationId)
3247 {
3248 char *depextname = get_extension_name(pg_depend->objid);
3250 ListCell *lc;
3251
3253 foreach(lc, dcontrol->no_relocate)
3254 {
3255 char *nrextname = (char *) lfirst(lc);
3256
3257 if (strcmp(nrextname, NameStr(extForm->extname)) == 0)
3258 {
3259 ereport(ERROR,
3261 errmsg("cannot SET SCHEMA of extension \"%s\" because other extensions prevent it",
3262 NameStr(extForm->extname)),
3263 errdetail("Extension \"%s\" requests no relocation of extension \"%s\".",
3264 depextname,
3265 NameStr(extForm->extname))));
3266 }
3267 }
3268 }
3269
3270 /*
3271 * Otherwise, ignore non-membership dependencies. (Currently, the
3272 * only other case we could see here is a normal dependency from
3273 * another extension.)
3274 */
3275 if (pg_depend->deptype != DEPENDENCY_EXTENSION)
3276 continue;
3277
3278 dep.classId = pg_depend->classid;
3279 dep.objectId = pg_depend->objid;
3280 dep.objectSubId = pg_depend->objsubid;
3281
3282 if (dep.objectSubId != 0) /* should not happen */
3283 elog(ERROR, "extension should not have a sub-object dependency");
3284
3285 /* Relocate the object */
3287 dep.objectId,
3288 nspOid,
3289 objsMoved);
3290
3291 /*
3292 * If not all the objects had the same old namespace (ignoring any
3293 * that are not in namespaces or are dependent types), complain.
3294 */
3296 ereport(ERROR,
3298 errmsg("extension \"%s\" does not support SET SCHEMA",
3299 NameStr(extForm->extname)),
3300 errdetail("%s is not in the extension's schema \"%s\"",
3301 getObjectDescription(&dep, false),
3303 }
3304
3305 /* report old schema, if caller wants it */
3306 if (oldschema)
3308
3310
3312
3313 /* Now adjust pg_extension.extnamespace */
3314 extForm->extnamespace = nspOid;
3315
3317
3319
3320 /* update dependency to point to the new schema */
3323 elog(ERROR, "could not change schema dependency for extension %s",
3324 NameStr(extForm->extname));
3325
3327
3329
3330 return extAddr;
3331}
AclResult
Definition acl.h:182
@ ACLCHECK_OK
Definition acl.h:183
@ ACLCHECK_NOT_OWNER
Definition acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3836
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition aclchk.c:4090
Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
Definition alter.c:619
#define NameStr(name)
Definition c.h:765
ObjectAddresses * new_object_addresses(void)
@ DEPENDENCY_EXTENSION
Definition dependency.h:38
@ DEPENDENCY_NORMAL
Definition dependency.h:33
int errdetail(const char *fmt,...)
Definition elog.c:1216
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
static ExtensionControlFile * read_extension_control_file(const char *extname)
Definition extension.c:748
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition extension.c:206
char * get_extension_name(Oid ext_oid)
Definition extension.c:228
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
HeapTuple heap_copytuple(HeapTuple tuple)
Definition heaptuple.c:778
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
#define AccessShareLock
Definition lockdefs.h:36
#define RowExclusiveLock
Definition lockdefs.h:38
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516
Oid GetUserId(void)
Definition miscinit.c:469
Oid LookupCreationNamespace(const char *nspname)
Definition namespace.c:3498
#define InvokeObjectPostAlterHook(classId, objectId, subId)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
@ OBJECT_SCHEMA
@ OBJECT_EXTENSION
#define ACL_CREATE
Definition parsenodes.h:85
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition pg_depend.c:457
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition pg_depend.c:732
FormData_pg_depend * Form_pg_depend
Definition pg_depend.h:72
FormData_pg_extension * Form_pg_extension
#define lfirst(lc)
Definition pg_list.h:172
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
#define InvalidOid
unsigned int Oid
static int fb(int x)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
void relation_close(Relation relation, LOCKMODE lockmode)
Definition relation.c:205
#define BTEqualStrategyNumber
Definition stratnum.h:31
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References AccessShareLock, ACL_CREATE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, AlterObjectNamespace_oid(), BTEqualStrategyNumber, CatalogTupleUpdate(), changeDependencyFor(), DEPENDENCY_EXTENSION, DEPENDENCY_NORMAL, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, fb(), get_extension_name(), get_extension_oid(), get_namespace_name(), getExtensionOfObject(), getObjectDescription(), GETSTRUCT(), GetUserId(), heap_copytuple(), HeapTupleIsValid, InvalidObjectAddress, InvalidOid, InvokeObjectPostAlterHook, lfirst, LookupCreationNamespace(), NameStr, new_object_addresses(), object_aclcheck(), OBJECT_EXTENSION, object_ownercheck(), OBJECT_SCHEMA, ObjectAddressSet, ObjectIdGetDatum(), read_extension_control_file(), relation_close(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by ExecAlterObjectSchemaStmt().

◆ CreateExtension()

ObjectAddress CreateExtension ( ParseState pstate,
CreateExtensionStmt stmt 
)
extern

Definition at line 2013 of file extension.c.

2014{
2018 char *schemaName = NULL;
2019 char *versionName = NULL;
2020 bool cascade = false;
2021 ListCell *lc;
2022
2023 /* Check extension name validity before any filesystem access */
2025
2026 /*
2027 * Check for duplicate extension name. The unique index on
2028 * pg_extension.extname would catch this anyway, and serves as a backstop
2029 * in case of race conditions; but this is a friendlier error message, and
2030 * besides we need a check to support IF NOT EXISTS.
2031 */
2032 if (get_extension_oid(stmt->extname, true) != InvalidOid)
2033 {
2034 if (stmt->if_not_exists)
2035 {
2038 errmsg("extension \"%s\" already exists, skipping",
2039 stmt->extname)));
2040 return InvalidObjectAddress;
2041 }
2042 else
2043 ereport(ERROR,
2045 errmsg("extension \"%s\" already exists",
2046 stmt->extname)));
2047 }
2048
2049 /*
2050 * We use global variables to track the extension being created, so we can
2051 * create only one extension at the same time.
2052 */
2054 ereport(ERROR,
2056 errmsg("nested CREATE EXTENSION is not supported")));
2057
2058 /* Deconstruct the statement option list */
2059 foreach(lc, stmt->options)
2060 {
2061 DefElem *defel = (DefElem *) lfirst(lc);
2062
2063 if (strcmp(defel->defname, "schema") == 0)
2064 {
2065 if (d_schema)
2067 d_schema = defel;
2069 }
2070 else if (strcmp(defel->defname, "new_version") == 0)
2071 {
2072 if (d_new_version)
2076 }
2077 else if (strcmp(defel->defname, "cascade") == 0)
2078 {
2079 if (d_cascade)
2081 d_cascade = defel;
2082 cascade = defGetBoolean(d_cascade);
2083 }
2084 else
2085 elog(ERROR, "unrecognized option: %s", defel->defname);
2086 }
2087
2088 /* Call CreateExtensionInternal to do the real work. */
2089 return CreateExtensionInternal(stmt->extname,
2090 schemaName,
2092 cascade,
2093 NIL,
2094 true);
2095}
char * defGetString(DefElem *def)
Definition define.c:34
bool defGetBoolean(DefElem *def)
Definition define.c:93
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
Definition define.c:370
#define NOTICE
Definition elog.h:35
static void check_valid_extension_name(const char *extensionname)
Definition extension.c:270
bool creating_extension
Definition extension.c:77
static ObjectAddress CreateExtensionInternal(char *extensionName, char *schemaName, const char *versionName, bool cascade, List *parents, bool is_create)
Definition extension.c:1703
#define stmt
#define NIL
Definition pg_list.h:68
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30

References check_valid_extension_name(), CreateExtensionInternal(), creating_extension, defGetBoolean(), defGetString(), elog, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, errorConflictingDefElem(), fb(), get_extension_oid(), InvalidObjectAddress, InvalidOid, lfirst, NIL, NOTICE, and stmt.

Referenced by ProcessUtilitySlow().

◆ ExecAlterExtensionContentsStmt()

ObjectAddress ExecAlterExtensionContentsStmt ( AlterExtensionContentsStmt stmt,
ObjectAddress objAddr 
)
extern

Definition at line 3642 of file extension.c.

3644{
3646 ObjectAddress object;
3647 Relation relation;
3648
3649 switch (stmt->objtype)
3650 {
3651 case OBJECT_DATABASE:
3652 case OBJECT_EXTENSION:
3653 case OBJECT_INDEX:
3654 case OBJECT_PUBLICATION:
3655 case OBJECT_ROLE:
3658 case OBJECT_TABLESPACE:
3659 ereport(ERROR,
3661 errmsg("cannot add an object of this type to an extension")));
3662 break;
3663 default:
3664 /* OK */
3665 break;
3666 }
3667
3668 /*
3669 * Find the extension and acquire a lock on it, to ensure it doesn't get
3670 * dropped concurrently. A sharable lock seems sufficient: there's no
3671 * reason not to allow other sorts of manipulations, such as add/drop of
3672 * other objects, to occur concurrently. Concurrently adding/dropping the
3673 * *same* object would be bad, but we prevent that by using a non-sharable
3674 * lock on the individual object, below.
3675 */
3677 (Node *) makeString(stmt->extname),
3678 &relation, AccessShareLock, false);
3679
3680 /* Permission check: must own extension */
3683 stmt->extname);
3684
3685 /*
3686 * Translate the parser representation that identifies the object into an
3687 * ObjectAddress. get_object_address() will throw an error if the object
3688 * does not exist, and will also acquire a lock on the object to guard
3689 * against concurrent DROP and ALTER EXTENSION ADD/DROP operations.
3690 */
3691 object = get_object_address(stmt->objtype, stmt->object,
3692 &relation, ShareUpdateExclusiveLock, false);
3693
3694 Assert(object.objectSubId == 0);
3695 if (objAddr)
3696 *objAddr = object;
3697
3698 /* Permission check: must own target object, too */
3699 check_object_ownership(GetUserId(), stmt->objtype, object,
3700 stmt->object, relation);
3701
3702 /* Do the update, recursing to any dependent objects */
3704
3705 /* Finish up */
3707
3708 /*
3709 * If get_object_address() opened the relation for us, we close it to keep
3710 * the reference count correct - but we retain any locks acquired by
3711 * get_object_address() until commit time, to guard against concurrent
3712 * activity.
3713 */
3714 if (relation != NULL)
3715 relation_close(relation, NoLock);
3716
3717 return extension;
3718}
#define Assert(condition)
Definition c.h:873
static void ExecAlterExtensionContentsRecurse(AlterExtensionContentsStmt *stmt, ObjectAddress extension, ObjectAddress object)
Definition extension.c:3728
#define NoLock
Definition lockdefs.h:34
#define ShareUpdateExclusiveLock
Definition lockdefs.h:39
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
@ OBJECT_TABLESPACE
@ OBJECT_ROLE
@ OBJECT_INDEX
@ OBJECT_DATABASE
@ OBJECT_PUBLICATION
@ OBJECT_SUBSCRIPTION
@ OBJECT_STATISTIC_EXT
Definition nodes.h:135
String * makeString(char *str)
Definition value.c:63

References AccessShareLock, aclcheck_error(), ACLCHECK_NOT_OWNER, Assert, check_object_ownership(), ereport, errcode(), errmsg(), ERROR, ExecAlterExtensionContentsRecurse(), fb(), get_object_address(), GetUserId(), InvokeObjectPostAlterHook, makeString(), NoLock, OBJECT_DATABASE, OBJECT_EXTENSION, OBJECT_INDEX, object_ownercheck(), OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, relation_close(), ShareUpdateExclusiveLock, and stmt.

Referenced by ProcessUtilitySlow().

◆ ExecAlterExtensionStmt()

ObjectAddress ExecAlterExtensionStmt ( ParseState pstate,
AlterExtensionStmt stmt 
)
extern

Definition at line 3337 of file extension.c.

3338{
3340 char *versionName;
3341 char *oldVersionName;
3342 ExtensionControlFile *control;
3345 ScanKeyData key[1];
3349 Datum datum;
3350 bool isnull;
3351 ListCell *lc;
3352 ObjectAddress address;
3353
3354 /*
3355 * We use global variables to track the extension being created, so we can
3356 * create/update only one extension at the same time.
3357 */
3359 ereport(ERROR,
3361 errmsg("nested ALTER EXTENSION is not supported")));
3362
3363 /*
3364 * Look up the extension --- it must already exist in pg_extension
3365 */
3367
3368 ScanKeyInit(&key[0],
3371 CStringGetDatum(stmt->extname));
3372
3374 NULL, 1, key);
3375
3377
3379 ereport(ERROR,
3381 errmsg("extension \"%s\" does not exist",
3382 stmt->extname)));
3383
3385
3386 /*
3387 * Determine the existing version we are updating from
3388 */
3390 RelationGetDescr(extRel), &isnull);
3391 if (isnull)
3392 elog(ERROR, "extversion is null");
3394
3396
3398
3399 /* Permission check: must own extension */
3402 stmt->extname);
3403
3404 /*
3405 * Read the primary control file. Note we assume that it does not contain
3406 * any non-ASCII data, so there is no need to worry about encoding at this
3407 * point.
3408 */
3409 control = read_extension_control_file(stmt->extname);
3410
3411 /*
3412 * Read the statement option list
3413 */
3414 foreach(lc, stmt->options)
3415 {
3416 DefElem *defel = (DefElem *) lfirst(lc);
3417
3418 if (strcmp(defel->defname, "new_version") == 0)
3419 {
3420 if (d_new_version)
3423 }
3424 else
3425 elog(ERROR, "unrecognized option: %s", defel->defname);
3426 }
3427
3428 /*
3429 * Determine the version to update to
3430 */
3431 if (d_new_version && d_new_version->arg)
3433 else if (control->default_version)
3434 versionName = control->default_version;
3435 else
3436 {
3437 ereport(ERROR,
3439 errmsg("version to install must be specified")));
3440 versionName = NULL; /* keep compiler quiet */
3441 }
3443
3444 /*
3445 * If we're already at that version, just say so
3446 */
3448 {
3450 (errmsg("version \"%s\" of extension \"%s\" is already installed",
3451 versionName, stmt->extname)));
3452 return InvalidObjectAddress;
3453 }
3454
3455 /*
3456 * Identify the series of update script files we need to execute
3457 */
3460 versionName);
3461
3462 /*
3463 * Update the pg_extension row and execute the update scripts, one at a
3464 * time
3465 */
3468 NULL, false, false);
3469
3471
3472 return address;
3473}
static void check_valid_version_name(const char *versionname)
Definition extension.c:317
static List * identify_update_path(ExtensionControlFile *control, const char *oldVersion, const char *newVersion)
Definition extension.c:1512
static void ApplyExtensionUpdates(Oid extensionOid, ExtensionControlFile *pcontrol, const char *initialVersion, List *updateVersions, char *origSchemaName, bool cascade, bool is_create)
Definition extension.c:3484
#define DatumGetTextPP(X)
Definition fmgr.h:293
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
#define RelationGetDescr(relation)
Definition rel.h:540
Definition pg_list.h:54
#define strVal(v)
Definition value.h:82
char * text_to_cstring(const text *t)
Definition varlena.c:214

References AccessShareLock, aclcheck_error(), ACLCHECK_NOT_OWNER, ApplyExtensionUpdates(), BTEqualStrategyNumber, check_valid_version_name(), creating_extension, CStringGetDatum(), DatumGetTextPP, ExtensionControlFile::default_version, elog, ereport, errcode(), errmsg(), ERROR, errorConflictingDefElem(), fb(), GETSTRUCT(), GetUserId(), heap_getattr(), HeapTupleIsValid, identify_update_path(), InvalidObjectAddress, lfirst, NOTICE, OBJECT_EXTENSION, object_ownercheck(), ObjectAddressSet, read_extension_control_file(), RelationGetDescr, ScanKeyInit(), stmt, strVal, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), and text_to_cstring().

Referenced by ProcessUtilitySlow().

◆ extension_file_exists()

bool extension_file_exists ( const char extensionName)
extern

Definition at line 2551 of file extension.c.

2552{
2553 bool result = false;
2554 List *locations;
2555 DIR *dir;
2556 struct dirent *de;
2557
2559
2560 foreach_ptr(char, location, locations)
2561 {
2562 dir = AllocateDir(location);
2563
2564 /*
2565 * If the control directory doesn't exist, we want to silently return
2566 * false. Any other error will be reported by ReadDir.
2567 */
2568 if (dir == NULL && errno == ENOENT)
2569 {
2570 /* do nothing */
2571 }
2572 else
2573 {
2574 while ((de = ReadDir(dir, location)) != NULL)
2575 {
2576 char *extname;
2577
2578 if (!is_extension_control_filename(de->d_name))
2579 continue;
2580
2581 /* extract extension name from 'name.control' filename */
2582 extname = pstrdup(de->d_name);
2583 *strrchr(extname, '.') = '\0';
2584
2585 /* ignore it if it's an auxiliary control file */
2586 if (strstr(extname, "--"))
2587 continue;
2588
2589 /* done if it matches request */
2590 if (strcmp(extname, extensionName) == 0)
2591 {
2592 result = true;
2593 break;
2594 }
2595 }
2596
2597 FreeDir(dir);
2598 }
2599 if (result)
2600 break;
2601 }
2602
2603 return result;
2604}
static bool is_extension_control_filename(const char *filename)
Definition extension.c:364
static List * get_extension_control_directories(void)
Definition extension.c:383
int FreeDir(DIR *dir)
Definition fd.c:3005
DIR * AllocateDir(const char *dirname)
Definition fd.c:2887
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition fd.c:2953
char * pstrdup(const char *in)
Definition mcxt.c:1781
#define foreach_ptr(type, var, lst)
Definition pg_list.h:469
Definition dirent.c:26

References AllocateDir(), fb(), foreach_ptr, FreeDir(), get_extension_control_directories(), is_extension_control_filename(), pstrdup(), and ReadDir().

Referenced by CreateFunction(), and ExecuteDoStmt().

◆ get_extension_name()

char * get_extension_name ( Oid  ext_oid)
extern

Definition at line 228 of file extension.c.

229{
230 char *result;
231 HeapTuple tuple;
232
234
235 if (!HeapTupleIsValid(tuple))
236 return NULL;
237
238 result = pstrdup(NameStr(((Form_pg_extension) GETSTRUCT(tuple))->extname));
239 ReleaseSysCache(tuple);
240
241 return result;
242}
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220

References fb(), GETSTRUCT(), HeapTupleIsValid, NameStr, ObjectIdGetDatum(), pstrdup(), ReleaseSysCache(), and SearchSysCache1().

Referenced by AlterExtensionNamespace(), checkMembershipInCurrentExtension(), ExecAlterExtensionContentsRecurse(), getObjectDescription(), getObjectIdentityParts(), recordDependencyOnCurrentExtension(), and RemoveExtensionById().

◆ get_extension_oid()

Oid get_extension_oid ( const char extname,
bool  missing_ok 
)
extern

Definition at line 206 of file extension.c.

207{
208 Oid result;
209
211 CStringGetDatum(extname));
212
213 if (!OidIsValid(result) && !missing_ok)
216 errmsg("extension \"%s\" does not exist",
217 extname)));
218
219 return result;
220}
#define OidIsValid(objectId)
Definition c.h:788
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition syscache.h:109

References CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, fb(), GetSysCacheOid1, and OidIsValid.

Referenced by AlterExtensionNamespace(), binary_upgrade_create_empty_extension(), CreateExtension(), ExtractExtensionList(), get_object_address_unqualified(), and get_required_extension().

◆ get_extension_schema()

Oid get_extension_schema ( Oid  ext_oid)
extern

Definition at line 250 of file extension.c.

251{
252 Oid result;
253 HeapTuple tuple;
254
256
257 if (!HeapTupleIsValid(tuple))
258 return InvalidOid;
259
260 result = ((Form_pg_extension) GETSTRUCT(tuple))->extnamespace;
261 ReleaseSysCache(tuple);
262
263 return result;
264}

References fb(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().

Referenced by ApplyExtensionUpdates(), CreateExtensionInternal(), and ExecAlterExtensionContentsRecurse().

◆ InsertExtensionTuple()

ObjectAddress InsertExtensionTuple ( const char extName,
Oid  extOwner,
Oid  schemaOid,
bool  relocatable,
const char extVersion,
Datum  extConfig,
Datum  extCondition,
List requiredExtensions 
)
extern

Definition at line 2111 of file extension.c.

2115{
2117 Relation rel;
2119 bool nulls[Natts_pg_extension];
2120 HeapTuple tuple;
2124 ListCell *lc;
2125
2126 /*
2127 * Build and insert the pg_extension tuple
2128 */
2130
2131 memset(values, 0, sizeof(values));
2132 memset(nulls, 0, sizeof(nulls));
2133
2143
2145 nulls[Anum_pg_extension_extconfig - 1] = true;
2146 else
2148
2150 nulls[Anum_pg_extension_extcondition - 1] = true;
2151 else
2153
2154 tuple = heap_form_tuple(rel->rd_att, values, nulls);
2155
2156 CatalogTupleInsert(rel, tuple);
2157
2158 heap_freetuple(tuple);
2160
2161 /*
2162 * Record dependencies on owner, schema, and prerequisite extensions
2163 */
2165
2167
2169
2172
2173 foreach(lc, requiredExtensions)
2174 {
2177
2180 }
2181
2182 /* Record all of them (this includes duplicate elimination) */
2185
2186 /* Post creation hook for new extension */
2188
2189 return myself;
2190}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:97
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
#define DirectFunctionCall1(func, arg1)
Definition fmgr.h:684
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
Datum namein(PG_FUNCTION_ARGS)
Definition name.c:48
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define lfirst_oid(lc)
Definition pg_list.h:174
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
TupleDesc rd_att
Definition rel.h:112

References add_exact_object_address(), BoolGetDatum(), CatalogTupleInsert(), CStringGetDatum(), CStringGetTextDatum, DEPENDENCY_NORMAL, DirectFunctionCall1, fb(), free_object_addresses(), GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), InvokeObjectPostCreateHook, lfirst_oid, namein(), new_object_addresses(), ObjectAddressSet, ObjectIdGetDatum(), PointerGetDatum(), RelationData::rd_att, record_object_address_dependencies(), recordDependencyOnOwner(), RowExclusiveLock, table_close(), table_open(), and values.

Referenced by binary_upgrade_create_empty_extension(), and CreateExtensionInternal().

◆ RemoveExtensionById()

void RemoveExtensionById ( Oid  extId)
extern

Definition at line 2199 of file extension.c.

2200{
2201 Relation rel;
2202 SysScanDesc scandesc;
2203 HeapTuple tuple;
2204 ScanKeyData entry[1];
2205
2206 /*
2207 * Disallow deletion of any extension that's currently open for insertion;
2208 * else subsequent executions of recordDependencyOnCurrentExtension()
2209 * could create dangling pg_depend records that refer to a no-longer-valid
2210 * pg_extension OID. This is needed not so much because we think people
2211 * might write "DROP EXTENSION foo" in foo's own script files, as because
2212 * errors in dependency management in extension script files could give
2213 * rise to cases where an extension is dropped as a result of recursing
2214 * from some contained object. Because of that, we must test for the case
2215 * here, not at some higher level of the DROP EXTENSION command.
2216 */
2218 ereport(ERROR,
2220 errmsg("cannot drop extension \"%s\" because it is being modified",
2222
2224
2225 ScanKeyInit(&entry[0],
2229 scandesc = systable_beginscan(rel, ExtensionOidIndexId, true,
2230 NULL, 1, entry);
2231
2232 tuple = systable_getnext(scandesc);
2233
2234 /* We assume that there can be at most one matching tuple */
2235 if (HeapTupleIsValid(tuple))
2236 CatalogTupleDelete(rel, &tuple->t_self);
2237
2238 systable_endscan(scandesc);
2239
2241}
Oid CurrentExtensionObject
Definition extension.c:78
void CatalogTupleDelete(Relation heapRel, const ItemPointerData *tid)
Definition indexing.c:365
ItemPointerData t_self
Definition htup.h:65

References BTEqualStrategyNumber, CatalogTupleDelete(), CurrentExtensionObject, ereport, errcode(), errmsg(), ERROR, fb(), get_extension_name(), HeapTupleIsValid, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

Variable Documentation

◆ creating_extension

◆ CurrentExtensionObject

◆ Extension_control_path

PGDLLIMPORT char* Extension_control_path
extern

Definition at line 74 of file extension.c.

Referenced by get_extension_control_directories().