PostgreSQL Source Code git master
Loading...
Searching...
No Matches
objectaddress.h File Reference
#include "access/htup.h"
#include "nodes/parsenodes.h"
#include "storage/lockdefs.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
Include dependency graph for objectaddress.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ObjectAddress
 

Macros

#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
 
#define ObjectAddressSet(addr, class_id, object_id)    ObjectAddressSubSet(addr, class_id, object_id, 0)
 

Typedefs

typedef struct ObjectAddress ObjectAddress
 

Functions

ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
bool is_objectclass_supported (Oid class_id)
 
const charget_object_class_descr (Oid class_id)
 
Oid get_object_oid_index (Oid class_id)
 
SysCacheIdentifier get_object_catcache_oid (Oid class_id)
 
SysCacheIdentifier get_object_catcache_name (Oid class_id)
 
AttrNumber get_object_attnum_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
HeapTuple get_catalog_object_by_oid_extended (Relation catalog, AttrNumber oidcol, Oid objectId, bool locktup)
 
chargetObjectDescription (const ObjectAddress *object, bool missing_ok)
 
chargetObjectDescriptionOids (Oid classid, Oid objid)
 
int read_objtype_from_string (const char *objtype)
 
chargetObjectTypeDescription (const ObjectAddress *object, bool missing_ok)
 
chargetObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
chargetObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
struct ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

PGDLLIMPORT const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

#define ObjectAddressSet (   addr,
  class_id,
  object_id 
)     ObjectAddressSubSet(addr, class_id, object_id, 0)

Definition at line 41 of file objectaddress.h.

◆ ObjectAddressSubSet

#define ObjectAddressSubSet (   addr,
  class_id,
  object_id,
  object_sub_id 
)
Value:
do { \
(addr).classId = (class_id); \
(addr).objectId = (object_id); \
(addr).objectSubId = (object_sub_id); \
} while (0)
static int fb(int x)

Definition at line 34 of file objectaddress.h.

35 { \
36 (addr).classId = (class_id); \
37 (addr).objectId = (object_id); \
38 (addr).objectSubId = (object_sub_id); \
39 } while (0)

Typedef Documentation

◆ ObjectAddress

Function Documentation

◆ check_object_ownership()

void check_object_ownership ( Oid  roleid,
ObjectType  objtype,
ObjectAddress  address,
Node object,
Relation  relation 
)
extern

Definition at line 2391 of file objectaddress.c.

2393{
2394 switch (objtype)
2395 {
2396 case OBJECT_INDEX:
2397 case OBJECT_SEQUENCE:
2398 case OBJECT_TABLE:
2399 case OBJECT_VIEW:
2400 case OBJECT_MATVIEW:
2402 case OBJECT_COLUMN:
2403 case OBJECT_RULE:
2404 case OBJECT_TRIGGER:
2405 case OBJECT_POLICY:
2407 if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2409 RelationGetRelationName(relation));
2410 break;
2411 case OBJECT_TYPE:
2412 case OBJECT_DOMAIN:
2413 case OBJECT_ATTRIBUTE:
2414 if (!object_ownercheck(address.classId, address.objectId, roleid))
2416 break;
2418 {
2419 HeapTuple tuple;
2420 Oid contypid;
2421
2422 tuple = SearchSysCache1(CONSTROID,
2423 ObjectIdGetDatum(address.objectId));
2424 if (!HeapTupleIsValid(tuple))
2425 elog(ERROR, "constraint with OID %u does not exist",
2426 address.objectId);
2427
2429
2430 ReleaseSysCache(tuple);
2431
2432 /*
2433 * Fallback to type ownership check in this case as this is
2434 * what domain constraints rely on.
2435 */
2438 }
2439 break;
2440 case OBJECT_AGGREGATE:
2441 case OBJECT_FUNCTION:
2442 case OBJECT_PROCEDURE:
2443 case OBJECT_ROUTINE:
2444 case OBJECT_OPERATOR:
2445 if (!object_ownercheck(address.classId, address.objectId, roleid))
2447 NameListToString((castNode(ObjectWithArgs, object))->objname));
2448 break;
2449 case OBJECT_DATABASE:
2451 case OBJECT_EXTENSION:
2452 case OBJECT_FDW:
2454 case OBJECT_LANGUAGE:
2455 case OBJECT_PUBLICATION:
2456 case OBJECT_SCHEMA:
2458 case OBJECT_TABLESPACE:
2459 if (!object_ownercheck(address.classId, address.objectId, roleid))
2461 strVal(object));
2462 break;
2463 case OBJECT_COLLATION:
2464 case OBJECT_CONVERSION:
2465 case OBJECT_OPCLASS:
2466 case OBJECT_OPFAMILY:
2470 if (!object_ownercheck(address.classId, address.objectId, roleid))
2472 NameListToString(castNode(List, object)));
2473 break;
2474 case OBJECT_LARGEOBJECT:
2475 if (!lo_compat_privileges &&
2476 !object_ownercheck(address.classId, address.objectId, roleid))
2477 ereport(ERROR,
2479 errmsg("must be owner of large object %u",
2480 address.objectId)));
2481 break;
2482 case OBJECT_CAST:
2483 {
2484 /* We can only check permissions on the source/target types */
2485 TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2486 TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2487 Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2488 Oid targettypeid = typenameTypeId(NULL, targettype);
2489
2492 ereport(ERROR,
2494 errmsg("must be owner of type %s or type %s",
2497 }
2498 break;
2499 case OBJECT_TRANSFORM:
2500 {
2501 TypeName *typename = linitial_node(TypeName, castNode(List, object));
2502 Oid typeid = typenameTypeId(NULL, typename);
2503
2504 if (!object_ownercheck(TypeRelationId, typeid, roleid))
2506 }
2507 break;
2508 case OBJECT_ROLE:
2509
2510 /*
2511 * We treat roles as being "owned" by those with CREATEROLE priv,
2512 * provided that they also have admin option on the role.
2513 *
2514 * However, superusers are only owned by superusers.
2515 */
2516 if (superuser_arg(address.objectId))
2517 {
2518 if (!superuser_arg(roleid))
2519 ereport(ERROR,
2521 errmsg("permission denied"),
2522 errdetail("The current user must have the %s attribute.",
2523 "SUPERUSER")));
2524 }
2525 else
2526 {
2527 if (!has_createrole_privilege(roleid))
2528 ereport(ERROR,
2530 errmsg("permission denied"),
2531 errdetail("The current user must have the %s attribute.",
2532 "CREATEROLE")));
2533 if (!is_admin_of_role(roleid, address.objectId))
2534 ereport(ERROR,
2536 errmsg("permission denied"),
2537 errdetail("The current user must have the %s option on role \"%s\".",
2538 "ADMIN",
2540 true))));
2541 }
2542 break;
2543 case OBJECT_TSPARSER:
2544 case OBJECT_TSTEMPLATE:
2547 /* We treat these object types as being owned by superusers */
2548 if (!superuser_arg(roleid))
2549 ereport(ERROR,
2551 errmsg("must be superuser")));
2552 break;
2553 case OBJECT_AMOP:
2554 case OBJECT_AMPROC:
2555 case OBJECT_DEFAULT:
2556 case OBJECT_DEFACL:
2560 /* These are currently not supported or don't make sense here. */
2561 elog(ERROR, "unsupported object type: %d", (int) objtype);
2562 break;
2563 }
2564}
bool is_admin_of_role(Oid member, Oid role)
Definition acl.c:5416
@ ACLCHECK_NOT_OWNER
Definition acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition aclchk.c:4108
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition aclchk.c:2973
bool has_createrole_privilege(Oid roleid)
Definition aclchk.c:4187
int errcode(int sqlerrcode)
Definition elog.c:874
int errmsg(const char *fmt,...)
Definition elog.c:1093
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
char * format_type_be(Oid type_oid)
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
bool lo_compat_privileges
Definition inv_api.c:56
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:988
char * NameListToString(const List *names)
Definition namespace.c:3666
#define castNode(_type_, nodeptr)
Definition nodes.h:182
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition parse_type.c:291
@ OBJECT_EVENT_TRIGGER
@ OBJECT_FDW
@ OBJECT_TSPARSER
@ OBJECT_COLLATION
@ OBJECT_USER_MAPPING
@ OBJECT_ACCESS_METHOD
@ OBJECT_OPCLASS
@ OBJECT_DEFACL
@ OBJECT_AGGREGATE
@ OBJECT_MATVIEW
@ OBJECT_SCHEMA
@ OBJECT_POLICY
@ OBJECT_OPERATOR
@ OBJECT_FOREIGN_TABLE
@ OBJECT_TSCONFIGURATION
@ OBJECT_OPFAMILY
@ OBJECT_DOMAIN
@ OBJECT_COLUMN
@ OBJECT_TABLESPACE
@ OBJECT_ROLE
@ OBJECT_ROUTINE
@ OBJECT_LARGEOBJECT
@ OBJECT_PUBLICATION_NAMESPACE
@ OBJECT_PROCEDURE
@ OBJECT_EXTENSION
@ OBJECT_INDEX
@ OBJECT_DEFAULT
@ OBJECT_DATABASE
@ OBJECT_SEQUENCE
@ OBJECT_TSTEMPLATE
@ OBJECT_LANGUAGE
@ OBJECT_AMOP
@ OBJECT_PUBLICATION_REL
@ OBJECT_FOREIGN_SERVER
@ OBJECT_TSDICTIONARY
@ OBJECT_ATTRIBUTE
@ OBJECT_PUBLICATION
@ OBJECT_RULE
@ OBJECT_CONVERSION
@ OBJECT_AMPROC
@ OBJECT_TABLE
@ OBJECT_VIEW
@ OBJECT_PARAMETER_ACL
@ OBJECT_TYPE
@ OBJECT_FUNCTION
@ OBJECT_TABCONSTRAINT
@ OBJECT_DOMCONSTRAINT
@ OBJECT_SUBSCRIPTION
@ OBJECT_STATISTIC_EXT
@ OBJECT_CAST
@ OBJECT_TRIGGER
@ OBJECT_TRANSFORM
END_CATALOG_STRUCT typedef FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition pg_list.h:181
#define lsecond_node(type, l)
Definition pg_list.h:186
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
unsigned int Oid
#define RelationGetRelid(relation)
Definition rel.h:514
#define RelationGetRelationName(relation)
Definition rel.h:548
Definition pg_list.h:54
bool superuser_arg(Oid roleid)
Definition superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220
#define strVal(v)
Definition value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, fb(), Form_pg_constraint, format_type_be(), GETSTRUCT(), GetUserNameFromId(), has_createrole_privilege(), HeapTupleIsValid, is_admin_of_role(), linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, object_ownercheck(), OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectIdGetDatum(), RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCache1(), strVal, superuser_arg(), and typenameTypeId().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecSecLabelStmt(), and RemoveObjects().

◆ get_catalog_object_by_oid()

HeapTuple get_catalog_object_by_oid ( Relation  catalog,
AttrNumber  oidcol,
Oid  objectId 
)
extern

Definition at line 2790 of file objectaddress.c.

2791{
2792 return
2794}
HeapTuple get_catalog_object_by_oid_extended(Relation catalog, AttrNumber oidcol, Oid objectId, bool locktup)

References fb(), and get_catalog_object_by_oid_extended().

Referenced by getConstraintTypeDescription(), getObjectIdentityParts(), obtain_object_name_namespace(), pg_event_trigger_ddl_commands(), pg_get_acl(), and pg_identify_object().

◆ get_catalog_object_by_oid_extended()

HeapTuple get_catalog_object_by_oid_extended ( Relation  catalog,
AttrNumber  oidcol,
Oid  objectId,
bool  locktup 
)
extern

Definition at line 2803 of file objectaddress.c.

