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)
 
Oid get_function_sibling_type (Oid funcoid, const char *typname)
 
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 3251 of file extension.c.

3252{
3254 Oid nspOid;
3255 Oid oldNspOid;
3258 ScanKeyData key[2];
3267
3269
3270 nspOid = LookupCreationNamespace(newschema);
3271
3272 /*
3273 * Permission check: must own extension. Note that we don't bother to
3274 * check ownership of the individual member objects ...
3275 */
3279
3280 /* Permission check: must have creation rights in target namespace */
3282 if (aclresult != ACLCHECK_OK)
3284
3285 /*
3286 * If the schema is currently a member of the extension, disallow moving
3287 * the extension into the schema. That would create a dependency loop.
3288 */
3290 ereport(ERROR,
3292 errmsg("cannot move extension \"%s\" into schema \"%s\" "
3293 "because the extension contains the schema",
3294 extensionName, newschema)));
3295
3296 /* Locate the pg_extension tuple */
3298
3299 ScanKeyInit(&key[0],
3303
3305 NULL, 1, key);
3306
3308
3309 if (!HeapTupleIsValid(extTup)) /* should not happen */
3310 elog(ERROR, "could not find tuple for extension %u",
3311 extensionOid);
3312
3313 /* Copy tuple so we can modify it below */
3316
3318
3319 /*
3320 * If the extension is already in the target schema, just silently do
3321 * nothing.
3322 */
3323 if (extForm->extnamespace == nspOid)
3324 {
3326 return InvalidObjectAddress;
3327 }
3328
3329 /* Check extension is supposed to be relocatable */
3330 if (!extForm->extrelocatable)
3331 ereport(ERROR,
3333 errmsg("extension \"%s\" does not support SET SCHEMA",
3334 NameStr(extForm->extname))));
3335
3337
3338 /* store the OID of the namespace to-be-changed */
3339 oldNspOid = extForm->extnamespace;
3340
3341 /*
3342 * Scan pg_depend to find objects that depend directly on the extension,
3343 * and alter each one's schema.
3344 */
3346
3347 ScanKeyInit(&key[0],
3351 ScanKeyInit(&key[1],
3355
3357 NULL, 2, key);
3358
3360 {
3364
3365 /*
3366 * If a dependent extension has a no_relocate request for this
3367 * extension, disallow SET SCHEMA. (XXX it's a bit ugly to do this in
3368 * the same loop that's actually executing the renames: we may detect
3369 * the error condition only after having expended a fair amount of
3370 * work. However, the alternative is to do two scans of pg_depend,
3371 * which seems like optimizing for failure cases. The rename work
3372 * will all roll back cleanly enough if we do fail here.)
3373 */
3374 if (pg_depend->deptype == DEPENDENCY_NORMAL &&
3375 pg_depend->classid == ExtensionRelationId)
3376 {
3377 char *depextname = get_extension_name(pg_depend->objid);
3379 ListCell *lc;
3380
3382 foreach(lc, dcontrol->no_relocate)
3383 {
3384 char *nrextname = (char *) lfirst(lc);
3385
3386 if (strcmp(nrextname, NameStr(extForm->extname)) == 0)
3387 {
3388 ereport(ERROR,
3390 errmsg("cannot SET SCHEMA of extension \"%s\" because other extensions prevent it",
3391 NameStr(extForm->extname)),
3392 errdetail("Extension \"%s\" requests no relocation of extension \"%s\".",
3393 depextname,
3394 NameStr(extForm->extname))));
3395 }
3396 }
3397 }
3398
3399 /*
3400 * Otherwise, ignore non-membership dependencies. (Currently, the
3401 * only other case we could see here is a normal dependency from
3402 * another extension.)
3403 */
3404 if (pg_depend->deptype != DEPENDENCY_EXTENSION)
3405 continue;
3406
3407 dep.classId = pg_depend->classid;
3408 dep.objectId = pg_depend->objid;
3409 dep.objectSubId = pg_depend->objsubid;
3410
3411 if (dep.objectSubId != 0) /* should not happen */
3412 elog(ERROR, "extension should not have a sub-object dependency");
3413
3414 /* Relocate the object */
3416 dep.objectId,
3417 nspOid,
3418 objsMoved);
3419
3420 /*
3421 * If not all the objects had the same old namespace (ignoring any
3422 * that are not in namespaces or are dependent types), complain.
3423 */
3425 ereport(ERROR,
3427 errmsg("extension \"%s\" does not support SET SCHEMA",
3428 NameStr(extForm->extname)),
3429 errdetail("%s is not in the extension's schema \"%s\"",
3430 getObjectDescription(&dep, false),
3432 }
3433
3434 /* report old schema, if caller wants it */
3435 if (oldschema)
3437
3439
3441
3442 /* Now adjust pg_extension.extnamespace */
3443 extForm->extnamespace = nspOid;
3444
3446
3448
3449 /* update dependency to point to the new schema */
3452 elog(ERROR, "could not change schema dependency for extension %s",
3453 NameStr(extForm->extname));
3454
3456
3458
3459 return extAddr;
3460}
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:1217
int errcode(int sqlerrcode)
Definition elog.c:864
int errmsg(const char *fmt,...)
Definition elog.c:1081
#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:877
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition extension.c:227
char * get_extension_name(Oid ext_oid)
Definition extension.c:249
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:459
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition pg_depend.c:734
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 2142 of file extension.c.

