PostgreSQL Source Code  git master
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)
 
char * get_extension_name (Oid ext_oid)
 
ObjectAddress AlterExtensionNamespace (const char *extensionName, const char *newschema, Oid *oldschema)
 

Variables

PGDLLIMPORT bool creating_extension
 
PGDLLIMPORT Oid CurrentExtensionObject
 

Function Documentation

◆ AlterExtensionNamespace()

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

Definition at line 2708 of file extension.c.

References AccessShareLock, ACL_CREATE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, AlterObjectNamespace_oid(), BTEqualStrategyNumber, CatalogTupleUpdate(), changeDependencyFor(), ObjectAddress::classId, DEPENDENCY_EXTENSION, DependReferenceIndexId, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, ExtensionOidIndexId, get_extension_oid(), get_namespace_name(), getExtensionOfObject(), getObjectDescription(), GETSTRUCT, GetUserId(), heap_copytuple(), HeapTupleIsValid, InvalidObjectAddress, InvalidOid, InvokeObjectPostAlterHook, sort-test::key, LookupCreationNamespace(), NameStr, new_object_addresses(), OBJECT_EXTENSION, OBJECT_SCHEMA, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, pg_extension_ownercheck(), pg_namespace_aclcheck(), relation_close(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by ExecAlterObjectSchemaStmt().

2709 {
2710  Oid extensionOid;
2711  Oid nspOid;
2712  Oid oldNspOid = InvalidOid;
2713  AclResult aclresult;
2714  Relation extRel;
2715  ScanKeyData key[2];
2716  SysScanDesc extScan;
2717  HeapTuple extTup;
2718  Form_pg_extension extForm;
2719  Relation depRel;
2720  SysScanDesc depScan;
2721  HeapTuple depTup;
2722  ObjectAddresses *objsMoved;
2723  ObjectAddress extAddr;
2724 
2725  extensionOid = get_extension_oid(extensionName, false);
2726 
2727  nspOid = LookupCreationNamespace(newschema);
2728 
2729  /*
2730  * Permission check: must own extension. Note that we don't bother to
2731  * check ownership of the individual member objects ...
2732  */
2733  if (!pg_extension_ownercheck(extensionOid, GetUserId()))
2735  extensionName);
2736 
2737  /* Permission check: must have creation rights in target namespace */
2738  aclresult = pg_namespace_aclcheck(nspOid, GetUserId(), ACL_CREATE);
2739  if (aclresult != ACLCHECK_OK)
2740  aclcheck_error(aclresult, OBJECT_SCHEMA, newschema);
2741 
2742  /*
2743  * If the schema is currently a member of the extension, disallow moving
2744  * the extension into the schema. That would create a dependency loop.
2745  */
2746  if (getExtensionOfObject(NamespaceRelationId, nspOid) == extensionOid)
2747  ereport(ERROR,
2748  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2749  errmsg("cannot move extension \"%s\" into schema \"%s\" "
2750  "because the extension contains the schema",
2751  extensionName, newschema)));
2752 
2753  /* Locate the pg_extension tuple */
2754  extRel = table_open(ExtensionRelationId, RowExclusiveLock);
2755 
2756  ScanKeyInit(&key[0],
2757  Anum_pg_extension_oid,
2758  BTEqualStrategyNumber, F_OIDEQ,
2759  ObjectIdGetDatum(extensionOid));
2760 
2761  extScan = systable_beginscan(extRel, ExtensionOidIndexId, true,
2762  NULL, 1, key);
2763 
2764  extTup = systable_getnext(extScan);
2765 
2766  if (!HeapTupleIsValid(extTup)) /* should not happen */
2767  elog(ERROR, "could not find tuple for extension %u",
2768  extensionOid);
2769 
2770  /* Copy tuple so we can modify it below */
2771  extTup = heap_copytuple(extTup);
2772  extForm = (Form_pg_extension) GETSTRUCT(extTup);
2773 
2774  systable_endscan(extScan);
2775 
2776  /*
2777  * If the extension is already in the target schema, just silently do
2778  * nothing.
2779  */
2780  if (extForm->extnamespace == nspOid)
2781  {
2782  table_close(extRel, RowExclusiveLock);
2783  return InvalidObjectAddress;
2784  }
2785 
2786  /* Check extension is supposed to be relocatable */
2787  if (!extForm->extrelocatable)
2788  ereport(ERROR,
2789  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2790  errmsg("extension \"%s\" does not support SET SCHEMA",
2791  NameStr(extForm->extname))));
2792 
2793  objsMoved = new_object_addresses();
2794 
2795  /*
2796  * Scan pg_depend to find objects that depend directly on the extension,
2797  * and alter each one's schema.
2798  */
2799  depRel = table_open(DependRelationId, AccessShareLock);
2800 
2801  ScanKeyInit(&key[0],
2802  Anum_pg_depend_refclassid,
2803  BTEqualStrategyNumber, F_OIDEQ,
2804  ObjectIdGetDatum(ExtensionRelationId));
2805  ScanKeyInit(&key[1],
2806  Anum_pg_depend_refobjid,
2807  BTEqualStrategyNumber, F_OIDEQ,
2808  ObjectIdGetDatum(extensionOid));
2809 
2810  depScan = systable_beginscan(depRel, DependReferenceIndexId, true,
2811  NULL, 2, key);
2812 
2813  while (HeapTupleIsValid(depTup = systable_getnext(depScan)))
2814  {
2815  Form_pg_depend pg_depend = (Form_pg_depend) GETSTRUCT(depTup);
2816  ObjectAddress dep;
2817  Oid dep_oldNspOid;
2818 
2819  /*
2820  * Ignore non-membership dependencies. (Currently, the only other
2821  * case we could see here is a normal dependency from another
2822  * extension.)
2823  */
2824  if (pg_depend->deptype != DEPENDENCY_EXTENSION)
2825  continue;
2826 
2827  dep.classId = pg_depend->classid;
2828  dep.objectId = pg_depend->objid;
2829  dep.objectSubId = pg_depend->objsubid;
2830 
2831  if (dep.objectSubId != 0) /* should not happen */
2832  elog(ERROR, "extension should not have a sub-object dependency");
2833 
2834  /* Relocate the object */
2835  dep_oldNspOid = AlterObjectNamespace_oid(dep.classId,
2836  dep.objectId,
2837  nspOid,
2838  objsMoved);
2839 
2840  /*
2841  * Remember previous namespace of first object that has one
2842  */
2843  if (oldNspOid == InvalidOid && dep_oldNspOid != InvalidOid)
2844  oldNspOid = dep_oldNspOid;
2845 
2846  /*
2847  * If not all the objects had the same old namespace (ignoring any
2848  * that are not in namespaces), complain.
2849  */
2850  if (dep_oldNspOid != InvalidOid && dep_oldNspOid != oldNspOid)
2851  ereport(ERROR,
2852  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2853  errmsg("extension \"%s\" does not support SET SCHEMA",
2854  NameStr(extForm->extname)),
2855  errdetail("%s is not in the extension's schema \"%s\"",
2856  getObjectDescription(&dep),
2857  get_namespace_name(oldNspOid))));
2858  }
2859 
2860  /* report old schema, if caller wants it */
2861  if (oldschema)
2862  *oldschema = oldNspOid;
2863 
2864  systable_endscan(depScan);
2865 
2867 
2868  /* Now adjust pg_extension.extnamespace */
2869  extForm->extnamespace = nspOid;
2870 
2871  CatalogTupleUpdate(extRel, &extTup->t_self, extTup);
2872 
2873  table_close(extRel, RowExclusiveLock);
2874 
2875  /* update dependencies to point to the new schema */
2876  changeDependencyFor(ExtensionRelationId, extensionOid,
2877  NamespaceRelationId, oldNspOid, nspOid);
2878 
2879  InvokeObjectPostAlterHook(ExtensionRelationId, extensionOid, 0);
2880 
2881  ObjectAddressSet(extAddr, ExtensionRelationId, extensionOid);
2882 
2883  return extAddr;
2884 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:610
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Oid GetUserId(void)
Definition: miscinit.c:380
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:2928
#define DependReferenceIndexId
Definition: indexing.h:151
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:570
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2385
unsigned int Oid
Definition: postgres_ext.h:31
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4693
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
char * getObjectDescription(const ObjectAddress *object)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:84
ItemPointerData t_self
Definition: htup.h:65
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3094
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5251
#define RowExclusiveLock
Definition: lockdefs.h:38
int errdetail(const char *fmt,...)
Definition: elog.c:860
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:71
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:163
#define ExtensionOidIndexId
Definition: indexing.h:326
FormData_pg_extension * Form_pg_extension
Definition: pg_extension.h:50
AclResult
Definition: acl.h:177
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:224
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:138
const ObjectAddress InvalidObjectAddress
int errmsg(const char *fmt,...)
Definition: elog.c:784
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:297
Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: alter.c:564
#define elog(elevel,...)
Definition: elog.h:226
#define NameStr(name)
Definition: c.h:609
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ CreateExtension()

