PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
objectaddress.h File Reference
#include "nodes/pg_list.h"
#include "storage/lockdefs.h"
#include "utils/acl.h"
#include "utils/relcache.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, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, List *objname, List *objargs, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
bool is_objectclass_supported (Oid class_id)
 
Oid get_object_oid_index (Oid class_id)
 
int get_object_catcache_oid (Oid class_id)
 
int get_object_catcache_name (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)
 
AclObjectKind get_object_aclkind (Oid class_id)
 
bool get_object_namensp_unique (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, Oid objectId)
 
char * getObjectDescription (const ObjectAddress *object)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
int read_objtype_from_string (const char *objtype)
 
char * getObjectTypeDescription (const ObjectAddress *object)
 
char * getObjectIdentity (const ObjectAddress *address)
 
char * getObjectIdentityParts (const ObjectAddress *address, List **objname, List **objargs)
 
ArrayTypestrlist_to_textarray (List *list)
 

Variables

const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

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

Definition at line 40 of file objectaddress.h.

Referenced by AlterDatabaseOwner(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterEventTriggerOwner(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner(), AlterForeignServer(), AlterForeignServerOwner(), AlterFunction(), AlterPublicationOptions(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSequence(), AlterSubscription(), AlterSubscriptionOwner(), AlterTableNamespace(), AlterTSConfiguration(), AlterTSDictionary(), AlterTypeNamespace(), AlterTypeOwner(), AlterUserMapping(), ATAddCheckConstraint(), ATAddForeignKeyConstraint(), ATExecAddInherit(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecClusterOn(), ATExecDetachPartition(), ATExecDropInherit(), ATExecValidateConstraint(), CreatePublication(), CreateSchemaCommand(), CreateSubscription(), DefineCollation(), DefineIndex(), DefineQueryRewrite(), DefineRelation(), DefineTSConfiguration(), DefineVirtualRelation(), domainAddConstraint(), DropSubscription(), EventTriggerCollectAlterOpFam(), EventTriggerCollectAlterTSConfig(), EventTriggerCollectCreateOpClass(), ExecAlterExtensionStmt(), ExecAlterObjectSchemaStmt(), ExecRefreshMatView(), get_object_address_defacl(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_usermapping(), pg_event_trigger_ddl_commands(), publication_add_relation(), PublicationDropTables(), rename_constraint_internal(), rename_policy(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), TypeCreate(), and TypeShellMake().

#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)

Definition at line 33 of file objectaddress.h.

Referenced by ATExecAddColumn(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecColumnDefault(), ATExecDropNotNull(), ATExecSetNotNull(), ATExecSetOptions(), ATExecSetStatistics(), ATExecSetStorage(), and renameatt().

Typedef Documentation

Function Documentation

void check_object_ownership ( Oid  roleid,
ObjectType  objtype,
ObjectAddress  address,
List objname,
List objargs,
Relation  relation 
)

Definition at line 2158 of file objectaddress.c.

References ACL_KIND_CLASS, ACL_KIND_COLLATION, ACL_KIND_CONVERSION, ACL_KIND_DATABASE, ACL_KIND_EVENT_TRIGGER, ACL_KIND_EXTENSION, ACL_KIND_FDW, ACL_KIND_FOREIGN_SERVER, ACL_KIND_LANGUAGE, ACL_KIND_NAMESPACE, ACL_KIND_OPCLASS, ACL_KIND_OPER, ACL_KIND_OPFAMILY, ACL_KIND_PROC, ACL_KIND_PUBLICATION, ACL_KIND_SUBSCRIPTION, ACL_KIND_TABLESPACE, ACL_KIND_TSCONFIGURATION, ACL_KIND_TSDICTIONARY, aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), has_createrole_privilege(), linitial, lo_compat_privileges, NameListToString(), NULL, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, 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_POLICY, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddress::objectId, pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_ownercheck(), pg_language_ownercheck(), pg_largeobject_ownercheck(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), RelationGetRelationName, RelationGetRelid, superuser_arg(), and typenameTypeId().

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

2160 {
2161  switch (objtype)
2162  {
2163  case OBJECT_INDEX:
2164  case OBJECT_SEQUENCE:
2165  case OBJECT_TABLE:
2166  case OBJECT_VIEW:
2167  case OBJECT_MATVIEW:
2168  case OBJECT_FOREIGN_TABLE:
2169  case OBJECT_COLUMN:
2170  case OBJECT_RULE:
2171  case OBJECT_TRIGGER:
2172  case OBJECT_POLICY:
2173  case OBJECT_TABCONSTRAINT:
2174  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2176  RelationGetRelationName(relation));
2177  break;
2178  case OBJECT_DATABASE:
2179  if (!pg_database_ownercheck(address.objectId, roleid))
2181  NameListToString(objname));
2182  break;
2183  case OBJECT_TYPE:
2184  case OBJECT_DOMAIN:
2185  case OBJECT_ATTRIBUTE:
2186  case OBJECT_DOMCONSTRAINT:
2187  if (!pg_type_ownercheck(address.objectId, roleid))
2189  break;
2190  case OBJECT_AGGREGATE:
2191  case OBJECT_FUNCTION:
2192  if (!pg_proc_ownercheck(address.objectId, roleid))
2194  NameListToString(objname));
2195  break;
2196  case OBJECT_OPERATOR:
2197  if (!pg_oper_ownercheck(address.objectId, roleid))
2199  NameListToString(objname));
2200  break;
2201  case OBJECT_SCHEMA:
2202  if (!pg_namespace_ownercheck(address.objectId, roleid))
2204  NameListToString(objname));
2205  break;
2206  case OBJECT_COLLATION:
2207  if (!pg_collation_ownercheck(address.objectId, roleid))
2209  NameListToString(objname));
2210  break;
2211  case OBJECT_CONVERSION:
2212  if (!pg_conversion_ownercheck(address.objectId, roleid))
2214  NameListToString(objname));
2215  break;
2216  case OBJECT_EXTENSION:
2217  if (!pg_extension_ownercheck(address.objectId, roleid))
2219  NameListToString(objname));
2220  break;
2221  case OBJECT_FDW:
2222  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2224  NameListToString(objname));
2225  break;
2226  case OBJECT_FOREIGN_SERVER:
2227  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2229  NameListToString(objname));
2230  break;
2231  case OBJECT_EVENT_TRIGGER:
2232  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2234  NameListToString(objname));
2235  break;
2236  case OBJECT_LANGUAGE:
2237  if (!pg_language_ownercheck(address.objectId, roleid))
2239  NameListToString(objname));
2240  break;
2241  case OBJECT_OPCLASS:
2242  if (!pg_opclass_ownercheck(address.objectId, roleid))
2244  NameListToString(objname));
2245  break;
2246  case OBJECT_OPFAMILY:
2247  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2249  NameListToString(objname));
2250  break;
2251  case OBJECT_LARGEOBJECT:
2252  if (!lo_compat_privileges &&
2253  !pg_largeobject_ownercheck(address.objectId, roleid))
2254  ereport(ERROR,
2255  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2256  errmsg("must be owner of large object %u",
2257  address.objectId)));
2258  break;
2259  case OBJECT_CAST:
2260  {
2261  /* We can only check permissions on the source/target types */
2262  TypeName *sourcetype = (TypeName *) linitial(objname);
2263  TypeName *targettype = (TypeName *) linitial(objargs);
2264  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2265  Oid targettypeid = typenameTypeId(NULL, targettype);
2266 
2267  if (!pg_type_ownercheck(sourcetypeid, roleid)
2268  && !pg_type_ownercheck(targettypeid, roleid))
2269  ereport(ERROR,
2270  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2271  errmsg("must be owner of type %s or type %s",
2272  format_type_be(sourcetypeid),
2273  format_type_be(targettypeid))));
2274  }
2275  break;
2276  case OBJECT_PUBLICATION:
2277  if (!pg_publication_ownercheck(address.objectId, roleid))
2279  NameListToString(objname));
2280  break;
2281  case OBJECT_SUBSCRIPTION:
2282  if (!pg_subscription_ownercheck(address.objectId, roleid))
2284  NameListToString(objname));
2285  break;
2286  case OBJECT_TRANSFORM:
2287  {
2288  TypeName *typename = (TypeName *) linitial(objname);
2289  Oid typeid = typenameTypeId(NULL, typename);
2290 
2291  if (!pg_type_ownercheck(typeid, roleid))
2293  }
2294  break;
2295  case OBJECT_TABLESPACE:
2296  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2298  NameListToString(objname));
2299  break;
2300  case OBJECT_TSDICTIONARY:
2301  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2303  NameListToString(objname));
2304  break;
2306  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2308  NameListToString(objname));
2309  break;
2310  case OBJECT_ROLE:
2311 
2312  /*
2313  * We treat roles as being "owned" by those with CREATEROLE priv,
2314  * except that superusers are only owned by superusers.
2315  */
2316  if (superuser_arg(address.objectId))
2317  {
2318  if (!superuser_arg(roleid))
2319  ereport(ERROR,
2320  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2321  errmsg("must be superuser")));
2322  }
2323  else
2324  {
2325  if (!has_createrole_privilege(roleid))
2326  ereport(ERROR,
2327  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2328  errmsg("must have CREATEROLE privilege")));
2329  }
2330  break;
2331  case OBJECT_TSPARSER:
2332  case OBJECT_TSTEMPLATE:
2333  case OBJECT_ACCESS_METHOD:
2334  /* We treat these object types as being owned by superusers */
2335  if (!superuser_arg(roleid))
2336  ereport(ERROR,
2337  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2338  errmsg("must be superuser")));
2339  break;
2340  default:
2341  elog(ERROR, "unrecognized object type: %d",
2342  (int) objtype);
2343  }
2344 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5119
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:4965
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4654
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4804
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4625
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4831
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4885
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5059
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4573
int errcode(int sqlerrcode)
Definition: elog.c:575
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4697
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4547
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3436
bool lo_compat_privileges
Definition: be-fsstubs.c:57
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:4912
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5017
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RelationGetRelationName(relation)
Definition: rel.h:433
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4723
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4777
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:4939
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:2897
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4750
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:4991
#define NULL
Definition: c.h:226
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4521
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4858
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
#define RelationGetRelid(relation)
Definition: rel.h:413
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4599
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5085
HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

Definition at line 2540 of file objectaddress.c.

References Assert, BTEqualStrategyNumber, get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, NULL, ObjectIdAttributeNumber, ObjectIdGetDatum, OidIsValid, RelationGetRelid, ScanKeyInit(), SearchSysCacheCopy1, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterObjectOwner_internal(), EventTriggerSQLDropAddObject(), getConstraintTypeDescription(), getObjectIdentityParts(), pg_event_trigger_ddl_commands(), and pg_identify_object().