2143{
2147 char *schemaName = NULL;
2148 char *versionName = NULL;
2149 bool cascade = false;
2150 ListCell *lc;
2151
2152 /* Check extension name validity before any filesystem access */
2154
2155 /*
2156 * Check for duplicate extension name. The unique index on
2157 * pg_extension.extname would catch this anyway, and serves as a backstop
2158 * in case of race conditions; but this is a friendlier error message, and
2159 * besides we need a check to support IF NOT EXISTS.
2160 */
2161 if (get_extension_oid(stmt->extname, true) != InvalidOid)
2162 {
2163 if (stmt->if_not_exists)
2164 {
2167 errmsg("extension \"%s\" already exists, skipping",
2168 stmt->extname)));
2169 return InvalidObjectAddress;
2170 }
2171 else
2172 ereport(ERROR,
2174 errmsg("extension \"%s\" already exists",
2175 stmt->extname)));
2176 }
2177
2178 /*
2179 * We use global variables to track the extension being created, so we can
2180 * create only one extension at the same time.
2181 */
2183 ereport(ERROR,
2185 errmsg("nested CREATE EXTENSION is not supported")));
2186
2187 /* Deconstruct the statement option list */
2188 foreach(lc, stmt->options)
2189 {
2190 DefElem *defel = (DefElem *) lfirst(lc);
2191
2192 if (strcmp(defel->defname, "schema") == 0)
2193 {
2194 if (d_schema)
2196 d_schema = defel;
2198 }
2199 else if (strcmp(defel->defname, "new_version") == 0)
2200 {
2201 if (d_new_version)
2205 }
2206 else if (strcmp(defel->defname, "cascade") == 0)
2207 {
2208 if (d_cascade)
2210 d_cascade = defel;
2211 cascade = defGetBoolean(d_cascade);
2212 }
2213 else
2214 elog(ERROR, "unrecognized option: %s", defel->defname);
2215 }
2216
2217 /* Call CreateExtensionInternal to do the real work. */
2218 return CreateExtensionInternal(stmt->extname,
2219 schemaName,
2221 cascade,
2222 NIL,
2223 true);
2224}
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:399
bool creating_extension
Definition extension.c:79
static ObjectAddress CreateExtensionInternal(char *extensionName, char *schemaName, const char *versionName, bool cascade, List *parents, bool is_create)
Definition extension.c:1832
#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 3771 of file extension.c.