ObjectAddress CreateExtension ( ParseState pstate,
CreateExtensionStmt stmt 
)

Definition at line 1647 of file extension.c.

References check_valid_extension_name(), CreateExtensionInternal(), creating_extension, defGetBoolean(), defGetString(), DefElem::defname, elog, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errmsg(), ERROR, CreateExtensionStmt::extname, get_extension_oid(), CreateExtensionStmt::if_not_exists, InvalidObjectAddress, InvalidOid, lfirst, DefElem::location, NIL, NOTICE, CreateExtensionStmt::options, and parser_errposition().

Referenced by ProcessUtilitySlow().

1648 {
1649  DefElem *d_schema = NULL;
1650  DefElem *d_new_version = NULL;
1651  DefElem *d_old_version = NULL;
1652  DefElem *d_cascade = NULL;
1653  char *schemaName = NULL;
1654  char *versionName = NULL;
1655  char *oldVersionName = NULL;
1656  bool cascade = false;
1657  ListCell *lc;
1658 
1659  /* Check extension name validity before any filesystem access */
1661 
1662  /*
1663  * Check for duplicate extension name. The unique index on
1664  * pg_extension.extname would catch this anyway, and serves as a backstop
1665  * in case of race conditions; but this is a friendlier error message, and
1666  * besides we need a check to support IF NOT EXISTS.
1667  */
1668  if (get_extension_oid(stmt->extname, true) != InvalidOid)
1669  {
1670  if (stmt->if_not_exists)
1671  {
1672  ereport(NOTICE,
1674  errmsg("extension \"%s\" already exists, skipping",
1675  stmt->extname)));
1676  return InvalidObjectAddress;
1677  }
1678  else
1679  ereport(ERROR,
1681  errmsg("extension \"%s\" already exists",
1682  stmt->extname)));
1683  }
1684 
1685  /*
1686  * We use global variables to track the extension being created, so we can
1687  * create only one extension at the same time.
1688  */
1689  if (creating_extension)
1690  ereport(ERROR,
1691  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1692  errmsg("nested CREATE EXTENSION is not supported")));
1693 
1694  /* Deconstruct the statement option list */
1695  foreach(lc, stmt->options)
1696  {
1697  DefElem *defel = (DefElem *) lfirst(lc);
1698 
1699  if (strcmp(defel->defname, "schema") == 0)
1700  {
1701  if (d_schema)
1702  ereport(ERROR,
1703  (errcode(ERRCODE_SYNTAX_ERROR),
1704  errmsg("conflicting or redundant options"),
1705  parser_errposition(pstate, defel->location)));
1706  d_schema = defel;
1707  schemaName = defGetString(d_schema);
1708  }
1709  else if (strcmp(defel->defname, "new_version") == 0)
1710  {
1711  if (d_new_version)
1712  ereport(ERROR,
1713  (errcode(ERRCODE_SYNTAX_ERROR),
1714  errmsg("conflicting or redundant options"),
1715  parser_errposition(pstate, defel->location)));
1716  d_new_version = defel;
1717  versionName = defGetString(d_new_version);
1718  }
1719  else if (strcmp(defel->defname, "old_version") == 0)
1720  {
1721  if (d_old_version)
1722  ereport(ERROR,
1723  (errcode(ERRCODE_SYNTAX_ERROR),
1724  errmsg("conflicting or redundant options"),
1725  parser_errposition(pstate, defel->location)));
1726  d_old_version = defel;
1727  oldVersionName = defGetString(d_old_version);
1728  }
1729  else if (strcmp(defel->defname, "cascade") == 0)
1730  {
1731  if (d_cascade)
1732  ereport(ERROR,
1733  (errcode(ERRCODE_SYNTAX_ERROR),
1734  errmsg("conflicting or redundant options"),
1735  parser_errposition(pstate, defel->location)));
1736  d_cascade = defel;
1737  cascade = defGetBoolean(d_cascade);
1738  }
1739  else
1740  elog(ERROR, "unrecognized option: %s", defel->defname);
1741  }
1742 
1743  /* Call CreateExtensionInternal to do the real work. */
1744  return CreateExtensionInternal(stmt->extname,
1745  schemaName,
1746  versionName,
1747  oldVersionName,
1748  cascade,
1749  NIL,
1750  true);
1751 }
#define NIL
Definition: pg_list.h:65
static ObjectAddress CreateExtensionInternal(char *extensionName, char *schemaName, const char *versionName, const char *oldVersionName, bool cascade, List *parents, bool is_create)
Definition: extension.c:1286
static void check_valid_extension_name(const char *extensionname)
Definition: extension.c:259
int errcode(int sqlerrcode)
Definition: elog.c:570
bool defGetBoolean(DefElem *def)
Definition: define.c:111
#define ERROR
Definition: elog.h:43
char * defGetString(DefElem *def)
Definition: define.c:49
int location
Definition: parsenodes.h:733
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvalidOid
Definition: postgres_ext.h:36
bool creating_extension
Definition: extension.c:70
#define NOTICE
Definition: elog.h:37
#define lfirst(lc)
Definition: pg_list.h:190
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:138
const ObjectAddress InvalidObjectAddress
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
char * defname
Definition: parsenodes.h:730
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:33