2541 {
2542  HeapTuple tuple;
2543  Oid classId = RelationGetRelid(catalog);
2544  int oidCacheId = get_object_catcache_oid(classId);
2545 
2546  if (oidCacheId > 0)
2547  {
2548  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2549  if (!HeapTupleIsValid(tuple)) /* should not happen */
2550  return NULL;
2551  }
2552  else
2553  {
2554  Oid oidIndexId = get_object_oid_index(classId);
2555  SysScanDesc scan;
2556  ScanKeyData skey;
2557 
2558  Assert(OidIsValid(oidIndexId));
2559 
2560  ScanKeyInit(&skey,
2562  BTEqualStrategyNumber, F_OIDEQ,
2563  ObjectIdGetDatum(objectId));
2564 
2565  scan = systable_beginscan(catalog, oidIndexId, true,
2566  NULL, 1, &skey);
2567  tuple = systable_getnext(scan);
2568  if (!HeapTupleIsValid(tuple))
2569  {
2570  systable_endscan(scan);
2571  return NULL;
2572  }
2573  tuple = heap_copytuple(tuple);
2574 
2575  systable_endscan(scan);
2576  }
2577 
2578  return tuple;
2579 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:495
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:324
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:412
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:158
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:413
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclObjectKind get_object_aclkind ( Oid  class_id)

Definition at line 2468 of file objectaddress.c.

References ObjectPropertyType::acl_kind, and get_object_property_data().

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

2469 {
2470  const ObjectPropertyType *prop = get_object_property_data(class_id);
2471 
2472  return prop->acl_kind;
2473 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AclObjectKind acl_kind
ObjectAddress get_object_address ( ObjectType  objtype,
List objname,
List objargs,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 779 of file objectaddress.c.

References Assert, CastRelationId, ObjectAddress::classId, CollationRelationId, ConstraintRelationId, ConversionRelationId, elog, ereport, errcode(), errmsg(), ERROR, 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_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), LargeObjectRelationId, linitial, list_head(), list_length(), LockDatabaseObject(), LockSharedObject(), LookupAggNameTypeNames(), LookupFuncNameTypeNames(), LookupOperNameTypeNames(), LookupTypeNameOid(), lsecond, NoLock, NULL, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, 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_POLICY, OBJECT_PUBLICATION, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, 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(), OperatorRelationId, ProcedureRelationId, RelationRelationId, SharedInvalidMessageCounter, strVal, TransformRelationId, TSConfigRelationId, TSDictionaryRelationId, TSParserRelationId, TSTemplateRelationId, UnlockDatabaseObject(), and UnlockSharedObject().

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

781 {
782  ObjectAddress address;
783  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
784  Relation relation = NULL;
785  uint64 inval_count;
786 
787  /* Some kind of lock must be taken. */
788  Assert(lockmode != NoLock);
789 
790  for (;;)
791  {
792  /*
793  * Remember this value, so that, after looking up the object name and
794  * locking it, we can check whether any invalidation messages have
795  * been processed that might require a do-over.
796  */
797  inval_count = SharedInvalidMessageCounter;
798 
799  /* Look up object address. */
800  switch (objtype)
801  {
802  case OBJECT_INDEX:
803  case OBJECT_SEQUENCE:
804  case OBJECT_TABLE:
805  case OBJECT_VIEW:
806  case OBJECT_MATVIEW:
808  address =
809  get_relation_by_qualified_name(objtype, objname,
810  &relation, lockmode,
811  missing_ok);
812  break;
813  case OBJECT_COLUMN:
814  address =
815  get_object_address_attribute(objtype, objname,
816  &relation, lockmode,
817  missing_ok);
818  break;
819  case OBJECT_DEFAULT:
820  address =
821  get_object_address_attrdef(objtype, objname,
822  &relation, lockmode,
823  missing_ok);
824  break;
825  case OBJECT_RULE:
826  case OBJECT_TRIGGER:
828  case OBJECT_POLICY:
829  address = get_object_address_relobject(objtype, objname,
830  &relation, missing_ok);
831  break;
833  {
834  ObjectAddress domaddr;
835  char *constrname;
836 
838  list_head(objname), missing_ok);
839  constrname = strVal(linitial(objargs));
840 
841  address.classId = ConstraintRelationId;
842  address.objectId = get_domain_constraint_oid(domaddr.objectId,
843  constrname, missing_ok);
844  address.objectSubId = 0;
845 
846  }
847  break;
848  case OBJECT_DATABASE:
849  case OBJECT_EXTENSION:
850  case OBJECT_TABLESPACE:
851  case OBJECT_ROLE:
852  case OBJECT_SCHEMA:
853  case OBJECT_LANGUAGE:
854  case OBJECT_FDW:
858  case OBJECT_PUBLICATION:
859  case OBJECT_SUBSCRIPTION:
860  address = get_object_address_unqualified(objtype,
861  objname, missing_ok);
862  break;
863  case OBJECT_TYPE:
864  case OBJECT_DOMAIN:
865  address = get_object_address_type(objtype, list_head(objname), missing_ok);
866  break;
867  case OBJECT_AGGREGATE:
868  address.classId = ProcedureRelationId;
869  address.objectId =
870  LookupAggNameTypeNames(objname, objargs, missing_ok);
871  address.objectSubId = 0;
872  break;
873  case OBJECT_FUNCTION:
874  address.classId = ProcedureRelationId;
875  address.objectId =
876  LookupFuncNameTypeNames(objname, objargs, missing_ok);
877  address.objectSubId = 0;
878  break;
879  case OBJECT_OPERATOR:
880  Assert(list_length(objargs) == 2);
881  address.classId = OperatorRelationId;
882  address.objectId =
883  LookupOperNameTypeNames(NULL, objname,
884  (TypeName *) linitial(objargs),
885  (TypeName *) lsecond(objargs),
886  missing_ok, -1);
887  address.objectSubId = 0;
888  break;
889  case OBJECT_COLLATION:
890  address.classId = CollationRelationId;
891  address.objectId = get_collation_oid(objname, missing_ok);
892  address.objectSubId = 0;
893  break;
894  case OBJECT_CONVERSION:
895  address.classId = ConversionRelationId;
896  address.objectId = get_conversion_oid(objname, missing_ok);
897  address.objectSubId = 0;
898  break;
899  case OBJECT_OPCLASS:
900  case OBJECT_OPFAMILY:
901  address = get_object_address_opcf(objtype, objname, missing_ok);
902  break;
903  case OBJECT_AMOP:
904  case OBJECT_AMPROC:
905  address = get_object_address_opf_member(objtype, objname,
906  objargs, missing_ok);
907  break;
908  case OBJECT_LARGEOBJECT:
909  Assert(list_length(objname) == 1);
910  address.classId = LargeObjectRelationId;
911  address.objectId = oidparse(linitial(objname));
912  address.objectSubId = 0;
913  if (!LargeObjectExists(address.objectId))
914  {
915  if (!missing_ok)
916  ereport(ERROR,
917  (errcode(ERRCODE_UNDEFINED_OBJECT),
918  errmsg("large object %u does not exist",
919  address.objectId)));
920  }
921  break;
922  case OBJECT_CAST:
923  {
924  TypeName *sourcetype = (TypeName *) linitial(objname);
925  TypeName *targettype = (TypeName *) linitial(objargs);
926  Oid sourcetypeid;
927  Oid targettypeid;
928 
929  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
930  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
931  address.classId = CastRelationId;
932  address.objectId =
933  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
934  address.objectSubId = 0;
935  }
936  break;
937  case OBJECT_TRANSFORM:
938  {
939  TypeName *typename = (TypeName *) linitial(objname);
940  char *langname = strVal(linitial(objargs));
941  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
942  Oid lang_id = get_language_oid(langname, missing_ok);
943 
944  address.classId = TransformRelationId;
945  address.objectId =
946  get_transform_oid(type_id, lang_id, missing_ok);
947  address.objectSubId = 0;
948  }
949  break;
950  case OBJECT_TSPARSER:
951  address.classId = TSParserRelationId;
952  address.objectId = get_ts_parser_oid(objname, missing_ok);
953  address.objectSubId = 0;
954  break;
955  case OBJECT_TSDICTIONARY:
957  address.objectId = get_ts_dict_oid(objname, missing_ok);
958  address.objectSubId = 0;
959  break;
960  case OBJECT_TSTEMPLATE:
961  address.classId = TSTemplateRelationId;
962  address.objectId = get_ts_template_oid(objname, missing_ok);
963  address.objectSubId = 0;
964  break;
966  address.classId = TSConfigRelationId;
967  address.objectId = get_ts_config_oid(objname, missing_ok);
968  address.objectSubId = 0;
969  break;
970  case OBJECT_USER_MAPPING:
971  address = get_object_address_usermapping(objname, objargs,
972  missing_ok);
973  break;
975  address = get_object_address_publication_rel(objname, objargs,
976  &relation,
977  missing_ok);
978  break;
979  case OBJECT_DEFACL:
980  address = get_object_address_defacl(objname, objargs,
981  missing_ok);
982  break;
983  default:
984  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
985  /* placate compiler, in case it thinks elog might return */
986  address.classId = InvalidOid;
987  address.objectId = InvalidOid;
988  address.objectSubId = 0;
989  }
990 
991  /*
992  * If we could not find the supplied object, return without locking.
993  */
994  if (!OidIsValid(address.objectId))
995  {
996  Assert(missing_ok);
997  return address;
998  }
999 
1000  /*
1001  * If we're retrying, see if we got the same answer as last time. If
1002  * so, we're done; if not, we locked the wrong thing, so give up our
1003  * lock.
1004  */
1005  if (OidIsValid(old_address.classId))
1006  {
1007  if (old_address.classId == address.classId
1008  && old_address.objectId == address.objectId
1009  && old_address.objectSubId == address.objectSubId)
1010  break;
1011  if (old_address.classId != RelationRelationId)
1012  {
1013  if (IsSharedRelation(old_address.classId))
1014  UnlockSharedObject(old_address.classId,
1015  old_address.objectId,
1016  0, lockmode);
1017  else
1018  UnlockDatabaseObject(old_address.classId,
1019  old_address.objectId,
1020  0, lockmode);
1021  }
1022  }
1023 
1024  /*
1025  * If we're dealing with a relation or attribute, then the relation is
1026  * already locked. Otherwise, we lock it now.
1027  */
1028  if (address.classId != RelationRelationId)
1029  {
1030  if (IsSharedRelation(address.classId))
1031  LockSharedObject(address.classId, address.objectId, 0,
1032  lockmode);
1033  else
1034  LockDatabaseObject(address.classId, address.objectId, 0,
1035  lockmode);
1036  }
1037 
1038  /*
1039  * At this point, we've resolved the name to an OID and locked the
1040  * corresponding database object. However, it's possible that by the
1041  * time we acquire the lock on the object, concurrent DDL has modified
1042  * the database in such a way that the name we originally looked up no
1043  * longer resolves to that OID.
1044  *
1045  * We can be certain that this isn't an issue if (a) no shared
1046  * invalidation messages have been processed or (b) we've locked a
1047  * relation somewhere along the line. All the relation name lookups
1048  * in this module ultimately use RangeVarGetRelid() to acquire a
1049  * relation lock, and that function protects against the same kinds of
1050  * races we're worried about here. Even when operating on a
1051  * constraint, rule, or trigger, we still acquire AccessShareLock on
1052  * the relation, which is enough to freeze out any concurrent DDL.
1053  *
1054  * In all other cases, however, it's possible that the name we looked
1055  * up no longer refers to the object we locked, so we retry the lookup
1056  * and see whether we get the same answer.
1057  */
1058  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1059  break;
1060  old_address = address;
1061  }
1062 
1063  /* Return the object address and the relation. */
1064  *relp = relation;
1065  return address;
1066 }
Oid LookupOperNameTypeNames(ParseState *pstate, List *opername, TypeName *oprleft, TypeName *oprright, bool noError, int location)
Definition: parse_oper.c:142
#define OperatorRelationId
Definition: pg_operator.h:32
Oid LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
Definition: parse_func.c:1977
Oid oidparse(Node *node)
Definition: oid.c:314
#define TransformRelationId
Definition: pg_transform.h:25
#define ProcedureRelationId
Definition: pg_proc.h:33
#define RelationRelationId
Definition: pg_class.h:29
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:553
#define strVal(v)
Definition: value.h:54
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode, bool missing_ok)
int errcode(int sqlerrcode)
Definition: elog.c:575
static ObjectAddress get_object_address_publication_rel(List *objname, List *objargs, Relation *relp, bool missing_ok)
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2473
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
static ObjectAddress get_object_address_type(ObjectType objtype, ListCell *typecell, bool missing_ok)
#define lsecond(l)
Definition: pg_list.h:114
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *objname, bool missing_ok)
#define TSConfigRelationId
Definition: pg_ts_config.h:31
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2220
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *objname, Relation *relp, bool missing_ok)
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:892
#define TSDictionaryRelationId
Definition: pg_ts_dict.h:31
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2347
#define NoLock
Definition: lockdefs.h:34
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:830
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
Oid LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
Definition: parse_func.c:1940
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
#define ereport(elevel, rest)
Definition: elog.h:122
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:851
static ObjectAddress get_object_address_unqualified(ObjectType objtype, List *qualname, bool missing_ok)
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *objname, List *objargs, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *objname, List *objargs, bool missing_ok)
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode, bool missing_ok)
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:219
#define TSParserRelationId
Definition: pg_ts_parser.h:31
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:871
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
#define CollationRelationId
Definition: pg_collation.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:226
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2094
#define Assert(condition)
Definition: c.h:671
static int list_length(const List *l)
Definition: pg_list.h:89
#define CastRelationId
Definition: pg_cast.h:31
Oid get_conversion_oid(List *name, bool missing_ok)
Definition: namespace.c:3397
bool LargeObjectExists(Oid loid)
int errmsg(const char *fmt,...)
Definition: elog.c:797
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
#define ConstraintRelationId
Definition: pg_constraint.h:29
#define elog
Definition: elog.h:219
#define LargeObjectRelationId
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3324
#define ConversionRelationId
Definition: pg_conversion.h:38
static ObjectAddress get_object_address_usermapping(List *objname, List *objargs, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define TSTemplateRelationId
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:215
ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List objname,
List objargs,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 1076 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1079 {
1080  if (rel)
1081  {
1082  objname = lcons(makeString(rel->relname), objname);
1083  if (rel->schemaname)
1084  objname = lcons(makeString(rel->schemaname), objname);
1085  if (rel->catalogname)
1086  objname = lcons(makeString(rel->catalogname), objname);
1087  }
1088 
1089  return get_object_address(objtype, objname, objargs,
1090  relp, lockmode, missing_ok);
1091 }
Value * makeString(char *str)
Definition: value.c:53
char * schemaname
Definition: primnodes.h:66
char * relname
Definition: primnodes.h:67
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
List * lcons(void *datum, List *list)
Definition: list.c:259
char * catalogname
Definition: primnodes.h:65
AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2460 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2461 {
2462  const ObjectPropertyType *prop = get_object_property_data(class_id);
2463 
2464  return prop->attnum_acl;
2465 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl
AttrNumber get_object_attnum_name ( Oid  class_id)

Definition at line 2436 of file objectaddress.c.

References ObjectPropertyType::attnum_name, and get_object_property_data().

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), EventTriggerSQLDropAddObject(), and pg_identify_object().

2437 {
2438  const ObjectPropertyType *prop = get_object_property_data(class_id);
2439 
2440  return prop->attnum_name;
2441 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber get_object_attnum_namespace ( Oid  class_id)

Definition at line 2444 of file objectaddress.c.

References ObjectPropertyType::attnum_namespace, and get_object_property_data().

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), and pg_identify_object().

2445 {
2446  const ObjectPropertyType *prop = get_object_property_data(class_id);
2447 
2448  return prop->attnum_namespace;
2449 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace
AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2452 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2453 {
2454  const ObjectPropertyType *prop = get_object_property_data(class_id);
2455 
2456  return prop->attnum_owner;
2457 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_name ( Oid  class_id)

Definition at line 2428 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2429 {
2430  const ObjectPropertyType *prop = get_object_property_data(class_id);
2431 
2432  return prop->name_catcache_id;
2433 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_oid ( Oid  class_id)

Definition at line 2420 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_catcache_id.

Referenced by AlterObjectNamespace_internal(), AlterObjectRename_internal(), and get_catalog_object_by_oid().

2421 {
2422  const ObjectPropertyType *prop = get_object_property_data(class_id);
2423 
2424  return prop->oid_catcache_id;
2425 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2476 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2477 {
2478  const ObjectPropertyType *prop = get_object_property_data(class_id);
2479 
2480  return prop->is_nsp_name_unique;
2481 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2353 of file objectaddress.c.

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

Referenced by RemoveObjects().

2354 {
2355  int cache;
2356  HeapTuple tuple;
2357  bool isnull;
2358  Oid oid;
2359  const ObjectPropertyType *property;
2360 
2361  /* If not owned by a namespace, just return InvalidOid. */
2362  property = get_object_property_data(address->classId);
2363  if (property->attnum_namespace == InvalidAttrNumber)
2364  return InvalidOid;
2365 
2366  /* Currently, we can only handle object types with system caches. */
2367  cache = property->oid_catcache_id;
2368  Assert(cache != -1);
2369 
2370  /* Fetch tuple from syscache and extract namespace attribute. */
2371  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2372  if (!HeapTupleIsValid(tuple))
2373  elog(ERROR, "cache lookup failed for cache %d oid %u",
2374  cache, address->objectId);
2375  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2376  tuple,
2377  property->attnum_namespace,
2378  &isnull));
2379  Assert(!isnull);
2380  ReleaseSysCache(tuple);
2381 
2382  return oid;
2383 }
#define DatumGetObjectId(X)
Definition: postgres.h:508
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1245
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:671
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog
Definition: elog.h:219
Oid get_object_oid_index ( Oid  class_id)

Definition at line 2412 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2413 {
2414  const ObjectPropertyType *prop = get_object_property_data(class_id);
2415 
2416  return prop->oid_index_oid;
2417 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
char* getObjectDescription ( const ObjectAddress object)

Definition at line 2587 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, CastOidIndexId, CastRelationId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DEFACLOBJ_FUNCTION, DEFACLOBJ_RELATION, DEFACLOBJ_SEQUENCE, DEFACLOBJ_TYPE, DefaultAclOidIndexId, DefaultAclRelationId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_procedure(), format_type_be(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_rel_name(), get_relid_attribute_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), NameStr, NULL, ObjectAddress::objectId, ObjectIdAttributeNumber, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), pfree(), PolicyOidIndexId, PolicyRelationId, PUBLICATIONREL, quote_qualified_identifier(), RelationRelationId, ReleaseSysCache(), RewriteOidIndexId, RewriteRelationId, ScanKeyInit(), SearchSysCache1, ForeignServer::servername, systable_beginscan(), systable_endscan(), systable_getnext(), TRFOID, TriggerOidIndexId, TriggerRelationId, TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, and USERMAPPINGOID.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependencyFor(), check_relation_privileges(), checkSharedDependencies(), ExecAlterExtensionContentsStmt(), findDependentObjects(), get_object_address_opf_member(), getObjectDescription(), getObjectDescriptionOids(), pg_describe_object(), recordDependencyOnCurrentExtension(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), and storeObjectDescription().

2588 {
2589  StringInfoData buffer;
2590 
2591  initStringInfo(&buffer);
2592 
2593  switch (getObjectClass(object))
2594  {
2595  case OCLASS_CLASS:
2596  getRelationDescription(&buffer, object->objectId);
2597  if (object->objectSubId != 0)
2598  appendStringInfo(&buffer, _(" column %s"),
2600  object->objectSubId));
2601  break;
2602 
2603  case OCLASS_PROC:
2604  appendStringInfo(&buffer, _("function %s"),
2605  format_procedure(object->objectId));
2606  break;
2607 
2608  case OCLASS_TYPE:
2609  appendStringInfo(&buffer, _("type %s"),
2610  format_type_be(object->objectId));
2611  break;
2612 
2613  case OCLASS_CAST:
2614  {
2615  Relation castDesc;
2616  ScanKeyData skey[1];
2617  SysScanDesc rcscan;
2618  HeapTuple tup;
2619  Form_pg_cast castForm;
2620 
2622 
2623  ScanKeyInit(&skey[0],
2625  BTEqualStrategyNumber, F_OIDEQ,
2626  ObjectIdGetDatum(object->objectId));
2627 
2628  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2629  NULL, 1, skey);
2630 
2631  tup = systable_getnext(rcscan);
2632 
2633  if (!HeapTupleIsValid(tup))
2634  elog(ERROR, "could not find tuple for cast %u",
2635  object->objectId);
2636 
2637  castForm = (Form_pg_cast) GETSTRUCT(tup);
2638 
2639  appendStringInfo(&buffer, _("cast from %s to %s"),
2640  format_type_be(castForm->castsource),
2641  format_type_be(castForm->casttarget));
2642 
2643  systable_endscan(rcscan);
2644  heap_close(castDesc, AccessShareLock);
2645  break;
2646  }
2647 
2648  case OCLASS_COLLATION:
2649  {
2650  HeapTuple collTup;
2651  Form_pg_collation coll;
2652 
2653  collTup = SearchSysCache1(COLLOID,
2654  ObjectIdGetDatum(object->objectId));
2655  if (!HeapTupleIsValid(collTup))
2656  elog(ERROR, "cache lookup failed for collation %u",
2657  object->objectId);
2658  coll = (Form_pg_collation) GETSTRUCT(collTup);
2659  appendStringInfo(&buffer, _("collation %s"),
2660  NameStr(coll->collname));
2661  ReleaseSysCache(collTup);
2662  break;
2663  }
2664 
2665  case OCLASS_CONSTRAINT:
2666  {
2667  HeapTuple conTup;
2668  Form_pg_constraint con;
2669 
2670  conTup = SearchSysCache1(CONSTROID,
2671  ObjectIdGetDatum(object->objectId));
2672  if (!HeapTupleIsValid(conTup))
2673  elog(ERROR, "cache lookup failed for constraint %u",
2674  object->objectId);
2675  con = (Form_pg_constraint) GETSTRUCT(conTup);
2676 
2677  if (OidIsValid(con->conrelid))
2678  {
2679  StringInfoData rel;
2680 
2681  initStringInfo(&rel);
2682  getRelationDescription(&rel, con->conrelid);
2683  appendStringInfo(&buffer, _("constraint %s on %s"),
2684  NameStr(con->conname), rel.data);
2685  pfree(rel.data);
2686  }
2687  else
2688  {
2689  appendStringInfo(&buffer, _("constraint %s"),
2690  NameStr(con->conname));
2691  }
2692 
2693  ReleaseSysCache(conTup);
2694  break;
2695  }
2696 
2697  case OCLASS_CONVERSION:
2698  {
2699  HeapTuple conTup;
2700 
2701  conTup = SearchSysCache1(CONVOID,
2702  ObjectIdGetDatum(object->objectId));
2703  if (!HeapTupleIsValid(conTup))
2704  elog(ERROR, "cache lookup failed for conversion %u",
2705  object->objectId);
2706  appendStringInfo(&buffer, _("conversion %s"),
2707  NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2708  ReleaseSysCache(conTup);
2709  break;
2710  }
2711 
2712  case OCLASS_DEFAULT:
2713  {
2714  Relation attrdefDesc;
2715  ScanKeyData skey[1];
2716  SysScanDesc adscan;
2717  HeapTuple tup;
2718  Form_pg_attrdef attrdef;
2719  ObjectAddress colobject;
2720 
2722 
2723  ScanKeyInit(&skey[0],
2725  BTEqualStrategyNumber, F_OIDEQ,
2726  ObjectIdGetDatum(object->objectId));
2727 
2728  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2729  true, NULL, 1, skey);
2730 
2731  tup = systable_getnext(adscan);
2732 
2733  if (!HeapTupleIsValid(tup))
2734  elog(ERROR, "could not find tuple for attrdef %u",
2735  object->objectId);
2736 
2737  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2738 
2739  colobject.classId = RelationRelationId;
2740  colobject.objectId = attrdef->adrelid;
2741  colobject.objectSubId = attrdef->adnum;
2742 
2743  appendStringInfo(&buffer, _("default for %s"),
2744  getObjectDescription(&colobject));
2745 
2746  systable_endscan(adscan);
2747  heap_close(attrdefDesc, AccessShareLock);
2748  break;
2749  }
2750 
2751  case OCLASS_LANGUAGE:
2752  appendStringInfo(&buffer, _("language %s"),
2753  get_language_name(object->objectId, false));
2754  break;
2755 
2756  case OCLASS_LARGEOBJECT:
2757  appendStringInfo(&buffer, _("large object %u"),
2758  object->objectId);
2759  break;
2760 
2761  case OCLASS_OPERATOR:
2762  appendStringInfo(&buffer, _("operator %s"),
2763  format_operator(object->objectId));
2764  break;
2765 
2766  case OCLASS_OPCLASS:
2767  {
2768  HeapTuple opcTup;
2769  Form_pg_opclass opcForm;
2770  HeapTuple amTup;
2771  Form_pg_am amForm;
2772  char *nspname;
2773 
2774  opcTup = SearchSysCache1(CLAOID,
2775  ObjectIdGetDatum(object->objectId));
2776  if (!HeapTupleIsValid(opcTup))
2777  elog(ERROR, "cache lookup failed for opclass %u",
2778  object->objectId);
2779  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2780 
2781  amTup = SearchSysCache1(AMOID,
2782  ObjectIdGetDatum(opcForm->opcmethod));
2783  if (!HeapTupleIsValid(amTup))
2784  elog(ERROR, "cache lookup failed for access method %u",
2785  opcForm->opcmethod);
2786  amForm = (Form_pg_am) GETSTRUCT(amTup);
2787 
2788  /* Qualify the name if not visible in search path */
2789  if (OpclassIsVisible(object->objectId))
2790  nspname = NULL;
2791  else
2792  nspname = get_namespace_name(opcForm->opcnamespace);
2793 
2794  appendStringInfo(&buffer, _("operator class %s for access method %s"),
2796  NameStr(opcForm->opcname)),
2797  NameStr(amForm->amname));
2798 
2799  ReleaseSysCache(amTup);
2800  ReleaseSysCache(opcTup);
2801  break;
2802  }
2803 
2804  case OCLASS_OPFAMILY:
2805  getOpFamilyDescription(&buffer, object->objectId);
2806  break;
2807 
2808  case OCLASS_AMOP:
2809  {
2810  Relation amopDesc;
2811  HeapTuple tup;
2812  ScanKeyData skey[1];
2813  SysScanDesc amscan;
2814  Form_pg_amop amopForm;
2815  StringInfoData opfam;
2816 
2818  AccessShareLock);
2819 
2820  ScanKeyInit(&skey[0],
2822  BTEqualStrategyNumber, F_OIDEQ,
2823  ObjectIdGetDatum(object->objectId));
2824 
2825  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
2826  NULL, 1, skey);
2827 
2828  tup = systable_getnext(amscan);
2829 
2830  if (!HeapTupleIsValid(tup))
2831  elog(ERROR, "could not find tuple for amop entry %u",
2832  object->objectId);
2833 
2834  amopForm = (Form_pg_amop) GETSTRUCT(tup);
2835 
2836  initStringInfo(&opfam);
2837  getOpFamilyDescription(&opfam, amopForm->amopfamily);
2838 
2839  /*------
2840  translator: %d is the operator strategy (a number), the
2841  first two %s's are data type names, the third %s is the
2842  description of the operator family, and the last %s is the
2843  textual form of the operator with arguments. */
2844  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
2845  amopForm->amopstrategy,
2846  format_type_be(amopForm->amoplefttype),
2847  format_type_be(amopForm->amoprighttype),
2848  opfam.data,
2849  format_operator(amopForm->amopopr));
2850 
2851  pfree(opfam.data);
2852 
2853  systable_endscan(amscan);
2854  heap_close(amopDesc, AccessShareLock);
2855  break;
2856  }
2857 
2858  case OCLASS_AMPROC:
2859  {
2860  Relation amprocDesc;
2861  ScanKeyData skey[1];
2862  SysScanDesc amscan;
2863  HeapTuple tup;
2864  Form_pg_amproc amprocForm;
2865  StringInfoData opfam;
2866 
2868  AccessShareLock);
2869 
2870  ScanKeyInit(&skey[0],
2872  BTEqualStrategyNumber, F_OIDEQ,
2873  ObjectIdGetDatum(object->objectId));
2874 
2875  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
2876  NULL, 1, skey);
2877 
2878  tup = systable_getnext(amscan);
2879 
2880  if (!HeapTupleIsValid(tup))
2881  elog(ERROR, "could not find tuple for amproc entry %u",
2882  object->objectId);
2883 
2884  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
2885 
2886  initStringInfo(&opfam);
2887  getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
2888 
2889  /*------
2890  translator: %d is the function number, the first two %s's
2891  are data type names, the third %s is the description of the
2892  operator family, and the last %s is the textual form of the
2893  function with arguments. */
2894  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
2895  amprocForm->amprocnum,
2896  format_type_be(amprocForm->amproclefttype),
2897  format_type_be(amprocForm->amprocrighttype),
2898  opfam.data,
2899  format_procedure(amprocForm->amproc));
2900 
2901  pfree(opfam.data);
2902 
2903  systable_endscan(amscan);
2904  heap_close(amprocDesc, AccessShareLock);
2905  break;
2906  }
2907 
2908  case OCLASS_REWRITE:
2909  {
2910  Relation ruleDesc;
2911  ScanKeyData skey[1];
2912  SysScanDesc rcscan;
2913  HeapTuple tup;
2915 
2917 
2918  ScanKeyInit(&skey[0],
2920  BTEqualStrategyNumber, F_OIDEQ,
2921  ObjectIdGetDatum(object->objectId));
2922 
2923  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
2924  NULL, 1, skey);
2925 
2926  tup = systable_getnext(rcscan);
2927 
2928  if (!HeapTupleIsValid(tup))
2929  elog(ERROR, "could not find tuple for rule %u",
2930  object->objectId);
2931 
2932  rule = (Form_pg_rewrite) GETSTRUCT(tup);
2933 
2934  appendStringInfo(&buffer, _("rule %s on "),
2935  NameStr(rule->rulename));
2936  getRelationDescription(&buffer, rule->ev_class);
2937 
2938  systable_endscan(rcscan);
2939  heap_close(ruleDesc, AccessShareLock);
2940  break;
2941  }
2942 
2943  case OCLASS_TRANSFORM:
2944  {
2945  HeapTuple trfTup;
2946  Form_pg_transform trfForm;
2947 
2948  trfTup = SearchSysCache1(TRFOID,
2949  ObjectIdGetDatum(object->objectId));
2950  if (!HeapTupleIsValid(trfTup))
2951  elog(ERROR, "could not find tuple for transform %u",
2952  object->objectId);
2953 
2954  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
2955 
2956  appendStringInfo(&buffer, _("transform for %s language %s"),
2957  format_type_be(trfForm->trftype),
2958  get_language_name(trfForm->trflang, false));
2959 
2960  ReleaseSysCache(trfTup);
2961  break;
2962  }
2963 
2964  case OCLASS_TRIGGER:
2965  {
2966  Relation trigDesc;
2967  ScanKeyData skey[1];
2968  SysScanDesc tgscan;
2969  HeapTuple tup;
2970  Form_pg_trigger trig;
2971 
2973 
2974  ScanKeyInit(&skey[0],
2976  BTEqualStrategyNumber, F_OIDEQ,
2977  ObjectIdGetDatum(object->objectId));
2978 
2979  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
2980  NULL, 1, skey);
2981 
2982  tup = systable_getnext(tgscan);
2983 
2984  if (!HeapTupleIsValid(tup))
2985  elog(ERROR, "could not find tuple for trigger %u",
2986  object->objectId);
2987 
2988  trig = (Form_pg_trigger) GETSTRUCT(tup);
2989 
2990  appendStringInfo(&buffer, _("trigger %s on "),
2991  NameStr(trig->tgname));
2992  getRelationDescription(&buffer, trig->tgrelid);
2993 
2994  systable_endscan(tgscan);
2995  heap_close(trigDesc, AccessShareLock);
2996  break;
2997  }
2998 
2999  case OCLASS_SCHEMA:
3000  {
3001  char *nspname;
3002 
3003  nspname = get_namespace_name(object->objectId);
3004  if (!nspname)
3005  elog(ERROR, "cache lookup failed for namespace %u",
3006  object->objectId);
3007  appendStringInfo(&buffer, _("schema %s"), nspname);
3008  break;
3009  }
3010 
3011  case OCLASS_TSPARSER:
3012  {
3013  HeapTuple tup;
3014 
3016  ObjectIdGetDatum(object->objectId));
3017  if (!HeapTupleIsValid(tup))
3018  elog(ERROR, "cache lookup failed for text search parser %u",
3019  object->objectId);
3020  appendStringInfo(&buffer, _("text search parser %s"),
3021  NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
3022  ReleaseSysCache(tup);
3023  break;
3024  }
3025 
3026  case OCLASS_TSDICT:
3027  {
3028  HeapTuple tup;
3029 
3030  tup = SearchSysCache1(TSDICTOID,
3031  ObjectIdGetDatum(object->objectId));
3032  if (!HeapTupleIsValid(tup))
3033  elog(ERROR, "cache lookup failed for text search dictionary %u",
3034  object->objectId);
3035  appendStringInfo(&buffer, _("text search dictionary %s"),
3036  NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
3037  ReleaseSysCache(tup);
3038  break;
3039  }
3040 
3041  case OCLASS_TSTEMPLATE:
3042  {
3043  HeapTuple tup;
3044 
3046  ObjectIdGetDatum(object->objectId));
3047  if (!HeapTupleIsValid(tup))
3048  elog(ERROR, "cache lookup failed for text search template %u",
3049  object->objectId);
3050  appendStringInfo(&buffer, _("text search template %s"),
3051  NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
3052  ReleaseSysCache(tup);
3053  break;
3054  }
3055 
3056  case OCLASS_TSCONFIG:
3057  {
3058  HeapTuple tup;
3059 
3061  ObjectIdGetDatum(object->objectId));
3062  if (!HeapTupleIsValid(tup))
3063  elog(ERROR, "cache lookup failed for text search configuration %u",
3064  object->objectId);
3065  appendStringInfo(&buffer, _("text search configuration %s"),
3066  NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
3067  ReleaseSysCache(tup);
3068  break;
3069  }
3070 
3071  case OCLASS_ROLE:
3072  {
3073  appendStringInfo(&buffer, _("role %s"),
3074  GetUserNameFromId(object->objectId, false));
3075  break;
3076  }
3077 
3078  case OCLASS_DATABASE:
3079  {
3080  char *datname;
3081 
3082  datname = get_database_name(object->objectId);
3083  if (!datname)
3084  elog(ERROR, "cache lookup failed for database %u",
3085  object->objectId);
3086  appendStringInfo(&buffer, _("database %s"), datname);
3087  break;
3088  }
3089 
3090  case OCLASS_TBLSPACE:
3091  {
3092  char *tblspace;
3093 
3094  tblspace = get_tablespace_name(object->objectId);
3095  if (!tblspace)
3096  elog(ERROR, "cache lookup failed for tablespace %u",
3097  object->objectId);
3098  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3099  break;
3100  }
3101 
3102  case OCLASS_FDW:
3103  {
3104  ForeignDataWrapper *fdw;
3105 
3106  fdw = GetForeignDataWrapper(object->objectId);
3107  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3108  break;
3109  }
3110 
3111  case OCLASS_FOREIGN_SERVER:
3112  {
3113  ForeignServer *srv;
3114 
3115  srv = GetForeignServer(object->objectId);
3116  appendStringInfo(&buffer, _("server %s"), srv->servername);
3117  break;
3118  }
3119 
3120  case OCLASS_USER_MAPPING:
3121  {
3122  HeapTuple tup;
3123  Oid useid;
3124  char *usename;
3125  Form_pg_user_mapping umform;
3126  ForeignServer *srv;
3127 
3129  ObjectIdGetDatum(object->objectId));
3130  if (!HeapTupleIsValid(tup))
3131  elog(ERROR, "cache lookup failed for user mapping %u",
3132  object->objectId);
3133  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3134  useid = umform->umuser;
3135  srv = GetForeignServer(umform->umserver);
3136 
3137  ReleaseSysCache(tup);
3138 
3139  if (OidIsValid(useid))
3140  usename = GetUserNameFromId(useid, false);
3141  else
3142  usename = "public";
3143 
3144  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3145  srv->servername);
3146  break;
3147  }
3148 
3149  case OCLASS_DEFACL:
3150  {
3151  Relation defaclrel;
3152  ScanKeyData skey[1];
3153  SysScanDesc rcscan;
3154  HeapTuple tup;
3155  Form_pg_default_acl defacl;
3156 
3158 
3159  ScanKeyInit(&skey[0],
3161  BTEqualStrategyNumber, F_OIDEQ,
3162  ObjectIdGetDatum(object->objectId));
3163 
3164  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3165  true, NULL, 1, skey);
3166 
3167  tup = systable_getnext(rcscan);
3168 
3169  if (!HeapTupleIsValid(tup))
3170  elog(ERROR, "could not find tuple for default ACL %u",
3171  object->objectId);
3172 
3173  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3174 
3175  switch (defacl->defaclobjtype)
3176  {
3177  case DEFACLOBJ_RELATION:
3178  appendStringInfo(&buffer,
3179  _("default privileges on new relations belonging to role %s"),
3180  GetUserNameFromId(defacl->defaclrole, false));
3181  break;
3182  case DEFACLOBJ_SEQUENCE:
3183  appendStringInfo(&buffer,
3184  _("default privileges on new sequences belonging to role %s"),
3185  GetUserNameFromId(defacl->defaclrole, false));
3186  break;
3187  case DEFACLOBJ_FUNCTION:
3188  appendStringInfo(&buffer,
3189  _("default privileges on new functions belonging to role %s"),
3190  GetUserNameFromId(defacl->defaclrole, false));
3191  break;
3192  case DEFACLOBJ_TYPE:
3193  appendStringInfo(&buffer,
3194  _("default privileges on new types belonging to role %s"),
3195  GetUserNameFromId(defacl->defaclrole, false));
3196  break;
3197  default:
3198  /* shouldn't get here */
3199  appendStringInfo(&buffer,
3200  _("default privileges belonging to role %s"),
3201  GetUserNameFromId(defacl->defaclrole, false));
3202  break;
3203  }
3204 
3205  if (OidIsValid(defacl->defaclnamespace))
3206  {
3207  appendStringInfo(&buffer,
3208  _(" in schema %s"),
3209  get_namespace_name(defacl->defaclnamespace));
3210  }
3211 
3212  systable_endscan(rcscan);
3213  heap_close(defaclrel, AccessShareLock);
3214  break;
3215  }
3216 
3217  case OCLASS_EXTENSION:
3218  {
3219  char *extname;
3220 
3221  extname = get_extension_name(object->objectId);
3222  if (!extname)
3223  elog(ERROR, "cache lookup failed for extension %u",
3224  object->objectId);
3225  appendStringInfo(&buffer, _("extension %s"), extname);
3226  break;
3227  }
3228 
3229  case OCLASS_EVENT_TRIGGER:
3230  {
3231  HeapTuple tup;
3232 
3234  ObjectIdGetDatum(object->objectId));
3235  if (!HeapTupleIsValid(tup))
3236  elog(ERROR, "cache lookup failed for event trigger %u",
3237  object->objectId);
3238  appendStringInfo(&buffer, _("event trigger %s"),
3239  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3240  ReleaseSysCache(tup);
3241  break;
3242  }
3243 
3244  case OCLASS_POLICY:
3245  {
3246  Relation policy_rel;
3247  ScanKeyData skey[1];
3248  SysScanDesc sscan;
3249  HeapTuple tuple;
3250  Form_pg_policy form_policy;
3251 
3253 
3254  ScanKeyInit(&skey[0],
3256  BTEqualStrategyNumber, F_OIDEQ,
3257  ObjectIdGetDatum(object->objectId));
3258 
3259  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3260  true, NULL, 1, skey);
3261 
3262  tuple = systable_getnext(sscan);
3263 
3264  if (!HeapTupleIsValid(tuple))
3265  elog(ERROR, "cache lookup failed for policy %u",
3266  object->objectId);
3267 
3268  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3269 
3270  appendStringInfo(&buffer, _("policy %s on "),
3271  NameStr(form_policy->polname));
3272  getRelationDescription(&buffer, form_policy->polrelid);
3273 
3274  systable_endscan(sscan);
3275  heap_close(policy_rel, AccessShareLock);
3276  break;
3277  }
3278 
3279  case OCLASS_AM:
3280  {
3281  HeapTuple tup;
3282 
3283  tup = SearchSysCache1(AMOID,
3284  ObjectIdGetDatum(object->objectId));
3285  if (!HeapTupleIsValid(tup))
3286  elog(ERROR, "cache lookup failed for access method %u",
3287  object->objectId);
3288  appendStringInfo(&buffer, _("access method %s"),
3289  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3290  ReleaseSysCache(tup);
3291  break;
3292  }
3293 
3294  case OCLASS_PUBLICATION:
3295  {
3296  appendStringInfo(&buffer, _("publication %s"),
3297  get_publication_name(object->objectId));
3298  break;
3299  }
3300 
3302  {
3303  HeapTuple tup;
3304  char *pubname;
3305  Form_pg_publication_rel prform;
3306 
3308  ObjectIdGetDatum(object->objectId));
3309  if (!HeapTupleIsValid(tup))
3310  elog(ERROR, "cache lookup failed for publication table %u",
3311  object->objectId);
3312 
3313  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3314  pubname = get_publication_name(prform->prpubid);
3315 
3316  appendStringInfo(&buffer, _("publication table %s in publication %s"),
3317  get_rel_name(prform->prrelid), pubname);
3318  ReleaseSysCache(tup);
3319  break;
3320  }
3321 
3322  case OCLASS_SUBSCRIPTION:
3323  {
3324  appendStringInfo(&buffer, _("subscription %s"),
3325  get_subscription_name(object->objectId));
3326  break;
3327  }
3328 
3329  default:
3330  appendStringInfo(&buffer, "unrecognized object %u %u %d",
3331  object->classId,
3332  object->objectId,
3333  object->objectSubId);
3334  break;
3335  }
3336 
3337  return buffer.data;
3338 }
#define RewriteOidIndexId
Definition: indexing.h:214
#define TriggerOidIndexId
Definition: indexing.h:244
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:495
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:986
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:41
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
char * fdwname
Definition: foreign.h:39
#define PolicyOidIndexId
Definition: indexing.h:320
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:59
#define RelationRelationId
Definition: pg_class.h:29
char * get_extension_name(Oid ext_oid)
Definition: extension.c:179
#define DefaultAclOidIndexId
Definition: indexing.h:300
#define AccessShareLock
Definition: lockdefs.h:36
static void getOpFamilyDescription(StringInfo buffer, Oid opfid)
#define AttrDefaultOidIndexId
Definition: indexing.h:89
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:79
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
char * format_operator(Oid operator_oid)
Definition: regproc.c:904
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2312
#define OidIsValid(objectId)
Definition: c.h:534
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:324
#define DefaultAclRelationId
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
char * getObjectDescription(const ObjectAddress *object)
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
Definition: localtime.c:74
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:84
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:412
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:992
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:35
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2048
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:45
#define DEFACLOBJ_SEQUENCE
FormData_pg_default_acl * Form_pg_default_acl
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3006
#define CastOidIndexId
Definition: indexing.h:107
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:42
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10054
char * get_relid_attribute_name(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:801
#define DEFACLOBJ_TYPE
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:93
char * get_publication_name(Oid pubid)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:44
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:56
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1792
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:40
#define PolicyRelationId
Definition: pg_policy.h:19
#define RewriteRelationId
Definition: pg_rewrite.h:32
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:367
#define DEFACLOBJ_RELATION
static void getRelationDescription(StringInfo buffer, Oid relid)
FormData_pg_constraint * Form_pg_constraint
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:690
#define DEFACLOBJ_FUNCTION
#define TriggerRelationId
Definition: pg_trigger.h:34
#define CastRelationId
Definition: pg_cast.h:31
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:72
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:47
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:53
FormData_pg_am * Form_pg_am
Definition: pg_am.h:46
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:77
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1426
char * servername
Definition: foreign.h:50
FormData_pg_ts_template * Form_pg_ts_template
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:495
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define elog
Definition: elog.h:219
#define AttrDefaultRelationId
Definition: pg_attrdef.h:29
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:68
#define AccessMethodProcedureRelationId
Definition: pg_amproc.h:43
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1694
#define _(x)
Definition: elog.c:84
#define BTEqualStrategyNumber
Definition: stratnum.h:31
char * get_subscription_name(Oid subid)
char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3344 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3345 {
3346  ObjectAddress address;
3347 
3348  address.classId = classid;
3349  address.objectId = objid;
3350  address.objectSubId = 0;
3351 
3352  return getObjectDescription(&address);
3353 }
char * getObjectDescription(const ObjectAddress *object)
char* getObjectIdentityParts ( const ObjectAddress address,
List **  objname,
List **  objargs 
)

Definition at line 3960 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, CastRelationId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DEFACLOBJ_FUNCTION, DEFACLOBJ_RELATION, DEFACLOBJ_SEQUENCE, DEFACLOBJ_TYPE, DefaultAclOidIndexId, DefaultAclRelationId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator_parts(), format_operator_qualified(), format_procedure_parts(), format_procedure_qualified(), format_type_be_qualified(), get_am_name(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_rel_name(), get_relid_attribute_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectIdentityParts(), getOpFamilyIdentity(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), LANGOID, lappend(), list_make1, list_make2, list_make3, NameStr, NIL, NULL, ObjectAddress::objectId, ObjectIdAttributeNumber, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, pfree(), PointerIsValid, PolicyRelationId, psprintf(), pstrdup(), PUBLICATIONREL, quote_identifier(), quote_qualified_identifier(), RelationRelationId, ReleaseSysCache(), RewriteRelationId, ScanKeyInit(), SearchSysCache1, ForeignServer::servername, systable_beginscan(), systable_endscan(), systable_getnext(), TransformRelationId, TriggerRelationId, TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, TypeRelationId, USERMAPPINGOID, and username.

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

3962 {
3963  StringInfoData buffer;
3964 
3965  initStringInfo(&buffer);
3966 
3967  /*
3968  * Make sure that both objname and objargs were passed, or none was; and
3969  * initialize them to empty lists. For objname this is useless because it
3970  * will be initialized in all cases inside the switch; but we do it anyway
3971  * so that we can test below that no branch leaves it unset.
3972  */
3973  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
3974  if (objname)
3975  {
3976  *objname = NIL;
3977  *objargs = NIL;
3978  }
3979 
3980  switch (getObjectClass(object))
3981  {
3982  case OCLASS_CLASS:
3983  getRelationIdentity(&buffer, object->objectId, objname);
3984  if (object->objectSubId != 0)
3985  {
3986  char *attr;
3987 
3988  attr = get_relid_attribute_name(object->objectId,
3989  object->objectSubId);
3990  appendStringInfo(&buffer, ".%s", quote_identifier(attr));
3991  if (objname)
3992  *objname = lappend(*objname, attr);
3993  }
3994  break;
3995 
3996  case OCLASS_PROC:
3997  appendStringInfoString(&buffer,
3998  format_procedure_qualified(object->objectId));
3999  if (objname)
4000  format_procedure_parts(object->objectId, objname, objargs);
4001  break;
4002 
4003  case OCLASS_TYPE:
4004  {
4005  char *typeout;
4006 
4007  typeout = format_type_be_qualified(object->objectId);
4008  appendStringInfoString(&buffer, typeout);
4009  if (objname)
4010  *objname = list_make1(typeout);
4011  }
4012  break;
4013 
4014  case OCLASS_CAST:
4015  {
4016  Relation castRel;
4017  HeapTuple tup;
4018  Form_pg_cast castForm;
4019 
4021 
4022  tup = get_catalog_object_by_oid(castRel, object->objectId);
4023 
4024  if (!HeapTupleIsValid(tup))
4025  elog(ERROR, "could not find tuple for cast %u",
4026  object->objectId);
4027 
4028  castForm = (Form_pg_cast) GETSTRUCT(tup);
4029 
4030  appendStringInfo(&buffer, "(%s AS %s)",
4031  format_type_be_qualified(castForm->castsource),
4032  format_type_be_qualified(castForm->casttarget));
4033 
4034  if (objname)
4035  {
4036  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4037  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4038  }
4039 
4040  heap_close(castRel, AccessShareLock);
4041  break;
4042  }
4043 
4044  case OCLASS_COLLATION:
4045  {
4046  HeapTuple collTup;
4047  Form_pg_collation coll;
4048  char *schema;
4049 
4050  collTup = SearchSysCache1(COLLOID,
4051  ObjectIdGetDatum(object->objectId));
4052  if (!HeapTupleIsValid(collTup))
4053  elog(ERROR, "cache lookup failed for collation %u",
4054  object->objectId);
4055  coll = (Form_pg_collation) GETSTRUCT(collTup);
4056  schema = get_namespace_name_or_temp(coll->collnamespace);
4057  appendStringInfoString(&buffer,
4059  NameStr(coll->collname)));
4060  if (objname)
4061  *objname = list_make2(schema,
4062  pstrdup(NameStr(coll->collname)));
4063  ReleaseSysCache(collTup);
4064  break;
4065  }
4066 
4067  case OCLASS_CONSTRAINT:
4068  {
4069  HeapTuple conTup;
4070  Form_pg_constraint con;
4071 
4072  conTup = SearchSysCache1(CONSTROID,
4073  ObjectIdGetDatum(object->objectId));
4074  if (!HeapTupleIsValid(conTup))
4075  elog(ERROR, "cache lookup failed for constraint %u",
4076  object->objectId);
4077  con = (Form_pg_constraint) GETSTRUCT(conTup);
4078 
4079  if (OidIsValid(con->conrelid))
4080  {
4081  appendStringInfo(&buffer, "%s on ",
4082  quote_identifier(NameStr(con->conname)));
4083  getRelationIdentity(&buffer, con->conrelid, objname);
4084  if (objname)
4085  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4086  }
4087  else
4088  {
4089  ObjectAddress domain;
4090 
4091  Assert(OidIsValid(con->contypid));
4092  domain.classId = TypeRelationId;
4093  domain.objectId = con->contypid;
4094  domain.objectSubId = 0;
4095 
4096  appendStringInfo(&buffer, "%s on %s",
4097  quote_identifier(NameStr(con->conname)),
4098  getObjectIdentityParts(&domain, objname, objargs));
4099 
4100  if (objname)
4101  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4102  }
4103 
4104  ReleaseSysCache(conTup);
4105  break;
4106  }
4107 
4108  case OCLASS_CONVERSION:
4109  {
4110  HeapTuple conTup;
4111  Form_pg_conversion conForm;
4112  char *schema;
4113 
4114  conTup = SearchSysCache1(CONVOID,
4115  ObjectIdGetDatum(object->objectId));
4116  if (!HeapTupleIsValid(conTup))
4117  elog(ERROR, "cache lookup failed for conversion %u",
4118  object->objectId);
4119  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4120  schema = get_namespace_name_or_temp(conForm->connamespace);
4121  appendStringInfoString(&buffer,
4123  NameStr(conForm->conname)));
4124  if (objname)
4125  *objname = list_make2(schema,
4126  pstrdup(NameStr(conForm->conname)));
4127  ReleaseSysCache(conTup);
4128  break;
4129  }
4130 
4131  case OCLASS_DEFAULT:
4132  {
4133  Relation attrdefDesc;
4134  ScanKeyData skey[1];
4135  SysScanDesc adscan;
4136 
4137  HeapTuple tup;
4138  Form_pg_attrdef attrdef;
4139  ObjectAddress colobject;
4140 
4142 
4143  ScanKeyInit(&skey[0],
4145  BTEqualStrategyNumber, F_OIDEQ,
4146  ObjectIdGetDatum(object->objectId));
4147 
4148  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4149  true, NULL, 1, skey);
4150 
4151  tup = systable_getnext(adscan);
4152 
4153  if (!HeapTupleIsValid(tup))
4154  elog(ERROR, "could not find tuple for attrdef %u",
4155  object->objectId);
4156 
4157  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4158 
4159  colobject.classId = RelationRelationId;
4160  colobject.objectId = attrdef->adrelid;
4161  colobject.objectSubId = attrdef->adnum;
4162 
4163  appendStringInfo(&buffer, "for %s",
4164  getObjectIdentityParts(&colobject,
4165  objname, objargs));
4166 
4167  systable_endscan(adscan);
4168  heap_close(attrdefDesc, AccessShareLock);
4169  break;
4170  }
4171 
4172  case OCLASS_LANGUAGE:
4173  {
4174  HeapTuple langTup;
4175  Form_pg_language langForm;
4176 
4177  langTup = SearchSysCache1(LANGOID,
4178  ObjectIdGetDatum(object->objectId));
4179  if (!HeapTupleIsValid(langTup))
4180  elog(ERROR, "cache lookup failed for language %u",
4181  object->objectId);
4182  langForm = (Form_pg_language) GETSTRUCT(langTup);
4183  appendStringInfoString(&buffer,
4184  quote_identifier(NameStr(langForm->lanname)));
4185  if (objname)
4186  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4187  ReleaseSysCache(langTup);
4188  break;
4189  }
4190  case OCLASS_LARGEOBJECT:
4191  appendStringInfo(&buffer, "%u",
4192  object->objectId);
4193  if (objname)
4194  *objname = list_make1(psprintf("%u", object->objectId));
4195  break;
4196 
4197  case OCLASS_OPERATOR:
4198  appendStringInfoString(&buffer,
4199  format_operator_qualified(object->objectId));
4200  if (objname)
4201  format_operator_parts(object->objectId, objname, objargs);
4202  break;
4203 
4204  case OCLASS_OPCLASS:
4205  {
4206  HeapTuple opcTup;
4207  Form_pg_opclass opcForm;
4208  HeapTuple amTup;
4209  Form_pg_am amForm;
4210  char *schema;
4211 
4212  opcTup = SearchSysCache1(CLAOID,
4213  ObjectIdGetDatum(object->objectId));
4214  if (!HeapTupleIsValid(opcTup))
4215  elog(ERROR, "cache lookup failed for opclass %u",
4216  object->objectId);
4217  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4218  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4219 
4220  amTup = SearchSysCache1(AMOID,
4221  ObjectIdGetDatum(opcForm->opcmethod));
4222  if (!HeapTupleIsValid(amTup))
4223  elog(ERROR, "cache lookup failed for access method %u",
4224  opcForm->opcmethod);
4225  amForm = (Form_pg_am) GETSTRUCT(amTup);
4226 
4227  appendStringInfo(&buffer, "%s USING %s",
4229  NameStr(opcForm->opcname)),
4230  quote_identifier(NameStr(amForm->amname)));
4231  if (objname)
4232  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
4233  schema,
4234  pstrdup(NameStr(opcForm->opcname)));
4235 
4236  ReleaseSysCache(amTup);
4237  ReleaseSysCache(opcTup);
4238  break;
4239  }
4240 
4241  case OCLASS_OPFAMILY:
4242  getOpFamilyIdentity(&buffer, object->objectId, objname);
4243  break;
4244 
4245  case OCLASS_AMOP:
4246  {
4247  Relation amopDesc;
4248  HeapTuple tup;
4249  ScanKeyData skey[1];
4250  SysScanDesc amscan;
4251  Form_pg_amop amopForm;
4252  StringInfoData opfam;
4253  char *ltype;
4254  char *rtype;
4255 
4257  AccessShareLock);
4258 
4259  ScanKeyInit(&skey[0],
4261  BTEqualStrategyNumber, F_OIDEQ,
4262  ObjectIdGetDatum(object->objectId));
4263 
4264  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
4265  NULL, 1, skey);
4266 
4267  tup = systable_getnext(amscan);
4268 
4269  if (!HeapTupleIsValid(tup))
4270  elog(ERROR, "could not find tuple for amop entry %u",
4271  object->objectId);
4272 
4273  amopForm = (Form_pg_amop) GETSTRUCT(tup);
4274 
4275  initStringInfo(&opfam);
4276  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname);
4277 
4278  ltype = format_type_be_qualified(amopForm->amoplefttype);
4279  rtype = format_type_be_qualified(amopForm->amoprighttype);
4280 
4281  if (objname)
4282  {
4283  *objname = lappend(*objname,
4284  psprintf("%d", amopForm->amopstrategy));
4285  *objargs = list_make2(ltype, rtype);
4286  }
4287 
4288  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
4289  amopForm->amopstrategy,
4290  ltype, rtype, opfam.data);
4291 
4292  pfree(opfam.data);
4293 
4294  systable_endscan(amscan);
4295  heap_close(amopDesc, AccessShareLock);
4296  break;
4297  }
4298 
4299  case OCLASS_AMPROC:
4300  {
4301  Relation amprocDesc;
4302  ScanKeyData skey[1];
4303  SysScanDesc amscan;
4304  HeapTuple tup;
4305  Form_pg_amproc amprocForm;
4306  StringInfoData opfam;
4307  char *ltype;
4308  char *rtype;
4309 
4311  AccessShareLock);
4312 
4313  ScanKeyInit(&skey[0],
4315  BTEqualStrategyNumber, F_OIDEQ,
4316  ObjectIdGetDatum(object->objectId));
4317 
4318  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
4319  NULL, 1, skey);
4320 
4321  tup = systable_getnext(amscan);
4322 
4323  if (!HeapTupleIsValid(tup))
4324  elog(ERROR, "could not find tuple for amproc entry %u",
4325  object->objectId);
4326 
4327  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
4328 
4329  initStringInfo(&opfam);
4330  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname);
4331 
4332  ltype = format_type_be_qualified(amprocForm->amproclefttype);
4333  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
4334 
4335  if (objname)
4336  {
4337  *objname = lappend(*objname,
4338  psprintf("%d", amprocForm->amprocnum));
4339  *objargs = list_make2(ltype, rtype);
4340  }
4341 
4342  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
4343  amprocForm->amprocnum,
4344  ltype, rtype, opfam.data);
4345 
4346  pfree(opfam.data);
4347 
4348  systable_endscan(amscan);
4349  heap_close(amprocDesc, AccessShareLock);
4350  break;
4351  }
4352 
4353  case OCLASS_REWRITE:
4354  {
4355  Relation ruleDesc;
4356  HeapTuple tup;
4358 
4360 
4361  tup = get_catalog_object_by_oid(ruleDesc, object->objectId);
4362 
4363  if (!HeapTupleIsValid(tup))
4364  elog(ERROR, "could not find tuple for rule %u",
4365  object->objectId);
4366 
4367  rule = (Form_pg_rewrite) GETSTRUCT(tup);
4368 
4369  appendStringInfo(&buffer, "%s on ",
4370  quote_identifier(NameStr(rule->rulename)));
4371  getRelationIdentity(&buffer, rule->ev_class, objname);
4372  if (objname)
4373  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
4374 
4375  heap_close(ruleDesc, AccessShareLock);
4376  break;
4377  }
4378 
4379  case OCLASS_TRIGGER:
4380  {
4381  Relation trigDesc;
4382  HeapTuple tup;
4383  Form_pg_trigger trig;
4384 
4386 
4387  tup = get_catalog_object_by_oid(trigDesc, object->objectId);
4388 
4389  if (!HeapTupleIsValid(tup))
4390  elog(ERROR, "could not find tuple for trigger %u",
4391  object->objectId);
4392 
4393  trig = (Form_pg_trigger) GETSTRUCT(tup);
4394 
4395  appendStringInfo(&buffer, "%s on ",
4396  quote_identifier(NameStr(trig->tgname)));
4397  getRelationIdentity(&buffer, trig->tgrelid, objname);
4398  if (objname)
4399  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
4400 
4401  heap_close(trigDesc, AccessShareLock);
4402  break;
4403  }
4404 
4405  case OCLASS_POLICY:
4406  {
4407  Relation polDesc;
4408  HeapTuple tup;
4409  Form_pg_policy policy;
4410 
4412 
4413  tup = get_catalog_object_by_oid(polDesc, object->objectId);
4414 
4415  if (!HeapTupleIsValid(tup))
4416  elog(ERROR, "could not find tuple for policy %u",
4417  object->objectId);
4418 
4419  policy = (Form_pg_policy) GETSTRUCT(tup);
4420 
4421  appendStringInfo(&buffer, "%s on ",
4422  quote_identifier(NameStr(policy->polname)));
4423  getRelationIdentity(&buffer, policy->polrelid, objname);
4424  if (objname)
4425  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
4426 
4427  heap_close(polDesc, AccessShareLock);
4428  break;
4429  }
4430 
4431  case OCLASS_SCHEMA:
4432  {
4433  char *nspname;
4434 
4435  nspname = get_namespace_name_or_temp(object->objectId);
4436  if (!nspname)
4437  elog(ERROR, "cache lookup failed for namespace %u",
4438  object->objectId);
4439  appendStringInfoString(&buffer,
4440  quote_identifier(nspname));
4441  if (objname)
4442  *objname = list_make1(nspname);
4443  break;
4444  }
4445 
4446  case OCLASS_TSPARSER:
4447  {
4448  HeapTuple tup;
4449  Form_pg_ts_parser formParser;
4450  char *schema;
4451 
4453  ObjectIdGetDatum(object->objectId));
4454  if (!HeapTupleIsValid(tup))
4455  elog(ERROR, "cache lookup failed for text search parser %u",
4456  object->objectId);
4457  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4458  schema = get_namespace_name_or_temp(formParser->prsnamespace);
4459  appendStringInfoString(&buffer,
4461  NameStr(formParser->prsname)));
4462  if (objname)
4463  *objname = list_make2(schema,
4464  pstrdup(NameStr(formParser->prsname)));
4465  ReleaseSysCache(tup);
4466  break;
4467  }
4468 
4469  case OCLASS_TSDICT:
4470  {
4471  HeapTuple tup;
4472  Form_pg_ts_dict formDict;
4473  char *schema;
4474 
4475  tup = SearchSysCache1(TSDICTOID,
4476  ObjectIdGetDatum(object->objectId));
4477  if (!HeapTupleIsValid(tup))
4478  elog(ERROR, "cache lookup failed for text search dictionary %u",
4479  object->objectId);
4480  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4481  schema = get_namespace_name_or_temp(formDict->dictnamespace);
4482  appendStringInfoString(&buffer,
4484  NameStr(formDict->dictname)));
4485  if (objname)
4486  *objname = list_make2(schema,
4487  pstrdup(NameStr(formDict->dictname)));
4488  ReleaseSysCache(tup);
4489  break;
4490  }
4491 
4492  case OCLASS_TSTEMPLATE:
4493  {
4494  HeapTuple tup;
4495  Form_pg_ts_template formTmpl;
4496  char *schema;
4497 
4499  ObjectIdGetDatum(object->objectId));
4500  if (!HeapTupleIsValid(tup))
4501  elog(ERROR, "cache lookup failed for text search template %u",
4502  object->objectId);
4503  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4504  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4505  appendStringInfoString(&buffer,
4507  NameStr(formTmpl->tmplname)));
4508  if (objname)
4509  *objname = list_make2(schema,
4510  pstrdup(NameStr(formTmpl->tmplname)));
4511  ReleaseSysCache(tup);
4512  break;
4513  }
4514 
4515  case OCLASS_TSCONFIG:
4516  {
4517  HeapTuple tup;
4518  Form_pg_ts_config formCfg;
4519  char *schema;
4520 
4522  ObjectIdGetDatum(object->objectId));
4523  if (!HeapTupleIsValid(tup))
4524  elog(ERROR, "cache lookup failed for text search configuration %u",
4525  object->objectId);
4526  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4527  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4528  appendStringInfoString(&buffer,
4530  NameStr(formCfg->cfgname)));
4531  if (objname)
4532  *objname = list_make2(schema,
4533  pstrdup(NameStr(formCfg->cfgname)));
4534  ReleaseSysCache(tup);
4535  break;
4536  }
4537 
4538  case OCLASS_ROLE:
4539  {
4540  char *username;
4541 
4542  username = GetUserNameFromId(object->objectId, false);
4543  if (objname)
4544  *objname = list_make1(username);
4545  appendStringInfoString(&buffer,
4546  quote_identifier(username));
4547  break;
4548  }
4549 
4550  case OCLASS_DATABASE:
4551  {
4552  char *datname;
4553 
4554  datname = get_database_name(object->objectId);
4555  if (!datname)
4556  elog(ERROR, "cache lookup failed for database %u",
4557  object->objectId);
4558  if (objname)
4559  *objname = list_make1(datname);
4560  appendStringInfoString(&buffer,
4561  quote_identifier(datname));
4562  break;
4563  }
4564 
4565  case OCLASS_TBLSPACE:
4566  {
4567  char *tblspace;
4568 
4569  tblspace = get_tablespace_name(object->objectId);
4570  if (!tblspace)
4571  elog(ERROR, "cache lookup failed for tablespace %u",
4572  object->objectId);
4573  if (objname)
4574  *objname = list_make1(tblspace);
4575  appendStringInfoString(&buffer,
4576  quote_identifier(tblspace));
4577  break;
4578  }
4579 
4580  case OCLASS_FDW:
4581  {
4582  ForeignDataWrapper *fdw;
4583 
4584  fdw = GetForeignDataWrapper(object->objectId);
4586  if (objname)
4587  *objname = list_make1(pstrdup(fdw->fdwname));
4588  break;
4589  }
4590 
4591  case OCLASS_FOREIGN_SERVER:
4592  {
4593  ForeignServer *srv;
4594 
4595  srv = GetForeignServer(object->objectId);
4596  appendStringInfoString(&buffer,
4598  if (objname)
4599  *objname = list_make1(pstrdup(srv->servername));
4600  break;
4601  }
4602 
4603  case OCLASS_USER_MAPPING:
4604  {
4605  HeapTuple tup;
4606  Oid useid;
4607  Form_pg_user_mapping umform;
4608  ForeignServer *srv;
4609  const char *usename;
4610 
4612  ObjectIdGetDatum(object->objectId));
4613  if (!HeapTupleIsValid(tup))
4614  elog(ERROR, "cache lookup failed for user mapping %u",
4615  object->objectId);
4616  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
4617  useid = umform->umuser;
4618  srv = GetForeignServer(umform->umserver);
4619 
4620  ReleaseSysCache(tup);
4621 
4622  if (OidIsValid(useid))
4623  usename = GetUserNameFromId(useid, false);
4624  else
4625  usename = "public";
4626 
4627  if (objname)
4628  {
4629  *objname = list_make1(pstrdup(usename));
4630  *objargs = list_make1(pstrdup(srv->servername));
4631  }
4632 
4633  appendStringInfo(&buffer, "%s on server %s",
4634  quote_identifier(usename),
4635  srv->servername);
4636  break;
4637  }
4638 
4639  case OCLASS_DEFACL:
4640  {
4641  Relation defaclrel;
4642  ScanKeyData skey[1];
4643  SysScanDesc rcscan;
4644  HeapTuple tup;
4645  Form_pg_default_acl defacl;
4646  char *schema;
4647  char *username;
4648 
4650 
4651  ScanKeyInit(&skey[0],
4653  BTEqualStrategyNumber, F_OIDEQ,
4654  ObjectIdGetDatum(object->objectId));
4655 
4656  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
4657  true, NULL, 1, skey);
4658 
4659  tup = systable_getnext(rcscan);
4660 
4661  if (!HeapTupleIsValid(tup))
4662  elog(ERROR, "could not find tuple for default ACL %u",
4663  object->objectId);
4664 
4665  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
4666 
4667  username = GetUserNameFromId(defacl->defaclrole, false);
4668  appendStringInfo(&buffer,
4669  "for role %s",
4670  quote_identifier(username));
4671 
4672  if (OidIsValid(defacl->defaclnamespace))
4673  {
4674  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
4675  appendStringInfo(&buffer,
4676  " in schema %s",
4677  quote_identifier(schema));
4678  }
4679  else
4680  schema = NULL;
4681 
4682  switch (defacl->defaclobjtype)
4683  {
4684  case DEFACLOBJ_RELATION:
4685  appendStringInfoString(&buffer,
4686  " on tables");
4687  break;
4688  case DEFACLOBJ_SEQUENCE:
4689  appendStringInfoString(&buffer,
4690  " on sequences");
4691  break;
4692  case DEFACLOBJ_FUNCTION:
4693  appendStringInfoString(&buffer,
4694  " on functions");
4695  break;
4696  case DEFACLOBJ_TYPE:
4697  appendStringInfoString(&buffer,
4698  " on types");
4699  break;
4700  }
4701 
4702  if (objname)
4703  {
4704  *objname = list_make1(username);
4705  if (schema)
4706  *objname = lappend(*objname, schema);
4707  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
4708  }
4709 
4710  systable_endscan(rcscan);
4711  heap_close(defaclrel, AccessShareLock);
4712  break;
4713  }
4714 
4715  case OCLASS_EXTENSION:
4716  {
4717  char *extname;
4718 
4719  extname = get_extension_name(object->objectId);
4720  if (!extname)
4721  elog(ERROR, "cache lookup failed for extension %u",
4722  object->objectId);
4723  appendStringInfoString(&buffer, quote_identifier(extname));
4724  if (objname)
4725  *objname = list_make1(extname);
4726  break;
4727  }
4728 
4729  case OCLASS_EVENT_TRIGGER:
4730  {
4731  HeapTuple tup;
4732  Form_pg_event_trigger trigForm;
4733 
4734  /* no objname support here */
4735  if (objname)
4736  *objname = NIL;
4737 
4739  ObjectIdGetDatum(object->objectId));
4740  if (!HeapTupleIsValid(tup))
4741  elog(ERROR, "cache lookup failed for event trigger %u",
4742  object->objectId);
4743  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
4744  appendStringInfoString(&buffer,
4745  quote_identifier(NameStr(trigForm->evtname)));
4746  ReleaseSysCache(tup);
4747  break;
4748  }
4749 
4750  case OCLASS_TRANSFORM:
4751  {
4752  Relation transformDesc;
4753  HeapTuple tup;
4754  Form_pg_transform transform;
4755  char *transformLang;
4756  char *transformType;
4757 
4758  transformDesc = heap_open(TransformRelationId, AccessShareLock);
4759 
4760  tup = get_catalog_object_by_oid(transformDesc, object->objectId);
4761 
4762  if (!HeapTupleIsValid(tup))
4763  elog(ERROR, "could not find tuple for transform %u",
4764  object->objectId);
4765 
4766  transform = (Form_pg_transform) GETSTRUCT(tup);
4767 
4768  transformType = format_type_be_qualified(transform->trftype);
4769  transformLang = get_language_name(transform->trflang, false);
4770 
4771  appendStringInfo(&buffer, "for %s on language %s",
4772  transformType,
4773  transformLang);
4774  if (objname)
4775  {
4776  *objname = list_make1(transformType);
4777  *objargs = list_make1(pstrdup(transformLang));
4778  }
4779 
4780  heap_close(transformDesc, AccessShareLock);
4781  }
4782  break;
4783 
4784  case OCLASS_AM:
4785  {
4786  char *amname;
4787 
4788  amname = get_am_name(object->objectId);
4789  if (!amname)
4790  elog(ERROR, "cache lookup failed for access method %u",
4791  object->objectId);
4792  appendStringInfoString(&buffer, quote_identifier(amname));
4793  if (objname)
4794  *objname = list_make1(amname);
4795  }
4796  break;
4797 
4798  case OCLASS_PUBLICATION:
4799  {
4800  char *pubname;
4801 
4802  pubname = get_publication_name(object->objectId);
4803  appendStringInfoString(&buffer,
4804  quote_identifier(pubname));
4805  if (objname)
4806  *objname = list_make1(pubname);
4807  break;
4808  }
4809 
4811  {
4812  HeapTuple tup;
4813  char *pubname;
4814  Form_pg_publication_rel prform;
4815 
4817  ObjectIdGetDatum(object->objectId));
4818  if (!HeapTupleIsValid(tup))
4819  elog(ERROR, "cache lookup failed for publication table %u",
4820  object->objectId);
4821 
4822  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
4823  pubname = get_publication_name(prform->prpubid);
4824 
4825  appendStringInfo(&buffer, _("%s in publication %s"),
4826  get_rel_name(prform->prrelid), pubname);
4827 
4828  if (objname)
4829  {
4830  getRelationIdentity(&buffer, prform->prrelid, objname);
4831  *objargs = list_make1(pubname);
4832  }
4833 
4834  ReleaseSysCache(tup);
4835  break;
4836  }
4837 
4838  case OCLASS_SUBSCRIPTION:
4839  {
4840  char *subname;
4841 
4842  subname = get_subscription_name(object->objectId);
4843  appendStringInfoString(&buffer,
4844  quote_identifier(subname));
4845  if (objname)
4846  *objname = list_make1(subname);
4847  break;
4848  }
4849 
4850  default:
4851  appendStringInfo(&buffer, "unrecognized object %u %u %d",
4852  object->classId,
4853  object->objectId,
4854  object->objectSubId);
4855  break;
4856  }
4857 
4858  /*
4859  * If a get_object_address representation was requested, make sure we are
4860  * providing one. We don't check objargs, because many of the cases above
4861  * leave it as NIL.
4862  */
4863  if (objname && *objname == NIL)
4864  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
4865  (int) getObjectClass(object), buffer.data);
4866 
4867  return buffer.data;
4868 }
#define list_make2(x1, x2)
Definition: pg_list.h:134
#define list_make3(x1, x2, x3)
Definition: pg_list.h:135
#define NIL
Definition: pg_list.h:69
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:495
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Definition: syscache.h:36
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:9968
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:986
#define TransformRelationId
Definition: pg_transform.h:25
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:41
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
char * fdwname
Definition: foreign.h:39
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:59
char * pstrdup(const char *in)
Definition: mcxt.c:1165
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define RelationRelationId
Definition: pg_class.h:29
char * get_extension_name(Oid ext_oid)
Definition: extension.c:179
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs)
#define DefaultAclOidIndexId
Definition: indexing.h:300
#define AccessShareLock
Definition: lockdefs.h:36
#define AttrDefaultOidIndexId
Definition: indexing.h:89
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:79
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
#define TypeRelationId
Definition: pg_type.h:34
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2312
#define OidIsValid(objectId)
Definition: c.h:534
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:324
#define DefaultAclRelationId
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
Definition: localtime.c:74
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:84
#define list_make1(x1)
Definition: pg_list.h:133
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **objname)
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:412
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:992
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs)
Definition: regproc.c:916
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:35
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
char * format_operator_qualified(Oid operator_oid)
Definition: regproc.c:910
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2048
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:45
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
#define DEFACLOBJ_SEQUENCE
FormData_pg_default_acl * Form_pg_default_acl
char * get_am_name(Oid amOid)
Definition: amcmds.c:202
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs)
Definition: regproc.c:451
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:42
char * format_procedure_qualified(Oid procedure_oid)
Definition: regproc.c:373
List * lappend(List *list, void *datum)
Definition: list.c:128
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10054
char * get_relid_attribute_name(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:801
#define DEFACLOBJ_TYPE
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:93
char * get_publication_name(Oid pubid)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:44
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:56
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
static char * username
Definition: initdb.c:129
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:40
#define PolicyRelationId
Definition: pg_policy.h:19
#define RewriteRelationId
Definition: pg_rewrite.h:32
#define DEFACLOBJ_RELATION
FormData_pg_constraint * Form_pg_constraint
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:690
#define Assert(condition)
Definition: c.h:671
static void getRelationIdentity(StringInfo buffer, Oid relid, List **objname)
#define DEFACLOBJ_FUNCTION
#define TriggerRelationId
Definition: pg_trigger.h:34
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:104
#define CastRelationId
Definition: pg_cast.h:31
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:72
HeapTuple get_catalog_object_by_oid(Relation catalog, Oid objectId)
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:47
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:53
FormData_pg_am * Form_pg_am
Definition: pg_am.h:46
FormData_pg_language * Form_pg_language
Definition: pg_language.h:51
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3030
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:77
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1426
char * servername
Definition: foreign.h:50
FormData_pg_ts_template * Form_pg_ts_template
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:495
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define elog
Definition: elog.h:219
#define AttrDefaultRelationId
Definition: pg_attrdef.h:29
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:68
#define AccessMethodProcedureRelationId
Definition: pg_amproc.h:43
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1694
#define PointerIsValid(pointer)
Definition: c.h:522
#define _(x)
Definition: elog.c:84
#define BTEqualStrategyNumber
Definition: stratnum.h:31
char * get_subscription_name(Oid subid)
char* getObjectTypeDescription ( const ObjectAddress object)

Definition at line 3670 of file objectaddress.c.

References appendStringInfo(), appendStringInfoString(), ObjectAddress::classId, StringInfoData::data, getConstraintTypeDescription(), getObjectClass(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), ObjectAddress::objectId, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, and OCLASS_USER_MAPPING.

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

3671 {
3672  StringInfoData buffer;
3673 
3674  initStringInfo(&buffer);
3675 
3676  switch (getObjectClass(object))
3677  {
3678  case OCLASS_CLASS:
3679  getRelationTypeDescription(&buffer, object->objectId,
3680  object->objectSubId);
3681  break;
3682 
3683  case OCLASS_PROC:
3684  getProcedureTypeDescription(&buffer, object->objectId);
3685  break;
3686 
3687  case OCLASS_TYPE:
3688  appendStringInfoString(&buffer, "type");
3689  break;
3690 
3691  case OCLASS_CAST:
3692  appendStringInfoString(&buffer, "cast");
3693  break;
3694 
3695  case OCLASS_COLLATION:
3696  appendStringInfoString(&buffer, "collation");
3697  break;
3698 
3699  case OCLASS_CONSTRAINT:
3700  getConstraintTypeDescription(&buffer, object->objectId);
3701  break;
3702 
3703  case OCLASS_CONVERSION:
3704  appendStringInfoString(&buffer, "conversion");
3705  break;
3706 
3707  case OCLASS_DEFAULT:
3708  appendStringInfoString(&buffer, "default value");
3709  break;
3710 
3711  case OCLASS_LANGUAGE:
3712  appendStringInfoString(&buffer, "language");
3713  break;
3714 
3715  case OCLASS_LARGEOBJECT:
3716  appendStringInfoString(&buffer, "large object");
3717  break;
3718 
3719  case OCLASS_OPERATOR:
3720  appendStringInfoString(&buffer, "operator");
3721  break;
3722 
3723  case OCLASS_OPCLASS:
3724  appendStringInfoString(&buffer, "operator class");
3725  break;
3726 
3727  case OCLASS_OPFAMILY:
3728  appendStringInfoString(&buffer, "operator family");
3729  break;
3730 
3731  case OCLASS_AMOP:
3732  appendStringInfoString(&buffer, "operator of access method");
3733  break;
3734 
3735  case OCLASS_AMPROC:
3736  appendStringInfoString(&buffer, "function of access method");
3737  break;
3738 
3739  case OCLASS_REWRITE:
3740  appendStringInfoString(&buffer, "rule");
3741  break;
3742 
3743  case OCLASS_TRIGGER:
3744  appendStringInfoString(&buffer, "trigger");
3745  break;
3746 
3747  case OCLASS_SCHEMA:
3748  appendStringInfoString(&buffer, "schema");
3749  break;
3750 
3751  case OCLASS_TSPARSER:
3752  appendStringInfoString(&buffer, "text search parser");
3753  break;
3754 
3755  case OCLASS_TSDICT:
3756  appendStringInfoString(&buffer, "text search dictionary");
3757  break;
3758 
3759  case OCLASS_TSTEMPLATE:
3760  appendStringInfoString(&buffer, "text search template");
3761  break;
3762 
3763  case OCLASS_TSCONFIG:
3764  appendStringInfoString(&buffer, "text search configuration");
3765  break;
3766 
3767  case OCLASS_ROLE:
3768  appendStringInfoString(&buffer, "role");
3769  break;
3770 
3771  case OCLASS_DATABASE:
3772  appendStringInfoString(&buffer, "database");
3773  break;
3774 
3775  case OCLASS_TBLSPACE:
3776  appendStringInfoString(&buffer, "tablespace");
3777  break;
3778 
3779  case OCLASS_FDW:
3780  appendStringInfoString(&buffer, "foreign-data wrapper");
3781  break;
3782 
3783  case OCLASS_FOREIGN_SERVER:
3784  appendStringInfoString(&buffer, "server");
3785  break;
3786 
3787  case OCLASS_USER_MAPPING:
3788  appendStringInfoString(&buffer, "user mapping");
3789  break;
3790 
3791  case OCLASS_DEFACL:
3792  appendStringInfoString(&buffer, "default acl");
3793  break;
3794 
3795  case OCLASS_EXTENSION:
3796  appendStringInfoString(&buffer, "extension");
3797  break;
3798 
3799  case OCLASS_EVENT_TRIGGER:
3800  appendStringInfoString(&buffer, "event trigger");
3801  break;
3802 
3803  case OCLASS_POLICY:
3804  appendStringInfoString(&buffer, "policy");
3805  break;
3806 
3807  case OCLASS_TRANSFORM:
3808  appendStringInfoString(&buffer, "transform");
3809  break;
3810 
3811  case OCLASS_AM:
3812  appendStringInfoString(&buffer, "access method");
3813  break;
3814 
3815  case OCLASS_PUBLICATION:
3816  appendStringInfoString(&buffer, "publication");
3817  break;
3818 
3820  appendStringInfoString(&buffer, "publication relation");
3821  break;
3822 
3823  case OCLASS_SUBSCRIPTION:
3824  appendStringInfoString(&buffer, "subscription");
3825  break;
3826 
3827  default:
3828  appendStringInfo(&buffer, "unrecognized %u", object->classId);
3829  break;
3830  }
3831 
3832  return buffer.data;
3833 }
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid)
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId)
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2312
static void getProcedureTypeDescription(StringInfo buffer, Oid procid)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
bool is_objectclass_supported ( Oid  class_id)