2807{
2808 HeapTuple tuple;
2809 Oid classId = RelationGetRelid(catalog);
2811
2812 if (oidCacheId >= 0)
2813 {
2814 if (locktup)
2816 ObjectIdGetDatum(objectId));
2817 else
2819 ObjectIdGetDatum(objectId));
2820 if (!HeapTupleIsValid(tuple)) /* should not happen */
2821 return NULL;
2822 }
2823 else
2824 {
2826 SysScanDesc scan;
2828
2830
2832 oidcol,
2834 ObjectIdGetDatum(objectId));
2835
2837 NULL, 1, &skey);
2838 tuple = systable_getnext(scan);
2839 if (!HeapTupleIsValid(tuple))
2840 {
2841 systable_endscan(scan);
2842 return NULL;
2843 }
2844
2845 if (locktup)
2847
2848 tuple = heap_copytuple(tuple);
2849
2850 systable_endscan(scan);
2851 }
2852
2853 return tuple;
2854}
#define Assert(condition)
Definition c.h:885
#define OidIsValid(objectId)
Definition c.h:800
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
void LockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
Definition lmgr.c:562
#define InplaceUpdateTupleLock
Definition lockdefs.h:48
Oid get_object_oid_index(Oid class_id)
SysCacheIdentifier get_object_catcache_oid(Oid class_id)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
#define BTEqualStrategyNumber
Definition stratnum.h:31
ItemPointerData t_self
Definition htup.h:65
HeapTuple SearchSysCacheLockedCopy1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:399
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91

References Assert, BTEqualStrategyNumber, fb(), get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, InplaceUpdateTupleLock, LockTuple(), ObjectIdGetDatum(), OidIsValid, RelationGetRelid, ScanKeyInit(), SearchSysCacheCopy1, SearchSysCacheLockedCopy1(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by AlterObjectOwner_internal(), and get_catalog_object_by_oid().

◆ get_object_address()

ObjectAddress get_object_address ( ObjectType  objtype,
Node object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
extern

Definition at line 923 of file objectaddress.c.

925{
926 ObjectAddress address = {InvalidOid, InvalidOid, 0};
928 Relation relation = NULL;
930
931 /* Some kind of lock must be taken. */
932 Assert(lockmode != NoLock);
933
934 for (;;)
935 {
936 /*
937 * Remember this value, so that, after looking up the object name and
938 * locking it, we can check whether any invalidation messages have
939 * been processed that might require a do-over.
940 */
942
943 /* Look up object address. */
944 switch (objtype)
945 {
946 case OBJECT_INDEX:
947 case OBJECT_SEQUENCE:
948 case OBJECT_TABLE:
949 case OBJECT_VIEW:
950 case OBJECT_MATVIEW:
952 address =
954 &relation, lockmode,
955 missing_ok);
956 break;
957 case OBJECT_ATTRIBUTE:
958 case OBJECT_COLUMN:
959 address =
961 &relation, lockmode,
962 missing_ok);
963 break;
964 case OBJECT_DEFAULT:
965 address =
966 get_object_address_attrdef(objtype, castNode(List, object),
967 &relation, lockmode,
968 missing_ok);
969 break;
970 case OBJECT_RULE:
971 case OBJECT_TRIGGER:
973 case OBJECT_POLICY:
974 address = get_object_address_relobject(objtype, castNode(List, object),
975 &relation, missing_ok);
976 break;
978 {
979 List *objlist;
981 char *constrname;
982
983 objlist = castNode(List, object);
986 missing_ok);
988
990 address.objectId = get_domain_constraint_oid(domaddr.objectId,
991 constrname, missing_ok);
992 address.objectSubId = 0;
993 }
994 break;
995 case OBJECT_DATABASE:
996 case OBJECT_EXTENSION:
998 case OBJECT_ROLE:
999 case OBJECT_SCHEMA:
1000 case OBJECT_LANGUAGE:
1001 case OBJECT_FDW:
1006 case OBJECT_PUBLICATION:
1008 address = get_object_address_unqualified(objtype,
1009 castNode(String, object), missing_ok);
1010 break;
1011 case OBJECT_TYPE:
1012 case OBJECT_DOMAIN:
1013 address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
1014 break;
1015 case OBJECT_AGGREGATE:
1016 case OBJECT_FUNCTION:
1017 case OBJECT_PROCEDURE:
1018 case OBJECT_ROUTINE:
1019 address.classId = ProcedureRelationId;
1020 address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
1021 address.objectSubId = 0;
1022 break;
1023 case OBJECT_OPERATOR:
1024 address.classId = OperatorRelationId;
1025 address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1026 address.objectSubId = 0;
1027 break;
1028 case OBJECT_COLLATION:
1029 address.classId = CollationRelationId;
1030 address.objectId = get_collation_oid(castNode(List, object), missing_ok);
1031 address.objectSubId = 0;
1032 break;
1033 case OBJECT_CONVERSION:
1034 address.classId = ConversionRelationId;
1035 address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
1036 address.objectSubId = 0;
1037 break;
1038 case OBJECT_OPCLASS:
1039 case OBJECT_OPFAMILY:
1040 address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
1041 break;
1042 case OBJECT_AMOP:
1043 case OBJECT_AMPROC:
1044 address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
1045 break;
1046 case OBJECT_LARGEOBJECT:
1048 address.objectId = oidparse(object);
1049 address.objectSubId = 0;
1050 if (!LargeObjectExists(address.objectId))
1051 {
1052 if (!missing_ok)
1053 ereport(ERROR,
1055 errmsg("large object %u does not exist",
1056 address.objectId)));
1057 }
1058 break;
1059 case OBJECT_CAST:
1060 {
1061 TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1062 TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1065
1066 sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1067 targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
1068 address.classId = CastRelationId;
1069 address.objectId =
1071 address.objectSubId = 0;
1072 }
1073 break;
1074 case OBJECT_TRANSFORM:
1075 {
1076 TypeName *typename = linitial_node(TypeName, castNode(List, object));
1077 char *langname = strVal(lsecond(castNode(List, object)));
1078 Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1079 Oid lang_id = get_language_oid(langname, missing_ok);
1080
1081 address.classId = TransformRelationId;
1082 address.objectId =
1083 get_transform_oid(type_id, lang_id, missing_ok);
1084 address.objectSubId = 0;
1085 }
1086 break;
1087 case OBJECT_TSPARSER:
1088 address.classId = TSParserRelationId;
1089 address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1090 address.objectSubId = 0;
1091 break;
1094 address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1095 address.objectSubId = 0;
1096 break;
1097 case OBJECT_TSTEMPLATE:
1098 address.classId = TSTemplateRelationId;
1099 address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1100 address.objectSubId = 0;
1101 break;
1103 address.classId = TSConfigRelationId;
1104 address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1105 address.objectSubId = 0;
1106 break;
1108 address = get_object_address_usermapping(castNode(List, object),
1109 missing_ok);
1110 break;
1113 missing_ok);
1114 break;
1117 &relation,
1118 missing_ok);
1119 break;
1120 case OBJECT_DEFACL:
1121 address = get_object_address_defacl(castNode(List, object),
1122 missing_ok);
1123 break;
1127 missing_ok);
1128 address.objectSubId = 0;
1129 break;
1130 /* no default, to let compiler warn about missing case */
1131 }
1132
1133 if (!address.classId)
1134 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1135
1136 /*
1137 * If we could not find the supplied object, return without locking.
1138 */
1139 if (!OidIsValid(address.objectId))
1140 {
1141 Assert(missing_ok);
1142 return address;
1143 }
1144
1145 /*
1146 * If we're retrying, see if we got the same answer as last time. If
1147 * so, we're done; if not, we locked the wrong thing, so give up our
1148 * lock.
1149 */
1150 if (OidIsValid(old_address.classId))
1151 {
1152 if (old_address.classId == address.classId
1153 && old_address.objectId == address.objectId
1154 && old_address.objectSubId == address.objectSubId)
1155 break;
1156 if (old_address.classId != RelationRelationId)
1157 {
1158 if (IsSharedRelation(old_address.classId))
1160 old_address.objectId,
1161 0, lockmode);
1162 else
1164 old_address.objectId,
1165 0, lockmode);
1166 }
1167 }
1168
1169 /*
1170 * If we're dealing with a relation or attribute, then the relation is
1171 * already locked. Otherwise, we lock it now.
1172 */
1173 if (address.classId != RelationRelationId)
1174 {
1175 if (IsSharedRelation(address.classId))
1176 LockSharedObject(address.classId, address.objectId, 0,
1177 lockmode);
1178 else
1179 LockDatabaseObject(address.classId, address.objectId, 0,
1180 lockmode);
1181 }
1182
1183 /*
1184 * At this point, we've resolved the name to an OID and locked the
1185 * corresponding database object. However, it's possible that by the
1186 * time we acquire the lock on the object, concurrent DDL has modified
1187 * the database in such a way that the name we originally looked up no
1188 * longer resolves to that OID.
1189 *
1190 * We can be certain that this isn't an issue if (a) no shared
1191 * invalidation messages have been processed or (b) we've locked a
1192 * relation somewhere along the line. All the relation name lookups
1193 * in this module ultimately use RangeVarGetRelid() to acquire a
1194 * relation lock, and that function protects against the same kinds of
1195 * races we're worried about here. Even when operating on a
1196 * constraint, rule, or trigger, we still acquire AccessShareLock on
1197 * the relation, which is enough to freeze out any concurrent DDL.
1198 *
1199 * In all other cases, however, it's possible that the name we looked
1200 * up no longer refers to the object we locked, so we retry the lookup
1201 * and see whether we get the same answer.
1202 */
1203 if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1204 break;
1205 old_address = address;
1206 }
1207
1208 /* relp must be given if it's a relation */
1209 Assert(!relation || relp);
1210
1211 /* Return the object address and the relation. */
1212 if (relp)
1213 *relp = relation;
1214 return address;
1215}
uint64_t uint64
Definition c.h:559
bool IsSharedRelation(Oid relationId)
Definition catalog.c:304
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1088
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1008
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1148
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1068
#define NoLock
Definition lockdefs.h:34
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition lsyscache.c:1083
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition namespace.c:2644
Oid get_collation_oid(List *collname, bool missing_ok)
Definition namespace.c:4043
Oid get_conversion_oid(List *conname, bool missing_ok)
Definition namespace.c:4097
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition namespace.c:2933
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition namespace.c:2788
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition namespace.c:3224
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition namespace.c:3079
static ObjectAddress get_object_address_publication_schema(List *object, bool missing_ok)
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *object, bool missing_ok)
static ObjectAddress get_object_address_unqualified(ObjectType objtype, String *strval, bool missing_ok)
static ObjectAddress get_object_address_publication_rel(List *object, Relation *relp, bool missing_ok)
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
static ObjectAddress get_object_address_usermapping(List *object, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Oid oidparse(Node *node)
Definition oid.c:264
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition parse_oper.c:135
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition parse_type.c:232
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
bool LargeObjectExists(Oid loid)
#define lsecond(l)
Definition pg_list.h:183
#define InvalidOid
Oid get_language_oid(const char *langname, bool missing_ok)
Definition proclang.c:227
uint64 SharedInvalidMessageCounter
Definition sinval.c:24
Definition value.h:64

References Assert, castNode, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, fb(), get_cast_oid(), get_collation_oid(), get_conversion_oid(), get_domain_constraint_oid(), get_language_oid(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_defacl(), get_object_address_opcf(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_publication_schema(), get_object_address_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), SharedInvalidMessageCounter, strVal, UnlockDatabaseObject(), and UnlockSharedObject().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecRenameStmt(), ExecSecLabelStmt(), get_object_address_rv(), objectNamesToOids(), pg_get_object_address(), and RemoveObjects().

◆ get_object_address_rv()

ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
extern

Definition at line 1225 of file objectaddress.c.

1228{
1229 if (rel)
1230 {
1231 object = lcons(makeString(rel->relname), object);
1232 if (rel->schemaname)
1233 object = lcons(makeString(rel->schemaname), object);
1234 if (rel->catalogname)
1235 object = lcons(makeString(rel->catalogname), object);
1236 }
1237
1238 return get_object_address(objtype, (Node *) object,
1239 relp, lockmode, missing_ok);
1240}
List * lcons(void *datum, List *list)
Definition list.c:495
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition nodes.h:135
char * relname
Definition primnodes.h:84
char * catalogname
Definition primnodes.h:78
char * schemaname
Definition primnodes.h:81
String * makeString(char *str)
Definition value.c:63

References RangeVar::catalogname, fb(), get_object_address(), lcons(), makeString(), RangeVar::relname, and RangeVar::schemaname.

Referenced by ExecAlterObjectDependsStmt().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)
extern

Definition at line 2693 of file objectaddress.c.

2694{
2696
2697 return prop->attnum_acl;
2698}
static const ObjectPropertyType * get_object_property_data(Oid class_id)

References ObjectPropertyType::attnum_acl, fb(), and get_object_property_data().

Referenced by AlterObjectOwner_internal(), ExecGrant_common(), object_aclmask_ext(), pg_get_acl(), and recordExtObjInitPriv().

◆ get_object_attnum_name()

◆ get_object_attnum_namespace()

◆ get_object_attnum_oid()

◆ get_object_attnum_owner()

◆ get_object_catcache_name()

SysCacheIdentifier get_object_catcache_name ( Oid  class_id)
extern

Definition at line 2653 of file objectaddress.c.

2654{
2656
2657 return prop->name_catcache_id;
2658}
SysCacheIdentifier name_catcache_id

References fb(), get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

◆ get_object_class_descr()

const char * get_object_class_descr ( Oid  class_id)
extern

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)
extern

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)
extern