◆ ExecAlterExtensionContentsStmt()

ObjectAddress ExecAlterExtensionContentsStmt ( AlterExtensionContentsStmt stmt,
ObjectAddress objAddr 
)

Definition at line 3198 of file extension.c.

References aclcheck_error(), ACLCHECK_NOT_OWNER, AlterExtensionContentsStmt::action, Assert, check_object_ownership(), ObjectAddress::classId, deleteDependencyRecordsForClass(), DEPENDENCY_EXTENSION, elog, ereport, errcode(), errmsg(), ERROR, extension_config_remove(), AlterExtensionContentsStmt::extname, get_extension_name(), get_extension_oid(), get_extension_schema(), get_namespace_name(), get_object_address(), getExtensionOfObject(), getObjectDescription(), GetUserId(), InvokeObjectPostAlterHook, NoLock, AlterExtensionContentsStmt::object, OBJECT_EXTENSION, ObjectAddress::objectId, ObjectAddress::objectSubId, AlterExtensionContentsStmt::objtype, OidIsValid, pg_extension_ownercheck(), recordDependencyOn(), recordExtObjInitPriv(), relation_close(), removeExtObjInitPriv(), and ShareUpdateExclusiveLock.

Referenced by ProcessUtilitySlow().

3200 {
3201  ObjectAddress extension;
3202  ObjectAddress object;
3203  Relation relation;
3204  Oid oldExtension;
3205 
3206  extension.classId = ExtensionRelationId;
3207  extension.objectId = get_extension_oid(stmt->extname, false);
3208  extension.objectSubId = 0;
3209 
3210  /* Permission check: must own extension */
3211  if (!pg_extension_ownercheck(extension.objectId, GetUserId()))
3213  stmt->extname);
3214 
3215  /*
3216  * Translate the parser representation that identifies the object into an
3217  * ObjectAddress. get_object_address() will throw an error if the object
3218  * does not exist, and will also acquire a lock on the object to guard
3219  * against concurrent DROP and ALTER EXTENSION ADD/DROP operations.
3220  */
3221  object = get_object_address(stmt->objtype, stmt->object,
3222  &relation, ShareUpdateExclusiveLock, false);
3223 
3224  Assert(object.objectSubId == 0);
3225  if (objAddr)
3226  *objAddr = object;
3227 
3228  /* Permission check: must own target object, too */
3229  check_object_ownership(GetUserId(), stmt->objtype, object,
3230  stmt->object, relation);
3231 
3232  /*
3233  * Check existing extension membership.
3234  */
3235  oldExtension = getExtensionOfObject(object.classId, object.objectId);
3236 
3237  if (stmt->action > 0)
3238  {
3239  /*
3240  * ADD, so complain if object is already attached to some extension.
3241  */
3242  if (OidIsValid(oldExtension))
3243  ereport(ERROR,
3244  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3245  errmsg("%s is already a member of extension \"%s\"",
3246  getObjectDescription(&object),
3247  get_extension_name(oldExtension))));
3248 
3249  /*
3250  * Prevent a schema from being added to an extension if the schema
3251  * contains the extension. That would create a dependency loop.
3252  */
3253  if (object.classId == NamespaceRelationId &&
3254  object.objectId == get_extension_schema(extension.objectId))
3255  ereport(ERROR,
3256  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3257  errmsg("cannot add schema \"%s\" to extension \"%s\" "
3258  "because the schema contains the extension",
3259  get_namespace_name(object.objectId),
3260  stmt->extname)));
3261 
3262  /*
3263  * OK, add the dependency.
3264  */
3265  recordDependencyOn(&object, &extension, DEPENDENCY_EXTENSION);
3266 
3267  /*
3268  * Also record the initial ACL on the object, if any.
3269  *
3270  * Note that this will handle the object's ACLs, as well as any ACLs
3271  * on object subIds. (In other words, when the object is a table,
3272  * this will record the table's ACL and the ACLs for the columns on
3273  * the table, if any).
3274  */
3275  recordExtObjInitPriv(object.objectId, object.classId);
3276  }
3277  else
3278  {
3279  /*
3280  * DROP, so complain if it's not a member.
3281  */
3282  if (oldExtension != extension.objectId)
3283  ereport(ERROR,
3284  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3285  errmsg("%s is not a member of extension \"%s\"",
3286  getObjectDescription(&object),
3287  stmt->extname)));
3288 
3289  /*
3290  * OK, drop the dependency.
3291  */
3292  if (deleteDependencyRecordsForClass(object.classId, object.objectId,
3293  ExtensionRelationId,
3294  DEPENDENCY_EXTENSION) != 1)
3295  elog(ERROR, "unexpected number of extension dependency records");
3296 
3297  /*
3298  * If it's a relation, it might have an entry in the extension's
3299  * extconfig array, which we must remove.
3300  */
3301  if (object.classId == RelationRelationId)
3302  extension_config_remove(extension.objectId, object.objectId);
3303 
3304  /*
3305  * Remove all the initial ACLs, if any.
3306  *
3307  * Note that this will remove the object's ACLs, as well as any ACLs
3308  * on object subIds. (In other words, when the object is a table,
3309  * this will remove the table's ACL and the ACLs for the columns on
3310  * the table, if any).
3311  */
3312  removeExtObjInitPriv(object.objectId, object.classId);
3313  }
3314 
3315  InvokeObjectPostAlterHook(ExtensionRelationId, extension.objectId, 0);
3316 
3317  /*
3318  * If get_object_address() opened the relation for us, we close it to keep
3319  * the reference count correct - but we retain any locks acquired by
3320  * get_object_address() until commit time, to guard against concurrent
3321  * activity.
3322  */
3323  if (relation != NULL)
3324  relation_close(relation, NoLock);
3325 
3326  return extension;
3327 }
void recordExtObjInitPriv(Oid objoid, Oid classoid)
Definition: aclchk.c:5564
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:610
static Oid get_extension_schema(Oid ext_oid)
Definition: extension.c:222
Oid GetUserId(void)
Definition: miscinit.c:380
char * get_extension_name(Oid ext_oid)
Definition: extension.c:183
int errcode(int sqlerrcode)
Definition: elog.c:570
static void extension_config_remove(Oid extensionoid, Oid tableoid)
Definition: extension.c:2539
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:43
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
char * getObjectDescription(const ObjectAddress *object)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
#define ERROR
Definition: elog.h:43
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3094
#define NoLock
Definition: lockdefs.h:34
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5251
#define ereport(elevel, rest)
Definition: elog.h:141
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:163
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Definition: pg_depend.c:240
#define ShareUpdateExclusiveLock
Definition: lockdefs.h:39
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
#define Assert(condition)
Definition: c.h:732
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:138
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
void removeExtObjInitPriv(Oid objoid, Oid classoid)
Definition: aclchk.c:5854

