63 #include "utils/fmgroids.h"
85 Oid refclassid,
Oid refobjid,
90 int noldmembers,
Oid *oldmembers,
91 int nnewmembers,
Oid *newmembers);
94 Oid refclassId,
Oid refobjId,
99 Oid refclassId,
Oid refobjId,
108 Oid oldrole,
Oid newrole);
177 referenced.
classId = AuthIdRelationId;
208 Oid refclassid,
Oid refobjid,
227 Anum_pg_shdepend_dbid,
231 Anum_pg_shdepend_classid,
235 Anum_pg_shdepend_objid,
239 Anum_pg_shdepend_objsubid,
254 "multiple pg_shdepend entries for object %u/%u/%d deptype %c",
255 classid, objid, objsubid, deptype);
273 shForm->refclassid = refclassid;
274 shForm->refobjid = refobjid;
282 bool nulls[Natts_pg_shdepend];
284 memset(nulls,
false,
sizeof(nulls));
324 classId, objectId, 0,
325 AuthIdRelationId, newOwnerId,
348 AuthIdRelationId, newOwnerId,
397 if (newTablespaceId != DEFAULTTABLESPACE_OID &&
400 classId, objectId, 0,
401 TableSpaceRelationId, newTablespaceId,
405 classId, objectId, 0,
true,
428 in1 = in2 = out1 = out2 = 0;
429 while (in1 < *nlist1 && in2 < *nlist2)
431 if (list1[in1] == list2[in2])
437 else if (list1[in1] < list2[in2])
440 list1[out1++] = list1[in1++];
445 list2[out2++] = list2[in2++];
450 while (in1 < *nlist1)
452 list1[out1++] = list1[in1++];
456 while (in2 < *nlist2)
458 list2[out2++] = list2[in2++];
493 int noldmembers,
Oid *oldmembers,
494 int nnewmembers,
Oid *newmembers)
498 noldmembers, oldmembers,
499 nnewmembers, newmembers);
513 int noldmembers,
Oid *oldmembers,
514 int nnewmembers,
Oid *newmembers)
519 noldmembers, oldmembers,
520 nnewmembers, newmembers);
527 int noldmembers,
Oid *oldmembers,
528 int nnewmembers,
Oid *newmembers)
539 getOidListDiff(oldmembers, &noldmembers, newmembers, &nnewmembers);
541 if (noldmembers > 0 || nnewmembers > 0)
546 for (
i = 0;
i < nnewmembers;
i++)
548 Oid roleid = newmembers[
i];
565 AuthIdRelationId, roleid,
570 for (
i = 0;
i < noldmembers;
i++)
572 Oid roleid = oldmembers[
i];
584 AuthIdRelationId, roleid,
677 char **detail_msg,
char **detail_log_msg)
683 int numReportedDeps = 0;
684 int numNotReportedDeps = 0;
685 int numNotReportedDbs = 0;
698 object.classId = classId;
699 object.objectId = objectId;
700 object.objectSubId = 0;
702 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
703 errmsg(
"cannot drop %s because it is required by the database system",
716 #define MAX_REPORTED_DEPS 100
718 allocedobjects = 128;
728 Anum_pg_shdepend_refclassid,
732 Anum_pg_shdepend_refobjid,
743 object.classId = sdepForm->classid;
744 object.objectId = sdepForm->objid;
745 object.objectSubId = sdepForm->objsubid;
757 if (numobjects >= allocedobjects)
764 objects[numobjects].
object = object;
765 objects[numobjects].
deptype = sdepForm->deptype;
782 foreach(cell, remDeps)
785 if (dep->
dbOid == sdepForm->dbid)
795 dep->
dbOid = sdepForm->dbid;
797 remDeps =
lappend(remDeps, dep);
810 qsort(objects, numobjects,
813 for (
int i = 0;
i < numobjects;
i++)
825 numNotReportedDeps++;
836 foreach(cell, remDeps)
840 object.classId = DatabaseRelationId;
841 object.objectId = dep->
dbOid;
842 object.objectSubId = 0;
863 *detail_msg = *detail_log_msg = NULL;
867 if (numNotReportedDeps > 0)
869 "(see server log for list)",
870 "\nand %d other objects "
871 "(see server log for list)",
874 if (numNotReportedDbs > 0)
876 "(see server log for list)",
877 "\nand objects in %d other databases "
878 "(see server log for list)",
882 *detail_msg = descs.
data;
883 *detail_log_msg = alldescs.
data;
922 Anum_pg_shdepend_dbid,
930 slot_stored_count = 0;
945 if (slot_init_count < max_slots)
953 memset(slot[slot_stored_count]->tts_isnull,
false,
954 slot[slot_stored_count]->tts_tupleDescriptor->natts *
sizeof(
bool));
959 slot[slot_stored_count]->
tts_values[Anum_pg_shdepend_classid - 1] = shdep->classid;
960 slot[slot_stored_count]->
tts_values[Anum_pg_shdepend_objid - 1] = shdep->objid;
961 slot[slot_stored_count]->
tts_values[Anum_pg_shdepend_objsubid - 1] = shdep->objsubid;
962 slot[slot_stored_count]->
tts_values[Anum_pg_shdepend_refclassid - 1] = shdep->refclassid;
963 slot[slot_stored_count]->
tts_values[Anum_pg_shdepend_refobjid - 1] = shdep->refobjid;
964 slot[slot_stored_count]->
tts_values[Anum_pg_shdepend_deptype - 1] = shdep->deptype;
970 if (slot_stored_count == max_slots)
973 slot_stored_count = 0;
978 if (slot_stored_count > 0)
987 for (
int i = 0;
i < slot_init_count;
i++)
1013 Anum_pg_shdepend_dbid,
1071 Oid refclassId,
Oid refobjId,
1076 bool nulls[Natts_pg_shdepend];
1085 memset(nulls,
false,
sizeof(nulls));
1126 bool drop_subobjects,
1127 Oid refclassId,
Oid refobjId,
1137 Anum_pg_shdepend_dbid,
1141 Anum_pg_shdepend_classid,
1145 Anum_pg_shdepend_objid,
1148 if (drop_subobjects)
1153 Anum_pg_shdepend_objsubid,
1167 if (
OidIsValid(refclassId) && shdepForm->refclassid != refclassId)
1169 if (
OidIsValid(refobjId) && shdepForm->refobjid != refobjId)
1172 shdepForm->deptype != deptype)
1218 case AuthIdRelationId:
1221 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1222 errmsg(
"role %u was concurrently dropped",
1226 case TableSpaceRelationId:
1233 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1234 errmsg(
"tablespace %u was concurrently dropped",
1240 case DatabaseRelationId:
1245 if (database == NULL)
1247 (
errcode(ERRCODE_UNDEFINED_OBJECT),
1248 errmsg(
"database %u was concurrently dropped",
1256 elog(
ERROR,
"unrecognized shared classId: %u", classId);
1287 if (objdesc == NULL)
1291 if (descs->
len != 0)
1309 elog(
ERROR,
"unrecognized dependency type: %d",
1361 foreach(cell, roleids)
1373 obj.
classId = AuthIdRelationId;
1378 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1379 errmsg(
"cannot drop objects owned by %s because they are "
1380 "required by the database system",
1385 Anum_pg_shdepend_refclassid,
1389 Anum_pg_shdepend_refobjid,
1409 switch (sdepForm->deptype)
1413 elog(
ERROR,
"unexpected dependency type");
1425 obj.
classId = sdepForm->classid;
1454 if (sdepForm->classid != AuthMemRelationId)
1471 sdepForm->classid == AuthMemRelationId)
1473 obj.
classId = sdepForm->classid;
1495 Assert(sdepForm->classid != AuthMemRelationId);
1499 sdepForm->objsubid);
1542 foreach(cell, roleids)
1554 obj.
classId = AuthIdRelationId;
1559 (
errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1560 errmsg(
"cannot reassign ownership of objects owned by %s because they are required by the database system",
1570 Anum_pg_shdepend_refclassid,
1574 Anum_pg_shdepend_refobjid,
1603 "shdepReassignOwned",
1608 switch (sdepForm->deptype)
1622 elog(
ERROR,
"unrecognized dependency type: %d",
1623 (
int) sdepForm->deptype);
1650 switch (sdepForm->classid)
1652 case TypeRelationId:
1656 case NamespaceRelationId:
1660 case RelationRelationId:
1670 case DefaultAclRelationId:
1678 case UserMappingRelationId:
1682 case ForeignServerRelationId:
1686 case ForeignDataWrapperRelationId:
1690 case EventTriggerRelationId:
1694 case PublicationRelationId:
1698 case SubscriptionRelationId:
1703 case CollationRelationId:
1704 case ConversionRelationId:
1705 case OperatorRelationId:
1706 case ProcedureRelationId:
1707 case LanguageRelationId:
1708 case LargeObjectRelationId:
1709 case OperatorFamilyRelationId:
1710 case OperatorClassRelationId:
1711 case ExtensionRelationId:
1712 case StatisticExtRelationId:
1713 case TableSpaceRelationId:
1714 case DatabaseRelationId:
1715 case TSConfigRelationId:
1716 case TSDictionaryRelationId:
1723 elog(
ERROR,
"unexpected classid %u", sdepForm->classid);
1758 sdepForm->objsubid);
void RemoveRoleFromInitPriv(Oid roleid, Oid classid, Oid objid, int32 objsubid)
void ReplaceRoleInInitPriv(Oid oldroleid, Oid newroleid, Oid classid, Oid objid, int32 objsubid)
void RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid)
void AlterObjectOwner_internal(Oid classId, Oid objectId, Oid new_ownerId)
char * get_tablespace_name(Oid spc_oid)
static Datum values[MAXATTR]
#define ngettext(s, p, n)
#define Assert(condition)
#define OidIsValid(objectId)
bool IsPinnedObject(Oid classId, Oid objectId)
bool IsSharedRelation(Oid relationId)
char * get_database_name(Oid dbid)
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
void sort_object_addresses(ObjectAddresses *addrs)
void AcquireDeletionLock(const ObjectAddress *object, int flags)
void ReleaseDeletionLock(const ObjectAddress *object)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
@ SHARED_DEPENDENCY_INITACL
@ SHARED_DEPENDENCY_TABLESPACE
@ SHARED_DEPENDENCY_INVALID
@ SHARED_DEPENDENCY_POLICY
@ SHARED_DEPENDENCY_OWNER
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void AlterEventTriggerOwner_oid(Oid trigOid, Oid newOwnerId)
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
const TupleTableSlotOps TTSOpsHeapTuple
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void AlterForeignServerOwner_oid(Oid srvId, Oid newOwnerId)
void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId)
void systable_endscan(SysScanDesc sysscan)
bool systable_recheck_tuple(SysScanDesc sysscan, HeapTuple tup)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTuplesMultiInsertWithInfo(Relation heapRel, TupleTableSlot **slot, int ntuples, CatalogIndexState indstate)
void CatalogCloseIndexes(CatalogIndexState indstate)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
#define MAX_CATALOG_MULTI_INSERT_BYTES
List * lappend(List *list, void *datum)
void list_free_deep(List *list)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
#define AccessExclusiveLock
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define IsBootstrapProcessingMode()
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
#define ObjectAddressSet(addr, class_id, object_id)
static void shdepDropDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, bool drop_subobjects, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
static int shared_dependency_comparator(const void *a, const void *b)
static void shdepReassignOwned_InitAcl(Form_pg_shdepend sdepForm, Oid oldrole, Oid newrole)
void dropDatabaseDependencies(Oid databaseId)
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
static void shdepReassignOwned_Owner(Form_pg_shdepend sdepForm, Oid newrole)
static void getOidListDiff(Oid *list1, int *nlist1, Oid *list2, int *nlist2)
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
static Oid classIdGetDbId(Oid classId)
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
void updateInitAclDependencies(Oid classId, Oid objectId, int32 objsubId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
#define MAX_REPORTED_DEPS
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
void recordDependencyOnTablespace(Oid classId, Oid objectId, Oid tablespace)
static void shdepAddDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
void shdepDropOwned(List *roleids, DropBehavior behavior)
static void storeObjectDescription(StringInfo descs, SharedDependencyObjectType type, ObjectAddress *object, SharedDependencyType deptype, int count)
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
void shdepLockAndCheckObject(Oid classId, Oid objectId)
void changeDependencyOnTablespace(Oid classId, Oid objectId, Oid newTablespaceId)
static void updateAclDependenciesWorker(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, SharedDependencyType deptype, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
SharedDependencyObjectType
void shdepReassignOwned(List *roleids, Oid newrole)
static void shdepChangeDep(Relation sdepRel, Oid classid, Oid objid, int32 objsubid, Oid refclassid, Oid refobjid, SharedDependencyType deptype)
FormData_pg_shdepend * Form_pg_shdepend
bool RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid policy_id)
#define qsort(a, b, c, d)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
void AlterPublicationOwner_oid(Oid subid, Oid newOwnerId)
MemoryContextSwitchTo(old_ctx)
#define RelationGetDescr(relation)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
void AlterSchemaOwner_oid(Oid schemaoid, Oid newOwnerId)
#define BTEqualStrategyNumber
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
SharedDependencyObjectType objtype
void AlterSubscriptionOwner_oid(Oid subid, Oid newOwnerId)
#define SearchSysCacheExists1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
void AlterTypeOwner_oid(Oid typeOid, Oid newOwnerId, bool hasDependEntry)
void CommandCounterIncrement(void)