Definition at line 2573 of file objectaddress.c.

2574{
2575 SysCacheIdentifier cache;
2576 HeapTuple tuple;
2577 Oid oid;
2579
2580 /* If not owned by a namespace, just return InvalidOid. */
2581 property = get_object_property_data(address->classId);
2582 if (property->attnum_namespace == InvalidAttrNumber)
2583 return InvalidOid;
2584
2585 /* Currently, we can only handle object types with system caches. */
2586 cache = property->oid_catcache_id;
2587 Assert(cache != SYSCACHEID_INVALID);
2588
2589 /* Fetch tuple from syscache and extract namespace attribute. */
2590 tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2591 if (!HeapTupleIsValid(tuple))
2592 elog(ERROR, "cache lookup failed for cache %d oid %u",
2593 cache, address->objectId);
2595 tuple,
2596 property->attnum_namespace));
2597 ReleaseSysCache(tuple);
2598
2599 return oid;
2600}
#define InvalidAttrNumber
Definition attnum.h:23
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:252
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:625

References Assert, ObjectAddress::classId, DatumGetObjectId(), elog, ERROR, fb(), get_object_property_data(), HeapTupleIsValid, InvalidAttrNumber, InvalidOid, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and SysCacheGetAttrNotNull().

Referenced by find_temp_object(), and RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)
extern

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)
extern

Definition at line 2708 of file objectaddress.c.

2709{
2711
2712 if (prop->objtype == OBJECT_TABLE)
2713 {
2714 /*
2715 * If the property data says it's a table, dig a little deeper to get
2716 * the real relation kind, so that callers can produce more precise
2717 * error messages.
2718 */
2719 return get_relkind_objtype(get_rel_relkind(object_id));
2720 }
2721 else
2722 return prop->objtype;
2723}
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2153
ObjectType get_relkind_objtype(char relkind)

References fb(), get_object_property_data(), get_rel_relkind(), get_relkind_objtype(), OBJECT_TABLE, and ObjectPropertyType::objtype.

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), ExecGrant_common(), and object_aclmask_ext().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)
extern

Definition at line 6186 of file objectaddress.c.

6187{
6188 switch (relkind)
6189 {
6190 case RELKIND_RELATION:
6192 return OBJECT_TABLE;
6193 case RELKIND_INDEX:
6195 return OBJECT_INDEX;
6196 case RELKIND_SEQUENCE:
6197 return OBJECT_SEQUENCE;
6198 case RELKIND_VIEW:
6199 return OBJECT_VIEW;
6200 case RELKIND_MATVIEW:
6201 return OBJECT_MATVIEW;
6203 return OBJECT_FOREIGN_TABLE;
6204 case RELKIND_TOASTVALUE:
6205 return OBJECT_TABLE;
6206 default:
6207 /* Per above, don't raise an error */
6208 return OBJECT_TABLE;
6209 }
6210}