◆ ExecAlterExtensionStmt()

ObjectAddress ExecAlterExtensionStmt ( ParseState pstate,
AlterExtensionStmt stmt 
)

Definition at line 2890 of file extension.c.

References AccessShareLock, aclcheck_error(), ACLCHECK_NOT_OWNER, ApplyExtensionUpdates(), DefElem::arg, BTEqualStrategyNumber, check_valid_version_name(), creating_extension, CStringGetDatum, DatumGetTextPP, ExtensionControlFile::default_version, DefElem::defname, elog, ereport, errcode(), errmsg(), ERROR, ExtensionNameIndexId, AlterExtensionStmt::extname, GETSTRUCT, GetUserId(), heap_getattr, HeapTupleIsValid, identify_update_path(), InvalidObjectAddress, sort-test::key, lfirst, DefElem::location, NOTICE, OBJECT_EXTENSION, ObjectAddressSet, AlterExtensionStmt::options, parser_errposition(), pg_extension_ownercheck(), read_extension_control_file(), RelationGetDescr, ScanKeyInit(), strVal, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), and text_to_cstring().

Referenced by ProcessUtilitySlow().

2891 {
2892  DefElem *d_new_version = NULL;
2893  char *versionName;
2894  char *oldVersionName;
2895  ExtensionControlFile *control;
2896  Oid extensionOid;
2897  Relation extRel;
2898  ScanKeyData key[1];
2899  SysScanDesc extScan;
2900  HeapTuple extTup;
2901  List *updateVersions;
2902  Datum datum;
2903  bool isnull;
2904  ListCell *lc;
2905  ObjectAddress address;
2906 
2907  /*
2908  * We use global variables to track the extension being created, so we can
2909  * create/update only one extension at the same time.
2910  */
2911  if (creating_extension)
2912  ereport(ERROR,
2913  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2914  errmsg("nested ALTER EXTENSION is not supported")));
2915 
2916  /*
2917  * Look up the extension --- it must already exist in pg_extension
2918  */
2919  extRel = table_open(ExtensionRelationId, AccessShareLock);
2920 
2921  ScanKeyInit(&key[0],
2922  Anum_pg_extension_extname,
2923  BTEqualStrategyNumber, F_NAMEEQ,
2924  CStringGetDatum(stmt->extname));
2925 
2926  extScan = systable_beginscan(extRel, ExtensionNameIndexId, true,
2927  NULL, 1, key);
2928 
2929  extTup = systable_getnext(extScan);
2930 
2931  if (!HeapTupleIsValid(extTup))
2932  ereport(ERROR,
2933  (errcode(ERRCODE_UNDEFINED_OBJECT),
2934  errmsg("extension \"%s\" does not exist",
2935  stmt->extname)));
2936 
2937  extensionOid = ((Form_pg_extension) GETSTRUCT(extTup))->oid;
2938 
2939  /*
2940  * Determine the existing version we are updating from
2941  */
2942  datum = heap_getattr(extTup, Anum_pg_extension_extversion,
2943  RelationGetDescr(extRel), &isnull);
2944  if (isnull)
2945  elog(ERROR, "extversion is null");
2946  oldVersionName = text_to_cstring(DatumGetTextPP(datum));
2947 
2948  systable_endscan(extScan);
2949 
2950  table_close(extRel, AccessShareLock);
2951 
2952  /* Permission check: must own extension */
2953  if (!pg_extension_ownercheck(extensionOid, GetUserId()))
2955  stmt->extname);
2956 
2957  /*
2958  * Read the primary control file. Note we assume that it does not contain
2959  * any non-ASCII data, so there is no need to worry about encoding at this
2960  * point.
2961  */
2962  control = read_extension_control_file(stmt->extname);
2963 
2964  /*
2965  * Read the statement option list
2966  */
2967  foreach(lc, stmt->options)
2968  {
2969  DefElem *defel = (DefElem *) lfirst(lc);
2970 
2971  if (strcmp(defel->defname, "new_version") == 0)
2972  {
2973  if (d_new_version)
2974  ereport(ERROR,
2975  (errcode(ERRCODE_SYNTAX_ERROR),
2976  errmsg("conflicting or redundant options"),
2977  parser_errposition(pstate, defel->location)));
2978  d_new_version = defel;
2979  }
2980  else
2981  elog(ERROR, "unrecognized option: %s", defel->defname);
2982  }
2983 
2984  /*
2985  * Determine the version to update to
2986  */
2987  if (d_new_version && d_new_version->arg)
2988  versionName = strVal(d_new_version->arg);
2989  else if (control->default_version)
2990  versionName = control->default_version;
2991  else
2992  {
2993  ereport(ERROR,
2994  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2995  errmsg("version to install must be specified")));
2996  versionName = NULL; /* keep compiler quiet */
2997  }
2998  check_valid_version_name(versionName);
2999 
3000  /*
3001  * If we're already at that version, just say so
3002  */
3003  if (strcmp(oldVersionName, versionName) == 0)
3004  {
3005  ereport(NOTICE,
3006  (errmsg("version \"%s\" of extension \"%s\" is already installed",
3007  versionName, stmt->extname)));
3008  return InvalidObjectAddress;
3009  }
3010 
3011  /*
3012  * Identify the series of update script files we need to execute
3013  */
3014  updateVersions = identify_update_path(control,
3015  oldVersionName,
3016  versionName);
3017 
3018  /*
3019  * Update the pg_extension row and execute the update scripts, one at a
3020  * time
3021  */
3022  ApplyExtensionUpdates(extensionOid, control,
3023  oldVersionName, updateVersions,
3024  NULL, false, false);
3025 
3026  ObjectAddressSet(address, ExtensionRelationId, extensionOid);
3027 
3028  return address;
3029 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define ExtensionNameIndexId
Definition: indexing.h:328
static ExtensionControlFile * read_extension_control_file(const char *extname)
Definition: extension.c:606
#define RelationGetDescr(relation)
Definition: rel.h:442
Oid GetUserId(void)
Definition: miscinit.c:380
#define DatumGetTextPP(X)
Definition: fmgr.h:286
static void ApplyExtensionUpdates(Oid extensionOid, ExtensionControlFile *pcontrol, const char *initialVersion, List *updateVersions, char *origSchemaName, bool cascade, bool is_create)
Definition: extension.c:3040
#define AccessShareLock
Definition: lockdefs.h:36
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ERROR
Definition: elog.h:43
static List * identify_update_path(ExtensionControlFile *control, const char *oldVersion, const char *newVersion)
Definition: extension.c:1095
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5251
int location
Definition: parsenodes.h:733
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
FormData_pg_extension * Form_pg_extension
Definition: pg_extension.h:50
Node * arg
Definition: parsenodes.h:731
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:762
char * default_version
Definition: extension.c:80
uintptr_t Datum
Definition: postgres.h:367
static void check_valid_version_name(const char *versionname)
Definition: extension.c:306
bool creating_extension
Definition: extension.c:70
#define NOTICE
Definition: elog.h:37
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define lfirst(lc)
Definition: pg_list.h:190
int parser_errposition(ParseState *pstate, int location)
Definition: parse_node.c:111
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
char * text_to_cstring(const text *t)
Definition: varlena.c:204
const ObjectAddress InvalidObjectAddress
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
char * defname
Definition: parsenodes.h:730
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_extension_name()