3773{
3775 ObjectAddress object;
3776 Relation relation;
3777
3778 switch (stmt->objtype)
3779 {
3780 case OBJECT_DATABASE:
3781 case OBJECT_EXTENSION:
3782 case OBJECT_INDEX:
3783 case OBJECT_PUBLICATION:
3784 case OBJECT_ROLE:
3787 case OBJECT_TABLESPACE:
3788 ereport(ERROR,
3790 errmsg("cannot add an object of this type to an extension")));
3791 break;
3792 default:
3793 /* OK */
3794 break;
3795 }
3796
3797 /*
3798 * Find the extension and acquire a lock on it, to ensure it doesn't get
3799 * dropped concurrently. A sharable lock seems sufficient: there's no
3800 * reason not to allow other sorts of manipulations, such as add/drop of
3801 * other objects, to occur concurrently. Concurrently adding/dropping the
3802 * *same* object would be bad, but we prevent that by using a non-sharable
3803 * lock on the individual object, below.
3804 */
3806 (Node *) makeString(stmt->extname),
3807 &relation, AccessShareLock, false);
3808
3809 /* Permission check: must own extension */
3812 stmt->extname);
3813
3814 /*
3815 * Translate the parser representation that identifies the object into an
3816 * ObjectAddress. get_object_address() will throw an error if the object
3817 * does not exist, and will also acquire a lock on the object to guard
3818 * against concurrent DROP and ALTER EXTENSION ADD/DROP operations.
3819 */
3820 object = get_object_address(stmt->objtype, stmt->object,
3821 &relation, ShareUpdateExclusiveLock, false);
3822
3823 Assert(object.objectSubId == 0);
3824 if (objAddr)
3825 *objAddr = object;
3826
3827 /* Permission check: must own target object, too */
3828 check_object_ownership(GetUserId(), stmt->objtype, object,
3829 stmt->object, relation);
3830
3831 /* Do the update, recursing to any dependent objects */
3833
3834 /* Finish up */
3836
3837 /*
3838 * If get_object_address() opened the relation for us, we close it to keep
3839 * the reference count correct - but we retain any locks acquired by
3840 * get_object_address() until commit time, to guard against concurrent
3841 * activity.
3842 */
3843 if (relation != NULL)
3844 relation_close(relation, NoLock);
3845
3846 return extension;
3847}
#define Assert(condition)
Definition c.h:873
static void ExecAlterExtensionContentsRecurse(AlterExtensionContentsStmt *stmt, ObjectAddress extension, ObjectAddress object)
Definition extension.c:3857
#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 3466 of file extension.c.

3467{
3469 char *versionName;
3470 char *oldVersionName;
3471 ExtensionControlFile *control;
3474 ScanKeyData key[1];
3478 Datum datum;
3479 bool isnull;
3480 ListCell *lc;
3481 ObjectAddress address;
3482
3483 /*
3484 * We use global variables to track the extension being created, so we can
3485 * create/update only one extension at the same time.
3486 */
3488 ereport(ERROR,
3490 errmsg("nested ALTER EXTENSION is not supported")));
3491
3492 /*
3493 * Look up the extension --- it must already exist in pg_extension
3494 */
3496
3497 ScanKeyInit(&key[0],
3500 CStringGetDatum(stmt->extname));
3501
3503 NULL, 1, key);
3504
3506
3508 ereport(ERROR,
3510 errmsg("extension \"%s\" does not exist",
3511 stmt->extname)));
3512
3514
3515 /*
3516 * Determine the existing version we are updating from
3517 */
3519 RelationGetDescr(extRel), &isnull);
3520 if (isnull)
3521 elog(ERROR, "extversion is null");
3523
3525
3527
3528 /* Permission check: must own extension */
3531 stmt->extname);
3532
3533 /*
3534 * Read the primary control file. Note we assume that it does not contain
3535 * any non-ASCII data, so there is no need to worry about encoding at this
3536 * point.
3537 */
3538 control = read_extension_control_file(stmt->extname);
3539
3540 /*
3541 * Read the statement option list
3542 */
3543 foreach(lc, stmt->options)
3544 {
3545 DefElem *defel = (DefElem *) lfirst(lc);
3546
3547 if (strcmp(defel->defname, "new_version") == 0)
3548 {
3549 if (d_new_version)
3552 }
3553 else
3554 elog(ERROR, "unrecognized option: %s", defel->defname);
3555 }
3556
3557 /*
3558 * Determine the version to update to
3559 */
3560 if (d_new_version && d_new_version->arg)
3562 else if (control->default_version)
3563 versionName = control->default_version;
3564 else
3565 {
3566 ereport(ERROR,
3568 errmsg("version to install must be specified")));
3569 versionName = NULL; /* keep compiler quiet */
3570 }
3572
3573 /*
3574 * If we're already at that version, just say so
3575 */
3577 {
3579 (errmsg("version \"%s\" of extension \"%s\" is already installed",
3580 versionName, stmt->extname)));
3581 return InvalidObjectAddress;
3582 }
3583
3584 /*
3585 * Identify the series of update script files we need to execute
3586 */
3589 versionName);
3590
3591 /*
3592 * Update the pg_extension row and execute the update scripts, one at a
3593 * time
3594 */
3597 NULL, false, false);
3598
3600
3601 return address;
3602}
static void check_valid_version_name(const char *versionname)
Definition extension.c:446
static List * identify_update_path(ExtensionControlFile *control, const char *oldVersion, const char *newVersion)
Definition extension.c:1641
static void ApplyExtensionUpdates(Oid extensionOid, ExtensionControlFile *pcontrol, const char *initialVersion, List *updateVersions, char *origSchemaName, bool cascade, bool is_create)
Definition extension.c:3613
#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 2680 of file extension.c.