References fb(), OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, and OBJECT_VIEW.

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTriggerFiringOn(), currtid_internal(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckPermissions(), get_object_type(), heap_force_common(), LockViewRecurse_walker(), LogicalRepSyncTableStart(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDblink(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackForStats(), RangeVarCallbackMaintainsTable(), RangeVarCallbackOwnsRelation(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), TargetPrivilegesCheck(), transformTableLikeClause(), and truncate_check_perms().

◆ getObjectDescription()

char * getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)
extern

Definition at line 2912 of file objectaddress.c.

2913{
2914 StringInfoData buffer;
2915
2916 initStringInfo(&buffer);
2917
2918 switch (object->classId)
2919 {
2920 case RelationRelationId:
2921 if (object->objectSubId == 0)
2922 getRelationDescription(&buffer, object->objectId, missing_ok);
2923 else
2924 {
2925 /* column, not whole relation */
2926 StringInfoData rel;
2927 char *attname = get_attname(object->objectId,
2928 object->objectSubId,
2929 missing_ok);
2930
2931 if (!attname)
2932 break;
2933
2934 initStringInfo(&rel);
2935 getRelationDescription(&rel, object->objectId, missing_ok);
2936 /* translator: second %s is, e.g., "table %s" */
2937 appendStringInfo(&buffer, _("column %s of %s"),
2938 attname, rel.data);
2939 pfree(rel.data);
2940 }
2941 break;
2942
2944 {
2947 flags);
2948
2949 if (proname == NULL)
2950 break;
2951
2952 appendStringInfo(&buffer, _("function %s"), proname);
2953 break;
2954 }
2955
2956 case TypeRelationId:
2957 {
2959 char *typname = format_type_extended(object->objectId, -1,
2960 flags);
2961
2962 if (typname == NULL)
2963 break;
2964
2965 appendStringInfo(&buffer, _("type %s"), typname);
2966 break;
2967 }
2968
2969 case CastRelationId:
2970 {
2972 ScanKeyData skey[1];
2974 HeapTuple tup;
2976
2978
2979 ScanKeyInit(&skey[0],
2982 ObjectIdGetDatum(object->objectId));
2983
2985 NULL, 1, skey);
2986
2988
2989 if (!HeapTupleIsValid(tup))
2990 {
2991 if (!missing_ok)
2992 elog(ERROR, "could not find tuple for cast %u",
2993 object->objectId);
2994
2997 break;
2998 }
2999
3001
3002 appendStringInfo(&buffer, _("cast from %s to %s"),
3003 format_type_be(castForm->castsource),
3004 format_type_be(castForm->casttarget));
3005
3008 break;
3009 }
3010
3012 {
3015 char *nspname;
3016
3018 ObjectIdGetDatum(object->objectId));
3020 {
3021 if (!missing_ok)
3022 elog(ERROR, "cache lookup failed for collation %u",
3023 object->objectId);
3024 break;
3025 }
3026
3028
3029 /* Qualify the name if not visible in search path */
3030 if (CollationIsVisible(object->objectId))
3031 nspname = NULL;
3032 else
3033 nspname = get_namespace_name(coll->collnamespace);
3034
3035 appendStringInfo(&buffer, _("collation %s"),
3037 NameStr(coll->collname)));
3039 break;
3040 }
3041
3043 {
3046
3048 ObjectIdGetDatum(object->objectId));
3050 {
3051 if (!missing_ok)
3052 elog(ERROR, "cache lookup failed for constraint %u",
3053 object->objectId);
3054 break;
3055 }
3056
3058
3059 if (OidIsValid(con->conrelid))
3060 {
3061 StringInfoData rel;
3062
3063 initStringInfo(&rel);
3064 getRelationDescription(&rel, con->conrelid, false);
3065 /* translator: second %s is, e.g., "table %s" */
3066 appendStringInfo(&buffer, _("constraint %s on %s"),
3067 NameStr(con->conname), rel.data);
3068 pfree(rel.data);
3069 }
3070 else
3071 {
3072 appendStringInfo(&buffer, _("constraint %s"),
3073 NameStr(con->conname));
3074 }
3075
3077 break;
3078 }
3079
3081 {
3084 char *nspname;
3085
3087 ObjectIdGetDatum(object->objectId));
3089 {
3090 if (!missing_ok)
3091 elog(ERROR, "cache lookup failed for conversion %u",
3092 object->objectId);
3093 break;
3094 }
3095
3097
3098 /* Qualify the name if not visible in search path */
3099 if (ConversionIsVisible(object->objectId))
3100 nspname = NULL;
3101 else
3102 nspname = get_namespace_name(conv->connamespace);
3103
3104 appendStringInfo(&buffer, _("conversion %s"),
3106 NameStr(conv->conname)));
3108 break;
3109 }
3110
3112 {
3114
3116
3117 if (!OidIsValid(colobject.objectId))
3118 {
3119 if (!missing_ok)
3120 elog(ERROR, "could not find tuple for attrdef %u",
3121 object->objectId);
3122 break;
3123 }
3124
3125 /* translator: %s is typically "column %s of table %s" */
3126 appendStringInfo(&buffer, _("default value for %s"),
3128 break;
3129 }
3130
3131 case LanguageRelationId:
3132 {
3133 char *langname = get_language_name(object->objectId,
3134 missing_ok);
3135
3136 if (langname)
3137 appendStringInfo(&buffer, _("language %s"),
3138 get_language_name(object->objectId, false));
3139 break;
3140 }
3141
3143 if (!LargeObjectExists(object->objectId))
3144 break;
3145 appendStringInfo(&buffer, _("large object %u"),
3146 object->objectId);
3147 break;
3148
3149 case OperatorRelationId:
3150 {
3152 char *oprname = format_operator_extended(object->objectId,
3153 flags);
3154
3155 if (oprname == NULL)
3156 break;
3157
3158 appendStringInfo(&buffer, _("operator %s"), oprname);
3159 break;
3160 }
3161
3163 {
3168 char *nspname;
3169
3171 ObjectIdGetDatum(object->objectId));
3173 {
3174 if (!missing_ok)
3175 elog(ERROR, "cache lookup failed for opclass %u",
3176 object->objectId);
3177 break;
3178 }
3179
3181
3183 ObjectIdGetDatum(opcForm->opcmethod));
3184 if (!HeapTupleIsValid(amTup))
3185 elog(ERROR, "cache lookup failed for access method %u",
3186 opcForm->opcmethod);
3188
3189 /* Qualify the name if not visible in search path */
3190 if (OpclassIsVisible(object->objectId))
3191 nspname = NULL;
3192 else
3193 nspname = get_namespace_name(opcForm->opcnamespace);
3194
3195 appendStringInfo(&buffer, _("operator class %s for access method %s"),
3197 NameStr(opcForm->opcname)),
3198 NameStr(amForm->amname));
3199
3202 break;
3203 }
3204
3206 getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3207 break;
3208
3210 {
3211 HeapTuple tup;
3212
3214 ObjectIdGetDatum(object->objectId));
3215 if (!HeapTupleIsValid(tup))
3216 {
3217 if (!missing_ok)
3218 elog(ERROR, "cache lookup failed for access method %u",
3219 object->objectId);
3220 break;
3221 }
3222
3223 appendStringInfo(&buffer, _("access method %s"),
3224 NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3226 break;
3227 }
3228
3230 {
3232 HeapTuple tup;
3233 ScanKeyData skey[1];
3236 StringInfoData opfam;
3237
3240
3241 ScanKeyInit(&skey[0],
3244 ObjectIdGetDatum(object->objectId));
3245
3247 NULL, 1, skey);
3248
3250
3251 if (!HeapTupleIsValid(tup))
3252 {
3253 if (!missing_ok)
3254 elog(ERROR, "could not find tuple for amop entry %u",
3255 object->objectId);
3256
3259 break;
3260 }
3261
3263
3264 initStringInfo(&opfam);
3265 getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3266
3267 /*
3268 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3269 * completely if the type links are dangling, which is a form
3270 * of catalog corruption that could occur due to old bugs.
3271 */
3272
3273 /*------
3274 translator: %d is the operator strategy (a number), the
3275 first two %s's are data type names, the third %s is the
3276 description of the operator family, and the last %s is the
3277 textual form of the operator with arguments. */
3278 appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3279 amopForm->amopstrategy,
3280 format_type_extended(amopForm->amoplefttype,
3282 format_type_extended(amopForm->amoprighttype,
3284 opfam.data,
3285 format_operator(amopForm->amopopr));
3286
3287 pfree(opfam.data);
3288
3291 break;
3292 }
3293
3295 {
3297 ScanKeyData skey[1];
3299 HeapTuple tup;
3301 StringInfoData opfam;
3302
3305
3306 ScanKeyInit(&skey[0],
3309 ObjectIdGetDatum(object->objectId));
3310
3312 NULL, 1, skey);
3313
3315
3316 if (!HeapTupleIsValid(tup))
3317 {
3318 if (!missing_ok)
3319 elog(ERROR, "could not find tuple for amproc entry %u",
3320 object->objectId);
3321
3324 break;
3325 }
3326
3328
3329 initStringInfo(&opfam);
3330 getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3331
3332 /*
3333 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3334 * completely if the type links are dangling, which is a form
3335 * of catalog corruption that could occur due to old bugs.
3336 */
3337
3338 /*------
3339 translator: %d is the function number, the first two %s's
3340 are data type names, the third %s is the description of the
3341 operator family, and the last %s is the textual form of the
3342 function with arguments. */
3343 appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3344 amprocForm->amprocnum,
3345 format_type_extended(amprocForm->amproclefttype,
3347 format_type_extended(amprocForm->amprocrighttype,
3349 opfam.data,
3350 format_procedure(amprocForm->amproc));
3351
3352 pfree(opfam.data);
3353
3356 break;
3357 }
3358
3359 case RewriteRelationId:
3360 {
3362 ScanKeyData skey[1];
3364 HeapTuple tup;
3366 StringInfoData rel;
3367
3369
3370 ScanKeyInit(&skey[0],
3373 ObjectIdGetDatum(object->objectId));
3374
3376 NULL, 1, skey);
3377
3379
3380 if (!HeapTupleIsValid(tup))
3381 {
3382 if (!missing_ok)
3383 elog(ERROR, "could not find tuple for rule %u",
3384 object->objectId);
3385
3388 break;
3389 }
3390
3392
3393 initStringInfo(&rel);
3394 getRelationDescription(&rel, rule->ev_class, false);
3395
3396 /* translator: second %s is, e.g., "table %s" */
3397 appendStringInfo(&buffer, _("rule %s on %s"),
3398 NameStr(rule->rulename), rel.data);
3399 pfree(rel.data);
3402 break;
3403 }
3404
3405 case TriggerRelationId:
3406 {
3408 ScanKeyData skey[1];
3410 HeapTuple tup;
3412 StringInfoData rel;
3413
3415
3416 ScanKeyInit(&skey[0],
3419 ObjectIdGetDatum(object->objectId));
3420
3422 NULL, 1, skey);
3423
3425
3426 if (!HeapTupleIsValid(tup))
3427 {
3428 if (!missing_ok)
3429 elog(ERROR, "could not find tuple for trigger %u",
3430 object->objectId);
3431
3434 break;
3435 }
3436
3438
3439 initStringInfo(&rel);
3440 getRelationDescription(&rel, trig->tgrelid, false);
3441
3442 /* translator: second %s is, e.g., "table %s" */
3443 appendStringInfo(&buffer, _("trigger %s on %s"),
3444 NameStr(trig->tgname), rel.data);
3445 pfree(rel.data);
3448 break;
3449 }
3450
3452 {
3453 char *nspname;
3454
3455 nspname = get_namespace_name(object->objectId);
3456 if (!nspname)
3457 {
3458 if (!missing_ok)
3459 elog(ERROR, "cache lookup failed for namespace %u",
3460 object->objectId);
3461 break;
3462 }
3463 appendStringInfo(&buffer, _("schema %s"), nspname);
3464 break;
3465 }
3466
3468 {
3471 char *nspname;
3472
3474 ObjectIdGetDatum(object->objectId));
3476 {
3477 if (!missing_ok)
3478 elog(ERROR, "could not find tuple for statistics object %u",
3479 object->objectId);
3480 break;
3481 }
3482
3484
3485 /* Qualify the name if not visible in search path */
3486 if (StatisticsObjIsVisible(object->objectId))
3487 nspname = NULL;
3488 else
3489 nspname = get_namespace_name(stxForm->stxnamespace);
3490
3491 appendStringInfo(&buffer, _("statistics object %s"),
3493 NameStr(stxForm->stxname)));
3494
3496 break;
3497 }
3498
3499 case TSParserRelationId:
3500 {
3501 HeapTuple tup;
3503 char *nspname;
3504
3506 ObjectIdGetDatum(object->objectId));
3507 if (!HeapTupleIsValid(tup))
3508 {
3509 if (!missing_ok)
3510 elog(ERROR, "cache lookup failed for text search parser %u",
3511 object->objectId);
3512 break;
3513 }
3515
3516 /* Qualify the name if not visible in search path */
3517 if (TSParserIsVisible(object->objectId))
3518 nspname = NULL;
3519 else
3520 nspname = get_namespace_name(prsForm->prsnamespace);
3521
3522 appendStringInfo(&buffer, _("text search parser %s"),
3524 NameStr(prsForm->prsname)));
3526 break;
3527 }
3528
3530 {
3531 HeapTuple tup;
3533 char *nspname;
3534
3536 ObjectIdGetDatum(object->objectId));
3537 if (!HeapTupleIsValid(tup))
3538 {
3539 if (!missing_ok)
3540 elog(ERROR, "cache lookup failed for text search dictionary %u",
3541 object->objectId);
3542 break;
3543 }
3544
3546
3547 /* Qualify the name if not visible in search path */
3548 if (TSDictionaryIsVisible(object->objectId))
3549 nspname = NULL;
3550 else
3551 nspname = get_namespace_name(dictForm->dictnamespace);
3552
3553 appendStringInfo(&buffer, _("text search dictionary %s"),
3555 NameStr(dictForm->dictname)));
3557 break;
3558 }
3559
3561 {
3562 HeapTuple tup;
3564 char *nspname;
3565
3567 ObjectIdGetDatum(object->objectId));
3568 if (!HeapTupleIsValid(tup))
3569 {
3570 if (!missing_ok)
3571 elog(ERROR, "cache lookup failed for text search template %u",
3572 object->objectId);
3573 break;
3574 }
3575
3577
3578 /* Qualify the name if not visible in search path */
3579 if (TSTemplateIsVisible(object->objectId))
3580 nspname = NULL;
3581 else
3582 nspname = get_namespace_name(tmplForm->tmplnamespace);
3583
3584 appendStringInfo(&buffer, _("text search template %s"),
3586 NameStr(tmplForm->tmplname)));
3588 break;
3589 }
3590
3591 case TSConfigRelationId:
3592 {
3593 HeapTuple tup;
3595 char *nspname;
3596
3598 ObjectIdGetDatum(object->objectId));
3599 if (!HeapTupleIsValid(tup))
3600 {
3601 if (!missing_ok)
3602 elog(ERROR, "cache lookup failed for text search configuration %u",
3603 object->objectId);
3604 break;
3605 }
3606
3608
3609 /* Qualify the name if not visible in search path */
3610 if (TSConfigIsVisible(object->objectId))
3611 nspname = NULL;
3612 else
3613 nspname = get_namespace_name(cfgForm->cfgnamespace);
3614
3615 appendStringInfo(&buffer, _("text search configuration %s"),
3617 NameStr(cfgForm->cfgname)));
3619 break;
3620 }
3621
3622 case AuthIdRelationId:
3623 {
3624 char *username = GetUserNameFromId(object->objectId,
3625 missing_ok);
3626
3627 if (username)
3628 appendStringInfo(&buffer, _("role %s"), username);
3629 break;
3630 }
3631
3632 case AuthMemRelationId:
3633 {
3635 ScanKeyData skey[1];
3637 HeapTuple tup;
3639
3641
3642 ScanKeyInit(&skey[0],
3645 ObjectIdGetDatum(object->objectId));
3646
3648 NULL, 1, skey);
3649
3651
3652 if (!HeapTupleIsValid(tup))
3653 {
3654 if (!missing_ok)
3655 elog(ERROR, "could not find tuple for role membership %u",
3656 object->objectId);
3657
3660 break;
3661 }
3662
3664
3665 appendStringInfo(&buffer, _("membership of role %s in role %s"),
3666 GetUserNameFromId(amForm->member, false),
3667 GetUserNameFromId(amForm->roleid, false));
3668
3671 break;
3672 }
3673
3674 case DatabaseRelationId:
3675 {
3676 char *datname;
3677
3679 if (!datname)
3680 {
3681 if (!missing_ok)
3682 elog(ERROR, "cache lookup failed for database %u",
3683 object->objectId);
3684 break;
3685 }
3686 appendStringInfo(&buffer, _("database %s"), datname);
3687 break;
3688 }
3689
3691 {
3692 char *tblspace;
3693
3695 if (!tblspace)
3696 {
3697 if (!missing_ok)
3698 elog(ERROR, "cache lookup failed for tablespace %u",
3699 object->objectId);
3700 break;
3701 }
3702 appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3703 break;
3704 }
3705
3707 {
3709
3711 missing_ok);
3712 if (fdw)
3713 appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3714 break;
3715 }
3716
3718 {
3720
3721 srv = GetForeignServerExtended(object->objectId, missing_ok);
3722 if (srv)
3723 appendStringInfo(&buffer, _("server %s"), srv->servername);
3724 break;
3725 }
3726
3728 {
3729 HeapTuple tup;
3730 Oid useid;
3731 char *usename;
3734
3736 ObjectIdGetDatum(object->objectId));
3737 if (!HeapTupleIsValid(tup))
3738 {
3739 if (!missing_ok)
3740 elog(ERROR, "cache lookup failed for user mapping %u",
3741 object->objectId);
3742 break;
3743 }
3744
3746 useid = umform->umuser;
3747 srv = GetForeignServer(umform->umserver);
3748
3750
3751 if (OidIsValid(useid))
3753 else
3754 usename = "public";
3755
3756 appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3757 srv->servername);
3758 break;
3759 }
3760
3762 {
3764 ScanKeyData skey[1];
3766 HeapTuple tup;
3768 char *rolename;
3769 char *nspname;
3770
3772
3773 ScanKeyInit(&skey[0],
3776 ObjectIdGetDatum(object->objectId));
3777
3779 true, NULL, 1, skey);
3780
3782
3783 if (!HeapTupleIsValid(tup))
3784 {
3785 if (!missing_ok)
3786 elog(ERROR, "could not find tuple for default ACL %u",
3787 object->objectId);
3788
3791 break;
3792 }
3793
3795
3796 rolename = GetUserNameFromId(defacl->defaclrole, false);
3797
3798 if (OidIsValid(defacl->defaclnamespace))
3799 nspname = get_namespace_name(defacl->defaclnamespace);
3800 else
3801 nspname = NULL;
3802
3803 switch (defacl->defaclobjtype)
3804 {
3805 case DEFACLOBJ_RELATION:
3806 if (nspname)
3807 appendStringInfo(&buffer,
3808 _("default privileges on new relations belonging to role %s in schema %s"),
3809 rolename, nspname);
3810 else
3811 appendStringInfo(&buffer,
3812 _("default privileges on new relations belonging to role %s"),
3813 rolename);
3814 break;
3815 case DEFACLOBJ_SEQUENCE:
3816 if (nspname)
3817 appendStringInfo(&buffer,
3818 _("default privileges on new sequences belonging to role %s in schema %s"),
3819 rolename, nspname);
3820 else
3821 appendStringInfo(&buffer,
3822 _("default privileges on new sequences belonging to role %s"),
3823 rolename);
3824 break;
3825 case DEFACLOBJ_FUNCTION:
3826 if (nspname)
3827 appendStringInfo(&buffer,
3828 _("default privileges on new functions belonging to role %s in schema %s"),
3829 rolename, nspname);
3830 else
3831 appendStringInfo(&buffer,
3832 _("default privileges on new functions belonging to role %s"),
3833 rolename);
3834 break;
3835 case DEFACLOBJ_TYPE:
3836 if (nspname)
3837 appendStringInfo(&buffer,
3838 _("default privileges on new types belonging to role %s in schema %s"),
3839 rolename, nspname);
3840 else
3841 appendStringInfo(&buffer,
3842 _("default privileges on new types belonging to role %s"),
3843 rolename);
3844 break;
3846 Assert(!nspname);
3847 appendStringInfo(&buffer,
3848 _("default privileges on new schemas belonging to role %s"),
3849 rolename);
3850 break;
3852 Assert(!nspname);
3853 appendStringInfo(&buffer,
3854 _("default privileges on new large objects belonging to role %s"),
3855 rolename);
3856 break;
3857 default:
3858 /* shouldn't get here */
3859 if (nspname)
3860 appendStringInfo(&buffer,
3861 _("default privileges belonging to role %s in schema %s"),
3862 rolename, nspname);
3863 else
3864 appendStringInfo(&buffer,
3865 _("default privileges belonging to role %s"),
3866 rolename);
3867 break;
3868 }
3869
3872 break;
3873 }
3874
3876 {
3877 char *extname;
3878
3879 extname = get_extension_name(object->objectId);
3880 if (!extname)
3881 {
3882 if (!missing_ok)
3883 elog(ERROR, "cache lookup failed for extension %u",
3884 object->objectId);
3885 break;
3886 }
3887 appendStringInfo(&buffer, _("extension %s"), extname);
3888 break;
3889 }
3890
3892 {
3893 HeapTuple tup;
3894
3896 ObjectIdGetDatum(object->objectId));
3897 if (!HeapTupleIsValid(tup))
3898 {
3899 if (!missing_ok)
3900 elog(ERROR, "cache lookup failed for event trigger %u",
3901 object->objectId);
3902 break;
3903 }
3904 appendStringInfo(&buffer, _("event trigger %s"),
3907 break;
3908 }
3909
3911 {
3912 HeapTuple tup;
3914 char *parname;
3915
3917 ObjectIdGetDatum(object->objectId));
3918 if (!HeapTupleIsValid(tup))
3919 {
3920 if (!missing_ok)
3921 elog(ERROR, "cache lookup failed for parameter ACL %u",
3922 object->objectId);
3923 break;
3924 }
3928 appendStringInfo(&buffer, _("parameter %s"), parname);
3930 break;
3931 }
3932
3933 case PolicyRelationId:
3934 {
3936 ScanKeyData skey[1];
3938 HeapTuple tuple;
3940 StringInfoData rel;
3941
3943
3944 ScanKeyInit(&skey[0],
3947 ObjectIdGetDatum(object->objectId));
3948
3950 true, NULL, 1, skey);
3951
3952 tuple = systable_getnext(sscan);
3953
3954 if (!HeapTupleIsValid(tuple))
3955 {
3956 if (!missing_ok)
3957 elog(ERROR, "could not find tuple for policy %u",
3958 object->objectId);
3959
3962 break;
3963 }
3964
3966
3967 initStringInfo(&rel);
3968 getRelationDescription(&rel, form_policy->polrelid, false);
3969
3970 /* translator: second %s is, e.g., "table %s" */
3971 appendStringInfo(&buffer, _("policy %s on %s"),
3972 NameStr(form_policy->polname), rel.data);
3973 pfree(rel.data);
3976 break;
3977 }
3978
3980 {
3981 char *pubname = get_publication_name(object->objectId,
3982 missing_ok);
3983
3984 if (pubname)
3985 appendStringInfo(&buffer, _("publication %s"), pubname);
3986 break;
3987 }
3988
3990 {
3991 char *pubname;
3992 char *nspname;
3993
3994 if (!getPublicationSchemaInfo(object, missing_ok,
3995 &pubname, &nspname))
3996 break;
3997
3998 appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
3999 nspname, pubname);
4000 pfree(pubname);
4001 pfree(nspname);
4002 break;
4003 }
4004
4006 {
4007 HeapTuple tup;
4008 char *pubname;
4010 StringInfoData rel;
4011
4013 ObjectIdGetDatum(object->objectId));
4014 if (!HeapTupleIsValid(tup))
4015 {
4016 if (!missing_ok)
4017 elog(ERROR, "cache lookup failed for publication table %u",
4018 object->objectId);
4019 break;
4020 }
4021
4023 pubname = get_publication_name(prform->prpubid, false);
4024
4025 initStringInfo(&rel);
4026 getRelationDescription(&rel, prform->prrelid, false);
4027
4028 /* translator: first %s is, e.g., "table %s" */
4029 appendStringInfo(&buffer, _("publication of %s in publication %s"),
4030 rel.data, pubname);
4031 pfree(rel.data);
4033 break;
4034 }
4035
4037 {
4038 char *subname = get_subscription_name(object->objectId,
4039 missing_ok);
4040
4041 if (subname)
4042 appendStringInfo(&buffer, _("subscription %s"), subname);
4043 break;
4044 }
4045
4047 {
4050
4052 ObjectIdGetDatum(object->objectId));
4054 {
4055 if (!missing_ok)
4056 elog(ERROR, "could not find tuple for transform %u",
4057 object->objectId);
4058 break;
4059 }
4060
4062
4063 appendStringInfo(&buffer, _("transform for %s language %s"),
4064 format_type_be(trfForm->trftype),
4065 get_language_name(trfForm->trflang, false));
4066
4068 break;
4069 }
4070
4071 default:
4072 elog(ERROR, "unsupported object class: %u", object->classId);
4073 }
4074
4075 /* an empty buffer is equivalent to no object found */
4076 if (buffer.len == 0)
4077 return NULL;
4078
4079 return buffer.data;
4080}
char * get_tablespace_name(Oid spc_oid)
#define FORMAT_TYPE_ALLOW_INVALID
Definition builtins.h:126
#define TextDatumGetCString(d)
Definition builtins.h:99
#define FORMAT_TYPE_INVALID_AS_NULL
Definition builtins.h:128
#define NameStr(name)
Definition c.h:777
uint16 bits16
Definition c.h:566
#define _(x)
Definition elog.c:95
char * get_extension_name(Oid ext_oid)
Definition extension.c:250
ForeignServer * GetForeignServer(Oid serverid)
Definition foreign.c:112
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition foreign.c:50
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition foreign.c:124
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
static char * username
Definition initdb.c:153
#define AccessShareLock
Definition lockdefs.h:36
char * get_database_name(Oid dbid)
Definition lsyscache.c:1242
char * get_language_name(Oid langoid, bool missing_ok)
Definition lsyscache.c:1263
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:903
char * get_subscription_name(Oid subid, bool missing_ok)
Definition lsyscache.c:3847
char * get_publication_name(Oid pubid, bool missing_ok)
Definition lsyscache.c:3797
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3518
void pfree(void *pointer)
Definition mcxt.c:1616
bool TSTemplateIsVisible(Oid tmplId)
Definition namespace.c:3137
bool CollationIsVisible(Oid collid)
Definition namespace.c:2476
bool ConversionIsVisible(Oid conid)
Definition namespace.c:2578
bool OpclassIsVisible(Oid opcid)
Definition namespace.c:2223
bool TSParserIsVisible(Oid prsId)
Definition namespace.c:2846
bool TSConfigIsVisible(Oid cfgid)
Definition namespace.c:3282
bool StatisticsObjIsVisible(Oid stxid)
Definition namespace.c:2701
bool TSDictionaryIsVisible(Oid dictId)
Definition namespace.c:2991
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
static bool getPublicationSchemaInfo(const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
END_CATALOG_STRUCT typedef FormData_pg_am * Form_pg_am
Definition pg_am.h:52
END_CATALOG_STRUCT typedef FormData_pg_amop * Form_pg_amop
Definition pg_amop.h:92
END_CATALOG_STRUCT typedef FormData_pg_amproc * Form_pg_amproc
Definition pg_amproc.h:72
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
Definition pg_attrdef.c:322
NameData attname
END_CATALOG_STRUCT typedef FormData_pg_auth_members * Form_pg_auth_members
END_CATALOG_STRUCT typedef FormData_pg_cast * Form_pg_cast
Definition pg_cast.h:61
END_CATALOG_STRUCT typedef FormData_pg_collation * Form_pg_collation
END_CATALOG_STRUCT typedef FormData_pg_conversion * Form_pg_conversion
NameData datname
Definition pg_database.h:37
END_CATALOG_STRUCT typedef FormData_pg_default_acl * Form_pg_default_acl
END_CATALOG_STRUCT typedef FormData_pg_event_trigger * Form_pg_event_trigger
END_CATALOG_STRUCT typedef FormData_pg_opclass * Form_pg_opclass
Definition pg_opclass.h:87
END_CATALOG_STRUCT typedef FormData_pg_policy * Form_pg_policy
Definition pg_policy.h:55
NameData proname
Definition pg_proc.h:37
END_CATALOG_STRUCT typedef FormData_pg_publication_rel * Form_pg_publication_rel
END_CATALOG_STRUCT typedef FormData_pg_rewrite * Form_pg_rewrite
Definition pg_rewrite.h:56
END_CATALOG_STRUCT typedef FormData_pg_statistic_ext * Form_pg_statistic_ext
NameData subname
END_CATALOG_STRUCT typedef FormData_pg_transform * Form_pg_transform
END_CATALOG_STRUCT typedef FormData_pg_trigger * Form_pg_trigger
Definition pg_trigger.h:84
END_CATALOG_STRUCT typedef FormData_pg_ts_config * Form_pg_ts_config
END_CATALOG_STRUCT typedef FormData_pg_ts_dict * Form_pg_ts_dict
Definition pg_ts_dict.h:56
END_CATALOG_STRUCT typedef FormData_pg_ts_parser * Form_pg_ts_parser
END_CATALOG_STRUCT typedef FormData_pg_ts_template * Form_pg_ts_template
NameData typname
Definition pg_type.h:43
END_CATALOG_STRUCT typedef FormData_pg_user_mapping * Form_pg_user_mapping
uint64_t Datum
Definition postgres.h:70
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition regproc.c:332
char * format_procedure(Oid procedure_oid)
Definition regproc.c:305
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition regproc.c:730
char * format_operator(Oid operator_oid)
Definition regproc.c:801
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition regproc.h:24
#define FORMAT_PROC_INVALID_AS_NULL
Definition regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References _, AccessShareLock, appendStringInfo(), Assert, attname, BTEqualStrategyNumber, ObjectAddress::classId, CollationIsVisible(), ConversionIsVisible(), StringInfoData::data, datname, elog, ERROR, fb(), Form_pg_am, Form_pg_amop, Form_pg_amproc, Form_pg_auth_members, Form_pg_cast, Form_pg_collation, Form_pg_constraint, Form_pg_conversion, Form_pg_default_acl, Form_pg_event_trigger, Form_pg_opclass, Form_pg_policy, Form_pg_publication_rel, Form_pg_rewrite, Form_pg_statistic_ext, Form_pg_transform, Form_pg_trigger, Form_pg_ts_config, Form_pg_ts_dict, Form_pg_ts_parser, Form_pg_ts_template, Form_pg_user_mapping, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), FORMAT_TYPE_ALLOW_INVALID, format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectDescription(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT(), GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, OpclassIsVisible(), pfree(), proname, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), StatisticsObjIsVisible(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typname, and username.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependenciesOn(), check_relation_privileges(), checkMembershipInCurrentExtension(), checkSharedDependencies(), DefineView(), ExecAlterExtensionContentsRecurse(), findDependentObjects(), get_altertable_subcmdinfo(), get_object_address_opf_member(), getObjectDescription(), getObjectDescriptionOids(), pg_describe_object(), ProcedureCreate(), recordDependencyOnCurrentExtension(), RememberAllDependentForRebuilding(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), storeObjectDescription(), and transformCreateTableAsStmt().

◆ getObjectDescriptionOids()

char * getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)
extern