char* get_extension_name ( Oid  ext_oid)

Definition at line 183 of file extension.c.

References AccessShareLock, BTEqualStrategyNumber, ExtensionOidIndexId, GETSTRUCT, HeapTupleIsValid, NameStr, ObjectIdGetDatum, pstrdup(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by ExecAlterExtensionContentsStmt(), getObjectDescription(), getObjectIdentityParts(), recordDependencyOnCurrentExtension(), and RemoveExtensionById().

184 {
185  char *result;
186  Relation rel;
187  SysScanDesc scandesc;
188  HeapTuple tuple;
189  ScanKeyData entry[1];
190 
191  rel = table_open(ExtensionRelationId, AccessShareLock);
192 
193  ScanKeyInit(&entry[0],
194  Anum_pg_extension_oid,
195  BTEqualStrategyNumber, F_OIDEQ,
196  ObjectIdGetDatum(ext_oid));
197 
198  scandesc = systable_beginscan(rel, ExtensionOidIndexId, true,
199  NULL, 1, entry);
200 
201  tuple = systable_getnext(scandesc);
202 
203  /* We assume that there can be at most one matching tuple */
204  if (HeapTupleIsValid(tuple))
205  result = pstrdup(NameStr(((Form_pg_extension) GETSTRUCT(tuple))->extname));
206  else
207  result = NULL;
208 
209  systable_endscan(scandesc);
210 
212 
213  return result;
214 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
char * pstrdup(const char *in)
Definition: mcxt.c:1161
#define AccessShareLock
Definition: lockdefs.h:36
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ExtensionOidIndexId
Definition: indexing.h:326
FormData_pg_extension * Form_pg_extension
Definition: pg_extension.h:50
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define NameStr(name)
Definition: c.h:609
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_extension_oid()

Oid get_extension_oid ( const char *  extname,
bool  missing_ok 
)

Definition at line 138 of file extension.c.

References AccessShareLock, BTEqualStrategyNumber, CStringGetDatum, ereport, errcode(), errmsg(), ERROR, ExtensionNameIndexId, GETSTRUCT, HeapTupleIsValid, InvalidOid, OidIsValid, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

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

139 {
140  Oid result;
141  Relation rel;
142  SysScanDesc scandesc;
143  HeapTuple tuple;
144  ScanKeyData entry[1];
145 
146  rel = table_open(ExtensionRelationId, AccessShareLock);
147 
148  ScanKeyInit(&entry[0],
149  Anum_pg_extension_extname,
150  BTEqualStrategyNumber, F_NAMEEQ,
151  CStringGetDatum(extname));
152 
153  scandesc = systable_beginscan(rel, ExtensionNameIndexId, true,
154  NULL, 1, entry);
155 
156  tuple = systable_getnext(scandesc);
157 
158  /* We assume that there can be at most one matching tuple */
159  if (HeapTupleIsValid(tuple))
160  result = ((Form_pg_extension) GETSTRUCT(tuple))->oid;
161  else
162  result = InvalidOid;
163 
164  systable_endscan(scandesc);
165 
167 
168  if (!OidIsValid(result) && !missing_ok)
169  ereport(ERROR,
170  (errcode(ERRCODE_UNDEFINED_OBJECT),
171  errmsg("extension \"%s\" does not exist",
172  extname)));
173 
174  return result;
175 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define ExtensionNameIndexId
Definition: indexing.h:328
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:570
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:638
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ereport(elevel, rest)
Definition: elog.h:141
FormData_pg_extension * Form_pg_extension
Definition: pg_extension.h:50
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
int errmsg(const char *fmt,...)
Definition: elog.c:784
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ InsertExtensionTuple()

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

Definition at line 1767 of file extension.c.

References BoolGetDatum, CatalogTupleInsert(), ObjectAddress::classId, CStringGetDatum, CStringGetTextDatum, DEPENDENCY_NORMAL, DirectFunctionCall1, ExtensionOidIndexId, GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), InvokeObjectPostCreateHook, lfirst_oid, namein(), ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, PointerGetDatum, RelationData::rd_att, recordDependencyOn(), recordDependencyOnOwner(), RowExclusiveLock, table_close(), table_open(), and values.

Referenced by binary_upgrade_create_empty_extension(), and CreateExtensionInternal().

1771 {
1772  Oid extensionOid;
1773  Relation rel;
1774  Datum values[Natts_pg_extension];
1775  bool nulls[Natts_pg_extension];
1776  HeapTuple tuple;
1777  ObjectAddress myself;
1778  ObjectAddress nsp;
1779  ListCell *lc;
1780 
1781  /*
1782  * Build and insert the pg_extension tuple
1783  */
1784  rel = table_open(ExtensionRelationId, RowExclusiveLock);
1785 
1786  memset(values, 0, sizeof(values));
1787  memset(nulls, 0, sizeof(nulls));
1788 
1789  extensionOid = GetNewOidWithIndex(rel, ExtensionOidIndexId,
1790  Anum_pg_extension_oid);
1791  values[Anum_pg_extension_oid - 1] = ObjectIdGetDatum(extensionOid);
1792  values[Anum_pg_extension_extname - 1] =
1794  values[Anum_pg_extension_extowner - 1] = ObjectIdGetDatum(extOwner);
1795  values[Anum_pg_extension_extnamespace - 1] = ObjectIdGetDatum(schemaOid);
1796  values[Anum_pg_extension_extrelocatable - 1] = BoolGetDatum(relocatable);
1797  values[Anum_pg_extension_extversion - 1] = CStringGetTextDatum(extVersion);
1798 
1799  if (extConfig == PointerGetDatum(NULL))
1800  nulls[Anum_pg_extension_extconfig - 1] = true;
1801  else
1802  values[Anum_pg_extension_extconfig - 1] = extConfig;
1803 
1804  if (extCondition == PointerGetDatum(NULL))
1805  nulls[Anum_pg_extension_extcondition - 1] = true;
1806  else
1807  values[Anum_pg_extension_extcondition - 1] = extCondition;
1808 
1809  tuple = heap_form_tuple(rel->rd_att, values, nulls);
1810 
1811  CatalogTupleInsert(rel, tuple);
1812 
1813  heap_freetuple(tuple);
1815 
1816  /*
1817  * Record dependencies on owner, schema, and prerequisite extensions
1818  */
1819  recordDependencyOnOwner(ExtensionRelationId, extensionOid, extOwner);
1820 
1821  myself.classId = ExtensionRelationId;
1822  myself.objectId = extensionOid;
1823  myself.objectSubId = 0;
1824 
1825  nsp.classId = NamespaceRelationId;
1826  nsp.objectId = schemaOid;
1827  nsp.objectSubId = 0;
1828 
1829  recordDependencyOn(&myself, &nsp, DEPENDENCY_NORMAL);
1830 
1831  foreach(lc, requiredExtensions)
1832  {
1833  Oid reqext = lfirst_oid(lc);
1834  ObjectAddress otherext;
1835 
1836  otherext.classId = ExtensionRelationId;
1837  otherext.objectId = reqext;
1838  otherext.objectSubId = 0;
1839 
1840  recordDependencyOn(&myself, &otherext, DEPENDENCY_NORMAL);
1841  }
1842  /* Post creation hook for new extension */
1843  InvokeObjectPostCreateHook(ExtensionRelationId, extensionOid, 0);
1844 
1845  return myself;
1846 }
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:323
Datum namein(PG_FUNCTION_ARGS)
Definition: name.c:48
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:145
#define PointerGetDatum(X)
Definition: postgres.h:556
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:43
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:617
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:165
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:578
#define ExtensionOidIndexId
Definition: indexing.h:326
uintptr_t Datum
Definition: postgres.h:367
TupleDesc rd_att
Definition: rel.h:84
#define BoolGetDatum(X)
Definition: postgres.h:402
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define CStringGetTextDatum(s)
Definition: builtins.h:83
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:183
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ RemoveExtensionById()

void RemoveExtensionById ( Oid  extId)

Definition at line 1855 of file extension.c.

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

Referenced by doDeletion().

1856 {
1857  Relation rel;
1858  SysScanDesc scandesc;
1859  HeapTuple tuple;
1860  ScanKeyData entry[1];
1861 
1862  /*
1863  * Disallow deletion of any extension that's currently open for insertion;
1864  * else subsequent executions of recordDependencyOnCurrentExtension()
1865  * could create dangling pg_depend records that refer to a no-longer-valid
1866  * pg_extension OID. This is needed not so much because we think people
1867  * might write "DROP EXTENSION foo" in foo's own script files, as because
1868  * errors in dependency management in extension script files could give
1869  * rise to cases where an extension is dropped as a result of recursing
1870  * from some contained object. Because of that, we must test for the case
1871  * here, not at some higher level of the DROP EXTENSION command.
1872  */
1873  if (extId == CurrentExtensionObject)
1874  ereport(ERROR,
1875  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1876  errmsg("cannot drop extension \"%s\" because it is being modified",
1877  get_extension_name(extId))));
1878 
1879  rel = table_open(ExtensionRelationId, RowExclusiveLock);
1880 
1881  ScanKeyInit(&entry[0],
1882  Anum_pg_extension_oid,
1883  BTEqualStrategyNumber, F_OIDEQ,
1884  ObjectIdGetDatum(extId));
1885  scandesc = systable_beginscan(rel, ExtensionOidIndexId, true,
1886  NULL, 1, entry);
1887 
1888  tuple = systable_getnext(scandesc);
1889 
1890  /* We assume that there can be at most one matching tuple */
1891  if (HeapTupleIsValid(tuple))
1892  CatalogTupleDelete(rel, &tuple->t_self);
1893 
1894  systable_endscan(scandesc);
1895 
1897 }
Oid CurrentExtensionObject
Definition: extension.c:71
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
char * get_extension_name(Oid ext_oid)
Definition: extension.c:183
int errcode(int sqlerrcode)
Definition: elog.c:570
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:269
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:141
#define ExtensionOidIndexId
Definition: indexing.h:326
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
int errmsg(const char *fmt,...)
Definition: elog.c:784
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
#define BTEqualStrategyNumber
Definition: stratnum.h:31

Variable Documentation

◆ creating_extension

◆ CurrentExtensionObject