Definition at line 2488 of file objectaddress.c.

References lengthof.

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

2489 {
2490  int index;
2491 
2492  for (index = 0; index < lengthof(ObjectProperty); index++)
2493  {
2494  if (ObjectProperty[index].class_oid == class_id)
2495  return true;
2496  }
2497 
2498  return false;
2499 }
#define lengthof(array)
Definition: c.h:558
Definition: type.h:90
static const ObjectPropertyType ObjectProperty[]
int read_objtype_from_string ( const char *  objtype)

Definition at line 2392 of file objectaddress.c.

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

Referenced by pg_get_object_address().

2393 {
2394  int i;
2395 
2396  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2397  {
2398  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2399  return ObjectTypeMap[i].tm_type;
2400  }
2401  ereport(ERROR,
2402  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2403  errmsg("unrecognized object type \"%s\"", objtype)));
2404 
2405  return -1; /* keep compiler quiet */
2406 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:558
#define ERROR
Definition: elog.h:43
static const struct object_type_map ObjectTypeMap[]
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
ArrayType* strlist_to_textarray ( List list)

Definition at line 4936 of file objectaddress.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), construct_array(), CStringGetTextDatum, CurrentMemoryContext, lfirst, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), name, palloc(), and TEXTOID.

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

4937 {
4938  ArrayType *arr;
4939  Datum *datums;
4940  int j = 0;
4941  ListCell *cell;
4942  MemoryContext memcxt;
4943  MemoryContext oldcxt;
4944 
4946  "strlist to array",
4948  oldcxt = MemoryContextSwitchTo(memcxt);
4949 
4950  datums = palloc(sizeof(text *) * list_length(list));
4951  foreach(cell, list)
4952  {
4953  char *name = lfirst(cell);
4954 
4955  datums[j++] = CStringGetTextDatum(name);
4956  }
4957 
4958  MemoryContextSwitchTo(oldcxt);
4959 
4960  arr = construct_array(datums, list_length(list),
4961  TEXTOID, -1, false, 'i');
4962  MemoryContextDelete(memcxt);
4963 
4964  return arr;
4965 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
#define TEXTOID
Definition: pg_type.h:324
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:151
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:329
uintptr_t Datum
Definition: postgres.h:374
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:891
#define CStringGetTextDatum(s)
Definition: builtins.h:90
Definition: c.h:435

Variable Documentation