Definition at line 4086 of file objectaddress.c.

4087{
4088 ObjectAddress address;
4089
4090 address.classId = classid;
4091 address.objectId = objid;
4092 address.objectSubId = 0;
4093
4094 return getObjectDescription(&address, false);
4095}

References ObjectAddress::classId, getObjectDescription(), ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ getObjectIdentity()

◆ getObjectIdentityParts()

char * getObjectIdentityParts ( const ObjectAddress object,
List **  objname,
List **  objargs,
bool  missing_ok 
)
extern

Definition at line 4839 of file objectaddress.c.

4842{
4843 StringInfoData buffer;
4844
4845 initStringInfo(&buffer);
4846
4847 /*
4848 * Make sure that both objname and objargs were passed, or none was; and
4849 * initialize them to empty lists. For objname this is useless because it
4850 * will be initialized in all cases inside the switch; but we do it anyway
4851 * so that we can test below that no branch leaves it unset.
4852 */
4853 Assert((objname != NULL) == (objargs != NULL));
4854 if (objname)
4855 {
4856 *objname = NIL;
4857 *objargs = NIL;
4858 }
4859
4860 switch (object->classId)
4861 {
4862 case RelationRelationId:
4863 {
4864 char *attr = NULL;
4865
4866 /*
4867 * Check for the attribute first, so as if it is missing we
4868 * can skip the entire relation description.
4869 */
4870 if (object->objectSubId != 0)
4871 {
4872 attr = get_attname(object->objectId,
4873 object->objectSubId,
4874 missing_ok);
4875
4876 if (missing_ok && attr == NULL)
4877 break;
4878 }
4879
4880 getRelationIdentity(&buffer, object->objectId, objname,
4881 missing_ok);
4882 if (objname && *objname == NIL)
4883 break;
4884
4885 if (attr)
4886 {
4887 appendStringInfo(&buffer, ".%s",
4888 quote_identifier(attr));
4889 if (objname)
4890 *objname = lappend(*objname, attr);
4891 }
4892 }
4893 break;
4894
4896 {
4899 flags);
4900
4901 if (proname == NULL)
4902 break;
4903
4905 if (objname)
4906 format_procedure_parts(object->objectId, objname, objargs,
4907 missing_ok);
4908 break;
4909 }
4910
4911 case TypeRelationId:
4912 {
4914 char *typeout;
4915
4916 typeout = format_type_extended(object->objectId, -1, flags);
4917
4918 if (typeout == NULL)
4919 break;
4920
4922 if (objname)
4923 *objname = list_make1(typeout);
4924 }
4925 break;
4926
4927 case CastRelationId:
4928 {
4930 HeapTuple tup;
4932
4934
4936 object->objectId);
4937
4938 if (!HeapTupleIsValid(tup))
4939 {
4940 if (!missing_ok)
4941 elog(ERROR, "could not find tuple for cast %u",
4942 object->objectId);
4943
4945 break;
4946 }
4947
4949
4950 appendStringInfo(&buffer, "(%s AS %s)",
4952 format_type_be_qualified(castForm->casttarget));
4953
4954 if (objname)
4955 {
4956 *objname = list_make1(format_type_be_qualified(castForm->castsource));
4957 *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4958 }
4959
4961 break;
4962 }
4963
4965 {
4968 char *schema;
4969
4971 ObjectIdGetDatum(object->objectId));
4973 {
4974 if (!missing_ok)
4975 elog(ERROR, "cache lookup failed for collation %u",
4976 object->objectId);
4977 break;
4978 }
4980 schema = get_namespace_name_or_temp(coll->collnamespace);
4981 appendStringInfoString(&buffer,
4983 NameStr(coll->collname)));
4984 if (objname)
4985 *objname = list_make2(schema,
4986 pstrdup(NameStr(coll->collname)));
4988 break;
4989 }
4990
4992 {
4995
4997 ObjectIdGetDatum(object->objectId));
4999 {
5000 if (!missing_ok)
5001 elog(ERROR, "cache lookup failed for constraint %u",
5002 object->objectId);
5003 break;
5004 }
5006
5007 if (OidIsValid(con->conrelid))
5008 {
5009 appendStringInfo(&buffer, "%s on ",
5010 quote_identifier(NameStr(con->conname)));
5011 getRelationIdentity(&buffer, con->conrelid, objname,
5012 false);
5013 if (objname)
5014 *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
5015 }
5016 else
5017 {
5018 ObjectAddress domain;
5019
5020 Assert(OidIsValid(con->contypid));
5021 domain.classId = TypeRelationId;
5022 domain.objectId = con->contypid;
5023 domain.objectSubId = 0;
5024
5025 appendStringInfo(&buffer, "%s on %s",
5026 quote_identifier(NameStr(con->conname)),
5027 getObjectIdentityParts(&domain, objname,
5028 objargs, false));
5029
5030 if (objname)
5031 *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
5032 }
5033
5035 break;
5036 }
5037
5039 {
5042 char *schema;
5043
5045 ObjectIdGetDatum(object->objectId));
5047 {
5048 if (!missing_ok)
5049 elog(ERROR, "cache lookup failed for conversion %u",
5050 object->objectId);
5051 break;
5052 }
5054 schema = get_namespace_name_or_temp(conForm->connamespace);
5055 appendStringInfoString(&buffer,
5057 NameStr(conForm->conname)));
5058 if (objname)
5059 *objname = list_make2(schema,
5060 pstrdup(NameStr(conForm->conname)));
5062 break;
5063 }
5064
5066 {
5068
5070
5071 if (!OidIsValid(colobject.objectId))
5072 {
5073 if (!missing_ok)
5074 elog(ERROR, "could not find tuple for attrdef %u",
5075 object->objectId);
5076 break;
5077 }
5078
5079 appendStringInfo(&buffer, "for %s",
5081 objname, objargs,
5082 false));
5083 break;
5084 }
5085
5086 case LanguageRelationId:
5087 {
5090
5092 ObjectIdGetDatum(object->objectId));
5094 {
5095 if (!missing_ok)
5096 elog(ERROR, "cache lookup failed for language %u",
5097 object->objectId);
5098 break;
5099 }
5101 appendStringInfoString(&buffer,
5102 quote_identifier(NameStr(langForm->lanname)));
5103 if (objname)
5104 *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5106 break;
5107 }
5108
5110 if (!LargeObjectExists(object->objectId))
5111 break;
5112 appendStringInfo(&buffer, "%u",
5113 object->objectId);
5114 if (objname)
5115 *objname = list_make1(psprintf("%u", object->objectId));
5116 break;
5117
5118 case OperatorRelationId:
5119 {
5121 char *oprname = format_operator_extended(object->objectId,
5122 flags);
5123
5124 if (oprname == NULL)
5125 break;
5126
5127 appendStringInfoString(&buffer, oprname);
5128 if (objname)
5129 format_operator_parts(object->objectId, objname, objargs, missing_ok);
5130 break;
5131 }
5132
5134 {
5139 char *schema;
5140
5142 ObjectIdGetDatum(object->objectId));
5144 {
5145 if (!missing_ok)
5146 elog(ERROR, "cache lookup failed for opclass %u",
5147 object->objectId);
5148 break;
5149 }
5151 schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5152
5154 ObjectIdGetDatum(opcForm->opcmethod));
5155 if (!HeapTupleIsValid(amTup))
5156 elog(ERROR, "cache lookup failed for access method %u",
5157 opcForm->opcmethod);
5159
5160 appendStringInfo(&buffer, "%s USING %s",
5162 NameStr(opcForm->opcname)),
5163 quote_identifier(NameStr(amForm->amname)));
5164 if (objname)
5165 *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5166 schema,
5167 pstrdup(NameStr(opcForm->opcname)));
5168
5171 break;
5172 }
5173
5175 getOpFamilyIdentity(&buffer, object->objectId, objname,
5176 missing_ok);
5177 break;
5178
5180 {
5181 char *amname;
5182
5183 amname = get_am_name(object->objectId);
5184 if (!amname)
5185 {
5186 if (!missing_ok)
5187 elog(ERROR, "cache lookup failed for access method %u",
5188 object->objectId);
5189 break;
5190 }
5191 appendStringInfoString(&buffer, quote_identifier(amname));
5192 if (objname)
5193 *objname = list_make1(amname);
5194 }
5195 break;
5196
5198 {
5200 HeapTuple tup;
5201 ScanKeyData skey[1];
5204 StringInfoData opfam;
5205 char *ltype;
5206 char *rtype;
5207
5210
5211 ScanKeyInit(&skey[0],
5214 ObjectIdGetDatum(object->objectId));
5215
5217 NULL, 1, skey);
5218
5220
5221 if (!HeapTupleIsValid(tup))
5222 {
5223 if (!missing_ok)
5224 elog(ERROR, "could not find tuple for amop entry %u",
5225 object->objectId);
5226
5229 break;
5230 }
5231
5233
5234 initStringInfo(&opfam);
5235 getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5236 false);
5237
5238 ltype = format_type_be_qualified(amopForm->amoplefttype);
5239 rtype = format_type_be_qualified(amopForm->amoprighttype);
5240
5241 if (objname)
5242 {
5243 *objname = lappend(*objname,
5244 psprintf("%d", amopForm->amopstrategy));
5245 *objargs = list_make2(ltype, rtype);
5246 }
5247
5248 appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5249 amopForm->amopstrategy,
5250 ltype, rtype, opfam.data);
5251
5252 pfree(opfam.data);
5253
5256 break;
5257 }
5258
5260 {
5262 ScanKeyData skey[1];
5264 HeapTuple tup;
5266 StringInfoData opfam;
5267 char *ltype;
5268 char *rtype;
5269
5272
5273 ScanKeyInit(&skey[0],
5276 ObjectIdGetDatum(object->objectId));
5277
5279 NULL, 1, skey);
5280
5282
5283 if (!HeapTupleIsValid(tup))
5284 {
5285 if (!missing_ok)
5286 elog(ERROR, "could not find tuple for amproc entry %u",
5287 object->objectId);
5288
5291 break;
5292 }
5293
5295
5296 initStringInfo(&opfam);
5297 getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5298 false);
5299
5300 ltype = format_type_be_qualified(amprocForm->amproclefttype);
5301 rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5302
5303 if (objname)
5304 {
5305 *objname = lappend(*objname,
5306 psprintf("%d", amprocForm->amprocnum));
5307 *objargs = list_make2(ltype, rtype);
5308 }
5309
5310 appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5311 amprocForm->amprocnum,
5312 ltype, rtype, opfam.data);
5313
5314 pfree(opfam.data);
5315
5318 break;
5319 }
5320
5321 case RewriteRelationId:
5322 {
5324 HeapTuple tup;
5326
5328
5330 object->objectId);
5331
5332 if (!HeapTupleIsValid(tup))
5333 {
5334 if (!missing_ok)
5335 elog(ERROR, "could not find tuple for rule %u",
5336 object->objectId);
5337
5339 break;
5340 }
5341
5343
5344 appendStringInfo(&buffer, "%s on ",
5345 quote_identifier(NameStr(rule->rulename)));
5346 getRelationIdentity(&buffer, rule->ev_class, objname, false);
5347 if (objname)
5348 *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5349
5351 break;
5352 }
5353
5354 case TriggerRelationId:
5355 {
5357 HeapTuple tup;
5359
5361
5363 object->objectId);
5364
5365 if (!HeapTupleIsValid(tup))
5366 {
5367 if (!missing_ok)
5368 elog(ERROR, "could not find tuple for trigger %u",
5369 object->objectId);
5370
5372 break;
5373 }
5374
5376
5377 appendStringInfo(&buffer, "%s on ",
5378 quote_identifier(NameStr(trig->tgname)));
5379 getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5380 if (objname)
5381 *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5382
5384 break;
5385 }
5386
5388 {
5389 char *nspname;
5390
5391 nspname = get_namespace_name_or_temp(object->objectId);
5392 if (!nspname)
5393 {
5394 if (!missing_ok)
5395 elog(ERROR, "cache lookup failed for namespace %u",
5396 object->objectId);
5397 break;
5398 }
5399 appendStringInfoString(&buffer,
5400 quote_identifier(nspname));
5401 if (objname)
5402 *objname = list_make1(nspname);
5403 break;
5404 }
5405
5407 {
5408 HeapTuple tup;
5410 char *schema;
5411
5413 ObjectIdGetDatum(object->objectId));
5414 if (!HeapTupleIsValid(tup))
5415 {
5416 if (!missing_ok)
5417 elog(ERROR, "cache lookup failed for statistics object %u",
5418 object->objectId);
5419 break;
5420 }
5422 schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5423 appendStringInfoString(&buffer,
5425 NameStr(formStatistic->stxname)));
5426 if (objname)
5427 *objname = list_make2(schema,
5428 pstrdup(NameStr(formStatistic->stxname)));
5430 }
5431 break;
5432
5433 case TSParserRelationId:
5434 {
5435 HeapTuple tup;
5437 char *schema;
5438
5440 ObjectIdGetDatum(object->objectId));
5441 if (!HeapTupleIsValid(tup))
5442 {
5443 if (!missing_ok)
5444 elog(ERROR, "cache lookup failed for text search parser %u",
5445 object->objectId);
5446 break;
5447 }
5449 schema = get_namespace_name_or_temp(formParser->prsnamespace);
5450 appendStringInfoString(&buffer,
5452 NameStr(formParser->prsname)));
5453 if (objname)
5454 *objname = list_make2(schema,
5455 pstrdup(NameStr(formParser->prsname)));
5457 break;
5458 }
5459
5461 {
5462 HeapTuple tup;
5464 char *schema;
5465
5467 ObjectIdGetDatum(object->objectId));
5468 if (!HeapTupleIsValid(tup))
5469 {
5470 if (!missing_ok)
5471 elog(ERROR, "cache lookup failed for text search dictionary %u",
5472 object->objectId);
5473 break;
5474 }
5476 schema = get_namespace_name_or_temp(formDict->dictnamespace);
5477 appendStringInfoString(&buffer,
5479 NameStr(formDict->dictname)));
5480 if (objname)
5481 *objname = list_make2(schema,
5482 pstrdup(NameStr(formDict->dictname)));
5484 break;
5485 }
5486
5488 {
5489 HeapTuple tup;
5491 char *schema;
5492
5494 ObjectIdGetDatum(object->objectId));
5495 if (!HeapTupleIsValid(tup))
5496 {
5497 if (!missing_ok)
5498 elog(ERROR, "cache lookup failed for text search template %u",
5499 object->objectId);
5500 break;
5501 }
5503 schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5504 appendStringInfoString(&buffer,
5506 NameStr(formTmpl->tmplname)));
5507 if (objname)
5508 *objname = list_make2(schema,
5509 pstrdup(NameStr(formTmpl->tmplname)));
5511 break;
5512 }
5513
5514 case TSConfigRelationId:
5515 {
5516 HeapTuple tup;
5518 char *schema;
5519
5521 ObjectIdGetDatum(object->objectId));
5522 if (!HeapTupleIsValid(tup))
5523 {
5524 if (!missing_ok)
5525 elog(ERROR, "cache lookup failed for text search configuration %u",
5526 object->objectId);
5527 break;
5528 }
5530 schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5531 appendStringInfoString(&buffer,
5533 NameStr(formCfg->cfgname)));
5534 if (objname)
5535 *objname = list_make2(schema,
5536 pstrdup(NameStr(formCfg->cfgname)));
5538 break;
5539 }
5540
5541 case AuthIdRelationId:
5542 {
5543 char *username;
5544
5545 username = GetUserNameFromId(object->objectId, missing_ok);
5546 if (!username)
5547 break;
5548 if (objname)
5549 *objname = list_make1(username);
5550 appendStringInfoString(&buffer,
5552 break;
5553 }
5554
5555 case AuthMemRelationId:
5556 {
5558 ScanKeyData skey[1];
5560 HeapTuple tup;
5562
5565
5566 ScanKeyInit(&skey[0],
5569 ObjectIdGetDatum(object->objectId));
5570
5572 NULL, 1, skey);
5573
5575
5576 if (!HeapTupleIsValid(tup))
5577 {
5578 if (!missing_ok)
5579 elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5580 object->objectId);
5581
5584 break;
5585 }
5586
5588
5589 appendStringInfo(&buffer, _("membership of role %s in role %s"),
5590 GetUserNameFromId(amForm->member, false),
5591 GetUserNameFromId(amForm->roleid, false));
5592
5595 break;
5596 }
5597
5598 case DatabaseRelationId:
5599 {
5600 char *datname;
5601
5603 if (!datname)
5604 {
5605 if (!missing_ok)
5606 elog(ERROR, "cache lookup failed for database %u",
5607 object->objectId);
5608 break;
5609 }
5610 if (objname)
5611 *objname = list_make1(datname);
5612 appendStringInfoString(&buffer,
5614 break;
5615 }
5616
5618 {
5619 char *tblspace;
5620
5622 if (!tblspace)
5623 {
5624 if (!missing_ok)
5625 elog(ERROR, "cache lookup failed for tablespace %u",
5626 object->objectId);
5627 break;
5628 }
5629 if (objname)
5630 *objname = list_make1(tblspace);
5631 appendStringInfoString(&buffer,
5633 break;
5634 }
5635
5637 {
5639
5641 missing_ok);
5642 if (fdw)
5643 {
5644 appendStringInfoString(&buffer, quote_identifier(fdw->fdwname));
5645 if (objname)
5646 *objname = list_make1(pstrdup(fdw->fdwname));
5647 }
5648 break;
5649 }
5650
5652 {
5654
5656 missing_ok);
5657 if (srv)
5658 {
5659 appendStringInfoString(&buffer,
5660 quote_identifier(srv->servername));
5661 if (objname)
5662 *objname = list_make1(pstrdup(srv->servername));
5663 }
5664 break;
5665 }
5666
5668 {
5669 HeapTuple tup;
5670 Oid useid;
5673 const char *usename;
5674
5676 ObjectIdGetDatum(object->objectId));
5677 if (!HeapTupleIsValid(tup))
5678 {
5679 if (!missing_ok)
5680 elog(ERROR, "cache lookup failed for user mapping %u",
5681 object->objectId);
5682 break;
5683 }
5685 useid = umform->umuser;
5686 srv = GetForeignServer(umform->umserver);
5687
5689
5690 if (OidIsValid(useid))
5692 else
5693 usename = "public";
5694
5695 if (objname)
5696 {
5697 *objname = list_make1(pstrdup(usename));
5698 *objargs = list_make1(pstrdup(srv->servername));
5699 }
5700
5701 appendStringInfo(&buffer, "%s on server %s",
5703 srv->servername);
5704 break;
5705 }
5706
5708 {
5710 ScanKeyData skey[1];
5712 HeapTuple tup;
5714 char *schema;
5715 char *username;
5716
5718
5719 ScanKeyInit(&skey[0],
5722 ObjectIdGetDatum(object->objectId));
5723
5725 true, NULL, 1, skey);
5726
5728
5729 if (!HeapTupleIsValid(tup))
5730 {
5731 if (!missing_ok)
5732 elog(ERROR, "could not find tuple for default ACL %u",
5733 object->objectId);
5734
5737 break;
5738 }
5739
5741
5742 username = GetUserNameFromId(defacl->defaclrole, false);
5743 appendStringInfo(&buffer,
5744 "for role %s",
5746
5747 if (OidIsValid(defacl->defaclnamespace))
5748 {
5749 schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5750 appendStringInfo(&buffer,
5751 " in schema %s",
5752 quote_identifier(schema));
5753 }
5754 else
5755 schema = NULL;
5756
5757 switch (defacl->defaclobjtype)
5758 {
5759 case DEFACLOBJ_RELATION:
5760 appendStringInfoString(&buffer,
5761 " on tables");
5762 break;
5763 case DEFACLOBJ_SEQUENCE:
5764 appendStringInfoString(&buffer,
5765 " on sequences");
5766 break;
5767 case DEFACLOBJ_FUNCTION:
5768 appendStringInfoString(&buffer,
5769 " on functions");
5770 break;
5771 case DEFACLOBJ_TYPE:
5772 appendStringInfoString(&buffer,
5773 " on types");
5774 break;
5776 appendStringInfoString(&buffer,
5777 " on schemas");
5778 break;
5780 appendStringInfoString(&buffer,
5781 " on large objects");
5782 break;
5783 }
5784
5785 if (objname)
5786 {
5787 *objname = list_make1(username);
5788 if (schema)
5789 *objname = lappend(*objname, schema);
5790 *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5791 }
5792
5795 break;
5796 }
5797
5799 {
5800 char *extname;
5801
5802 extname = get_extension_name(object->objectId);
5803 if (!extname)
5804 {
5805 if (!missing_ok)
5806 elog(ERROR, "cache lookup failed for extension %u",
5807 object->objectId);
5808 break;
5809 }
5810 appendStringInfoString(&buffer, quote_identifier(extname));
5811 if (objname)
5812 *objname = list_make1(extname);
5813 break;
5814 }
5815
5817 {
5818 HeapTuple tup;
5820 char *evtname;
5821
5823 ObjectIdGetDatum(object->objectId));
5824 if (!HeapTupleIsValid(tup))
5825 {
5826 if (!missing_ok)
5827 elog(ERROR, "cache lookup failed for event trigger %u",
5828 object->objectId);
5829 break;
5830 }
5832 evtname = pstrdup(NameStr(trigForm->evtname));
5833 appendStringInfoString(&buffer, quote_identifier(evtname));
5834 if (objname)
5835 *objname = list_make1(evtname);
5837 break;
5838 }
5839
5841 {
5842 HeapTuple tup;
5844 char *parname;
5845
5847 ObjectIdGetDatum(object->objectId));
5848 if (!HeapTupleIsValid(tup))
5849 {
5850 if (!missing_ok)
5851 elog(ERROR, "cache lookup failed for parameter ACL %u",
5852 object->objectId);
5853 break;
5854 }
5859 if (objname)
5860 *objname = list_make1(parname);
5862 break;
5863 }
5864
5865 case PolicyRelationId:
5866 {
5868 HeapTuple tup;
5870
5872
5874 object->objectId);
5875
5876 if (!HeapTupleIsValid(tup))
5877 {
5878 if (!missing_ok)
5879 elog(ERROR, "could not find tuple for policy %u",
5880 object->objectId);
5881
5883 break;
5884 }
5885
5887
5888 appendStringInfo(&buffer, "%s on ",
5889 quote_identifier(NameStr(policy->polname)));
5890 getRelationIdentity(&buffer, policy->polrelid, objname, false);
5891 if (objname)
5892 *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5893
5895 break;
5896 }
5897
5899 {
5900 char *pubname;
5901
5902 pubname = get_publication_name(object->objectId, missing_ok);
5903 if (pubname)
5904 {
5905 appendStringInfoString(&buffer,
5906 quote_identifier(pubname));
5907 if (objname)
5908 *objname = list_make1(pubname);
5909 }
5910 break;
5911 }
5912
5914 {
5915 char *pubname;
5916 char *nspname;
5917
5918 if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
5919 &nspname))
5920 break;
5921 appendStringInfo(&buffer, "%s in publication %s",
5922 nspname, pubname);
5923
5924 if (objargs)
5925 *objargs = list_make1(pubname);
5926 else
5927 pfree(pubname);
5928
5929 if (objname)
5930 *objname = list_make1(nspname);
5931 else
5932 pfree(nspname);
5933
5934 break;
5935 }
5936
5938 {
5939 HeapTuple tup;
5940 char *pubname;
5942
5944 ObjectIdGetDatum(object->objectId));
5945 if (!HeapTupleIsValid(tup))
5946 {
5947 if (!missing_ok)
5948 elog(ERROR, "cache lookup failed for publication table %u",
5949 object->objectId);
5950 break;
5951 }
5952
5954 pubname = get_publication_name(prform->prpubid, false);
5955
5956 getRelationIdentity(&buffer, prform->prrelid, objname, false);
5957 appendStringInfo(&buffer, " in publication %s", pubname);
5958
5959 if (objargs)
5960 *objargs = list_make1(pubname);
5961
5963 break;
5964 }
5965
5967 {
5968 char *subname;
5969
5970 subname = get_subscription_name(object->objectId, missing_ok);
5971 if (subname)
5972 {
5973 appendStringInfoString(&buffer,
5975 if (objname)
5976 *objname = list_make1(subname);
5977 }
5978 break;
5979 }
5980
5982 {
5984 HeapTuple tup;
5985 Form_pg_transform transform;
5986 char *transformLang;
5987 char *transformType;
5988
5990
5993 object->objectId);
5994
5995 if (!HeapTupleIsValid(tup))
5996 {
5997 if (!missing_ok)
5998 elog(ERROR, "could not find tuple for transform %u",
5999 object->objectId);
6000
6002 break;
6003 }
6004
6005 transform = (Form_pg_transform) GETSTRUCT(tup);
6006
6007 transformType = format_type_be_qualified(transform->trftype);
6008 transformLang = get_language_name(transform->trflang, false);
6009
6010 appendStringInfo(&buffer, "for %s language %s",
6013 if (objname)
6014 {
6015 *objname = list_make1(transformType);
6016 *objargs = list_make1(pstrdup(transformLang));
6017 }
6018
6020 }
6021 break;
6022
6023 default:
6024 elog(ERROR, "unsupported object class: %u", object->classId);
6025 }
6026
6027 if (!missing_ok)
6028 {
6029 /*
6030 * If a get_object_address() representation was requested, make sure
6031 * we are providing one. We don't check objargs, because many of the
6032 * cases above leave it as NIL.
6033 */
6034 if (objname && *objname == NIL)
6035 elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"",
6036 object->classId, buffer.data);
6037 }
6038 else
6039 {
6040 /* an empty buffer is equivalent to no object found */
6041 if (buffer.len == 0)
6042 {
6043 Assert((objname == NULL || *objname == NIL) &&
6044 (objargs == NULL || *objargs == NIL));
6045 return NULL;
6046 }
6047 }
6048
6049 return buffer.data;
6050}
char * get_am_name(Oid amOid)
Definition amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition builtins.h:127
char * format_type_be_qualified(Oid type_oid)
List * lappend(List *list, void *datum)
Definition list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition lsyscache.c:3542
char * pstrdup(const char *in)
Definition mcxt.c:1781
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
END_CATALOG_STRUCT typedef FormData_pg_language * Form_pg_language
Definition pg_language.h:69
#define NIL
Definition pg_list.h:68
#define list_make1(x1)
Definition pg_list.h:212
#define list_make3(x1, x2, x3)
Definition pg_list.h:216
#define list_make2(x1, x2)
Definition pg_list.h:214
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition regproc.c:814
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition regproc.c:404
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition regproc.h:25
#define FORMAT_PROC_FORCE_QUALIFY
Definition regproc.h:20
const char * quote_identifier(const char *ident)
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230