2681{
2682 bool result = false;
2683 List *locations;
2684 DIR *dir;
2685 struct dirent *de;
2686
2688
2690 {
2691 dir = AllocateDir(location->loc);
2692
2693 /*
2694 * If the control directory doesn't exist, we want to silently return
2695 * false. Any other error will be reported by ReadDir.
2696 */
2697 if (dir == NULL && errno == ENOENT)
2698 {
2699 /* do nothing */
2700 }
2701 else
2702 {
2703 while ((de = ReadDir(dir, location->loc)) != NULL)
2704 {
2705 char *extname;
2706
2707 if (!is_extension_control_filename(de->d_name))
2708 continue;
2709
2710 /* extract extension name from 'name.control' filename */
2711 extname = pstrdup(de->d_name);
2712 *strrchr(extname, '.') = '\0';
2713
2714 /* ignore it if it's an auxiliary control file */
2715 if (strstr(extname, "--"))
2716 continue;
2717
2718 /* done if it matches request */
2719 if (strcmp(extname, extensionName) == 0)
2720 {
2721 result = true;
2722 break;
2723 }
2724 }
2725
2726 FreeDir(dir);
2727 }
2728 if (result)
2729 break;
2730 }
2731
2732 return result;
2733}
static bool is_extension_control_filename(const char *filename)
Definition extension.c:493
static List * get_extension_control_directories(void)
Definition extension.c:512
int FreeDir(DIR *dir)
Definition fd.c:3008
DIR * AllocateDir(const char *dirname)
Definition fd.c:2890
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition fd.c:2956
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 249 of file extension.c.

250{
251 char *result;
252 HeapTuple tuple;
253
255
256 if (!HeapTupleIsValid(tuple))
257 return NULL;
258
259 result = pstrdup(NameStr(((Form_pg_extension) GETSTRUCT(tuple))->extname));
260 ReleaseSysCache(tuple);
261
262 return result;
263}
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 227 of file extension.c.

228{
229 Oid result;
230
232 CStringGetDatum(extname));
233
234 if (!OidIsValid(result) && !missing_ok)
237 errmsg("extension \"%s\" does not exist",
238 extname)));
239
240 return result;
241}
#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 271 of file extension.c.

272{
273 Oid result;
274 HeapTuple tuple;
275
277
278 if (!HeapTupleIsValid(tuple))
279 return InvalidOid;
280
281 result = ((Form_pg_extension) GETSTRUCT(tuple))->extnamespace;
282 ReleaseSysCache(tuple);
283
284 return result;
285}

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

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

◆ get_function_sibling_type()

Oid get_function_sibling_type ( Oid  funcoid,
const char typname 
)
extern

Definition at line 311 of file extension.c.