References _, AccessShareLock, appendStringInfo(), appendStringInfoString(), Assert, BTEqualStrategyNumber, ObjectAddress::classId, StringInfoData::data, datname, elog, ERROR, fb(), Form_pg_am, Form_pg_amop, Form_pg_amproc, Form_pg_auth_members, Form_pg_cast, Form_pg_collation, Form_pg_constraint, Form_pg_conversion, Form_pg_default_acl, Form_pg_event_trigger, Form_pg_language, Form_pg_opclass, Form_pg_policy, Form_pg_publication_rel, Form_pg_rewrite, Form_pg_statistic_ext, Form_pg_transform, Form_pg_trigger, Form_pg_ts_config, Form_pg_ts_dict, Form_pg_ts_parser, Form_pg_ts_template, Form_pg_user_mapping, format_operator_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectIdentityParts(), getOpFamilyIdentity(), getPublicationSchemaInfo(), getRelationIdentity(), GETSTRUCT(), GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), lappend(), LargeObjectExists(), StringInfoData::len, list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, pfree(), proname, psprintf(), pstrdup(), quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, and username.

Referenced by EventTriggerSQLDropAddObject(), getObjectIdentity(), getObjectIdentityParts(), and pg_identify_object_as_address().

◆ getObjectTypeDescription()

char * getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)
extern

Definition at line 4497 of file objectaddress.c.

4498{
4499 StringInfoData buffer;
4500
4501 initStringInfo(&buffer);
4502
4503 switch (object->classId)
4504 {
4505 case RelationRelationId:
4506 getRelationTypeDescription(&buffer, object->objectId,
4507 object->objectSubId,
4508 missing_ok);
4509 break;
4510
4512 getProcedureTypeDescription(&buffer, object->objectId,
4513 missing_ok);
4514 break;
4515
4516 case TypeRelationId:
4517 appendStringInfoString(&buffer, "type");
4518 break;
4519
4520 case CastRelationId:
4521 appendStringInfoString(&buffer, "cast");
4522 break;
4523
4525 appendStringInfoString(&buffer, "collation");
4526 break;
4527
4529 getConstraintTypeDescription(&buffer, object->objectId,
4530 missing_ok);
4531 break;
4532
4534 appendStringInfoString(&buffer, "conversion");
4535 break;
4536
4538 appendStringInfoString(&buffer, "default value");
4539 break;
4540
4541 case LanguageRelationId:
4542 appendStringInfoString(&buffer, "language");
4543 break;
4544
4546 appendStringInfoString(&buffer, "large object");
4547 break;
4548
4549 case OperatorRelationId:
4550 appendStringInfoString(&buffer, "operator");
4551 break;
4552
4554 appendStringInfoString(&buffer, "operator class");
4555 break;
4556
4558 appendStringInfoString(&buffer, "operator family");
4559 break;
4560
4562 appendStringInfoString(&buffer, "access method");
4563 break;
4564
4566 appendStringInfoString(&buffer, "operator of access method");
4567 break;
4568
4570 appendStringInfoString(&buffer, "function of access method");
4571 break;
4572
4573 case RewriteRelationId:
4574 appendStringInfoString(&buffer, "rule");
4575 break;
4576
4577 case TriggerRelationId:
4578 appendStringInfoString(&buffer, "trigger");
4579 break;
4580
4582 appendStringInfoString(&buffer, "schema");
4583 break;
4584
4586 appendStringInfoString(&buffer, "statistics object");
4587 break;
4588
4589 case TSParserRelationId:
4590 appendStringInfoString(&buffer, "text search parser");
4591 break;
4592
4594 appendStringInfoString(&buffer, "text search dictionary");
4595 break;
4596
4598 appendStringInfoString(&buffer, "text search template");
4599 break;
4600
4601 case TSConfigRelationId:
4602 appendStringInfoString(&buffer, "text search configuration");
4603 break;
4604
4605 case AuthIdRelationId:
4606 appendStringInfoString(&buffer, "role");
4607 break;
4608
4609 case AuthMemRelationId:
4610 appendStringInfoString(&buffer, "role membership");
4611 break;
4612
4613 case DatabaseRelationId:
4614 appendStringInfoString(&buffer, "database");
4615 break;
4616
4618 appendStringInfoString(&buffer, "tablespace");
4619 break;
4620
4622 appendStringInfoString(&buffer, "foreign-data wrapper");
4623 break;
4624
4626 appendStringInfoString(&buffer, "server");
4627 break;
4628
4630 appendStringInfoString(&buffer, "user mapping");
4631 break;
4632
4634 appendStringInfoString(&buffer, "default acl");
4635 break;
4636
4638 appendStringInfoString(&buffer, "extension");
4639 break;
4640
4642 appendStringInfoString(&buffer, "event trigger");
4643 break;
4644
4646 appendStringInfoString(&buffer, "parameter ACL");
4647 break;
4648
4649 case PolicyRelationId:
4650 appendStringInfoString(&buffer, "policy");
4651 break;
4652
4654 appendStringInfoString(&buffer, "publication");
4655 break;
4656
4658 appendStringInfoString(&buffer, "publication namespace");
4659 break;
4660
4662 appendStringInfoString(&buffer, "publication relation");
4663 break;
4664
4666 appendStringInfoString(&buffer, "subscription");
4667 break;
4668
4670 appendStringInfoString(&buffer, "transform");
4671 break;
4672
4673 default:
4674 elog(ERROR, "unsupported object class: %u", object->classId);
4675 }
4676
4677 /* the result can never be empty */
4678 Assert(buffer.len > 0);
4679
4680 return buffer.data;
4681}
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid, bool missing_ok)
static void getProcedureTypeDescription(StringInfo buffer, Oid procid, bool missing_ok)
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)