312{
314 Oid extoid;
315 Oid typeoid;
316
317 /*
318 * See if we have the answer cached. Someday there may be enough callers
319 * to justify a hash table, but for now, a simple linked list is fine.
320 */
323 {
324 if (funcoid == cache_entry->reqfuncoid &&
325 strcmp(typname, cache_entry->typname) == 0)
326 break;
327 }
328 if (cache_entry && cache_entry->valid)
329 return cache_entry->typeoid;
330
331 /*
332 * Nope, so do the expensive lookups. We do not expect failures, so we do
333 * not cache negative results.
334 */
336 if (!OidIsValid(extoid))
337 return InvalidOid;
338 typeoid = getExtensionType(extoid, typname);
339 if (!OidIsValid(typeoid))
340 return InvalidOid;
341
342 /*
343 * Build, or revalidate, cache entry.
344 */
345 if (cache_entry == NULL)
346 {
347 /* Register invalidation hook if this is first entry */
348 if (ext_sibling_list == NULL)
351 (Datum) 0);
352
353 /* Momentarily zero the space to ensure valid flag is false */
356 sizeof(ExtensionSiblingCache));
359 }
360
362 cache_entry->typname = typname;
365 cache_entry->typeoid = typeoid;
366 /* Mark it valid only once it's fully populated */
367 cache_entry->valid = true;
368
369 return typeoid;
370}
static ExtensionSiblingCache * ext_sibling_list
Definition extension.c:162
static void ext_sibling_callback(Datum arg, int cacheid, uint32 hashvalue)
Definition extension.c:382
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
MemoryContext CacheMemoryContext
Definition mcxt.c:169
Oid getExtensionType(Oid extensionOid, const char *typname)
Definition pg_depend.c:832
NameData typname
Definition pg_type.h:41
struct ExtensionSiblingCache * next
Definition extension.c:152
#define GetSysCacheHashValue1(cacheId, key1)
Definition syscache.h:118

References CacheMemoryContext, CacheRegisterSyscacheCallback(), ext_sibling_callback(), ext_sibling_list, fb(), getExtensionOfObject(), getExtensionType(), GetSysCacheHashValue1, InvalidOid, MemoryContextAllocZero(), ExtensionSiblingCache::next, ObjectIdGetDatum(), OidIsValid, ExtensionSiblingCache::reqfuncoid, ExtensionSiblingCache::typeoid, and typname.

Referenced by _int_matchsel().

◆ 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 2240 of file extension.c.

2244{
2246 Relation rel;
2248 bool nulls[Natts_pg_extension];
2249 HeapTuple tuple;
2253 ListCell *lc;
2254
2255 /*
2256 * Build and insert the pg_extension tuple
2257 */
2259
2260 memset(values, 0, sizeof(values));
2261 memset(nulls, 0, sizeof(nulls));
2262
2272
2274 nulls[Anum_pg_extension_extconfig - 1] = true;
2275 else
2277
2279 nulls[Anum_pg_extension_extcondition - 1] = true;
2280 else
2282
2283 tuple = heap_form_tuple(rel->rd_att, values, nulls);
2284
2285 CatalogTupleInsert(rel, tuple);
2286
2287 heap_freetuple(tuple);
2289
2290 /*
2291 * Record dependencies on owner, schema, and prerequisite extensions
2292 */
2294
2296
2298
2301
2302 foreach(lc, requiredExtensions)
2303 {
2306
2309 }
2310
2311 /* Record all of them (this includes duplicate elimination) */
2314
2315 /* Post creation hook for new extension */
2317
2318 return myself;
2319}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:98
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 2328 of file extension.c.

2329{
2330 Relation rel;
2331 SysScanDesc scandesc;
2332 HeapTuple tuple;
2333 ScanKeyData entry[1];
2334
2335 /*
2336 * Disallow deletion of any extension that's currently open for insertion;
2337 * else subsequent executions of recordDependencyOnCurrentExtension()
2338 * could create dangling pg_depend records that refer to a no-longer-valid
2339 * pg_extension OID. This is needed not so much because we think people
2340 * might write "DROP EXTENSION foo" in foo's own script files, as because
2341 * errors in dependency management in extension script files could give
2342 * rise to cases where an extension is dropped as a result of recursing
2343 * from some contained object. Because of that, we must test for the case
2344 * here, not at some higher level of the DROP EXTENSION command.
2345 */
2347 ereport(ERROR,
2349 errmsg("cannot drop extension \"%s\" because it is being modified",
2351
2353
2354 ScanKeyInit(&entry[0],
2358 scandesc = systable_beginscan(rel, ExtensionOidIndexId, true,
2359 NULL, 1, entry);
2360
2361 tuple = systable_getnext(scandesc);
2362
2363 /* We assume that there can be at most one matching tuple */
2364 if (HeapTupleIsValid(tuple))
2365 CatalogTupleDelete(rel, &tuple->t_self);
2366
2367 systable_endscan(scandesc);
2368
2370}
Oid CurrentExtensionObject
Definition extension.c:80
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 76 of file extension.c.

Referenced by get_extension_control_directories().