References appendStringInfoString(), Assert, ObjectAddress::classId, StringInfoData::data, elog, ERROR, fb(), getConstraintTypeDescription(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), StringInfoData::len, ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), pg_identify_object(), pg_identify_object_as_address(), and sepgsql_object_relabel().

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)
extern

Definition at line 2738 of file objectaddress.c.

2739{
2740 int index;
2741
2742 for (index = 0; index < lengthof(ObjectProperty); index++)
2743 {
2744 if (ObjectProperty[index].class_oid == class_id)
2745 return true;
2746 }
2747
2748 return false;
2749}
#define lengthof(array)
Definition c.h:815
static const ObjectPropertyType ObjectProperty[]
Definition type.h:96

References fb(), lengthof, and ObjectProperty.

Referenced by obtain_object_name_namespace(), pg_event_trigger_ddl_commands(), and pg_identify_object().

◆ read_objtype_from_string()

int read_objtype_from_string ( const char objtype)
extern

Definition at line 2609 of file objectaddress.c.

2610{
2611 int i;
2612
2613 for (i = 0; i < lengthof(ObjectTypeMap); i++)
2614 {
2615 if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2616 return ObjectTypeMap[i].tm_type;
2617 }
2618 ereport(ERROR,
2620 errmsg("unrecognized object type \"%s\"", objtype)));
2621
2622 return -1; /* keep compiler quiet */
2623}
int i
Definition isn.c:77
static const struct object_type_map ObjectTypeMap[]

References ereport, errcode(), errmsg(), ERROR, fb(), i, lengthof, and ObjectTypeMap.

Referenced by pg_get_object_address().

◆ strlist_to_textarray()

struct ArrayType * strlist_to_textarray ( List list)
extern

Definition at line 6131 of file objectaddress.c.

6132{
6133 ArrayType *arr;
6134 Datum *datums;
6135 bool *nulls;
6136 int j = 0;
6137 ListCell *cell;
6138 MemoryContext memcxt;
6140 int lb[1];
6141
6142 /* Work in a temp context; easier than individually pfree'ing the Datums */
6144 "strlist to array",
6146 oldcxt = MemoryContextSwitchTo(memcxt);
6147
6148 datums = palloc_array(Datum, list_length(list));
6149 nulls = palloc_array(bool, list_length(list));
6150
6151 foreach(cell, list)
6152 {
6153 char *name = lfirst(cell);
6154
6155 if (name)
6156 {
6157 nulls[j] = false;
6158 datums[j++] = CStringGetTextDatum(name);
6159 }
6160 else
6161 nulls[j] = true;
6162 }
6163
6165
6166 lb[0] = 1;
6167 arr = construct_md_array(datums, nulls, 1, &j,
6168 lb, TEXTOID, -1, false, TYPALIGN_INT);
6169
6170 MemoryContextDelete(memcxt);
6171
6172 return arr;
6173}
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define palloc_array(type, count)
Definition fe_memutils.h:76
int j
Definition isn.c:78
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
const char * name

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, construct_md_array(), CStringGetTextDatum, CurrentMemoryContext, fb(), j, lfirst, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), name, and palloc_array.

Referenced by fill_hba_line(), pg_event_trigger_dropped_objects(), and pg_identify_object_as_address().

Variable Documentation

◆ InvalidObjectAddress