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, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
bool is_objectclass_supported (Oid class_id)
 
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 AlterCollation(), 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(), CreateStatistics(), 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(), SetFunctionArgType(), SetFunctionReturnType(), 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(), ATExecAddIdentity(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecColumnDefault(), ATExecDropIdentity(), ATExecDropNotNull(), ATExecSetIdentity(), ATExecSetNotNull(), ATExecSetOptions(), ATExecSetStatistics(), ATExecSetStorage(), CreateStatistics(), and renameatt().

Typedef Documentation

Function Documentation

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

Definition at line 2222 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, castNode, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), has_createrole_privilege(), linitial_node, lo_compat_privileges, lsecond_node, 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_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_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_statistics_object_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), RelationGetRelationName, RelationGetRelid, strVal, superuser_arg(), and typenameTypeId().

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

2224 {
2225  switch (objtype)
2226  {
2227  case OBJECT_INDEX:
2228  case OBJECT_SEQUENCE:
2229  case OBJECT_TABLE:
2230  case OBJECT_VIEW:
2231  case OBJECT_MATVIEW:
2232  case OBJECT_FOREIGN_TABLE:
2233  case OBJECT_COLUMN:
2234  case OBJECT_RULE:
2235  case OBJECT_TRIGGER:
2236  case OBJECT_POLICY:
2237  case OBJECT_TABCONSTRAINT:
2238  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2240  RelationGetRelationName(relation));
2241  break;
2242  case OBJECT_DATABASE:
2243  if (!pg_database_ownercheck(address.objectId, roleid))
2245  strVal((Value *) object));
2246  break;
2247  case OBJECT_TYPE:
2248  case OBJECT_DOMAIN:
2249  case OBJECT_ATTRIBUTE:
2250  case OBJECT_DOMCONSTRAINT:
2251  if (!pg_type_ownercheck(address.objectId, roleid))
2253  break;
2254  case OBJECT_AGGREGATE:
2255  case OBJECT_FUNCTION:
2256  if (!pg_proc_ownercheck(address.objectId, roleid))
2258  NameListToString((castNode(ObjectWithArgs, object))->objname));
2259  break;
2260  case OBJECT_OPERATOR:
2261  if (!pg_oper_ownercheck(address.objectId, roleid))
2263  NameListToString((castNode(ObjectWithArgs, object))->objname));
2264  break;
2265  case OBJECT_SCHEMA:
2266  if (!pg_namespace_ownercheck(address.objectId, roleid))
2268  strVal((Value *) object));
2269  break;
2270  case OBJECT_COLLATION:
2271  if (!pg_collation_ownercheck(address.objectId, roleid))
2273  NameListToString(castNode(List, object)));
2274  break;
2275  case OBJECT_CONVERSION:
2276  if (!pg_conversion_ownercheck(address.objectId, roleid))
2278  NameListToString(castNode(List, object)));
2279  break;
2280  case OBJECT_EXTENSION:
2281  if (!pg_extension_ownercheck(address.objectId, roleid))
2283  strVal((Value *) object));
2284  break;
2285  case OBJECT_FDW:
2286  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2288  strVal((Value *) object));
2289  break;
2290  case OBJECT_FOREIGN_SERVER:
2291  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2293  strVal((Value *) object));
2294  break;
2295  case OBJECT_EVENT_TRIGGER:
2296  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2298  strVal((Value *) object));
2299  break;
2300  case OBJECT_LANGUAGE:
2301  if (!pg_language_ownercheck(address.objectId, roleid))
2303  strVal((Value *) object));
2304  break;
2305  case OBJECT_OPCLASS:
2306  if (!pg_opclass_ownercheck(address.objectId, roleid))
2308  NameListToString(castNode(List, object)));
2309  break;
2310  case OBJECT_OPFAMILY:
2311  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2313  NameListToString(castNode(List, object)));
2314  break;
2315  case OBJECT_LARGEOBJECT:
2316  if (!lo_compat_privileges &&
2317  !pg_largeobject_ownercheck(address.objectId, roleid))
2318  ereport(ERROR,
2319  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2320  errmsg("must be owner of large object %u",
2321  address.objectId)));
2322  break;
2323  case OBJECT_CAST:
2324  {
2325  /* We can only check permissions on the source/target types */
2326  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2327  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2328  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2329  Oid targettypeid = typenameTypeId(NULL, targettype);
2330 
2331  if (!pg_type_ownercheck(sourcetypeid, roleid)
2332  && !pg_type_ownercheck(targettypeid, roleid))
2333  ereport(ERROR,
2334  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2335  errmsg("must be owner of type %s or type %s",
2336  format_type_be(sourcetypeid),
2337  format_type_be(targettypeid))));
2338  }
2339  break;
2340  case OBJECT_PUBLICATION:
2341  if (!pg_publication_ownercheck(address.objectId, roleid))
2343  strVal((Value *) object));
2344  break;
2345  case OBJECT_SUBSCRIPTION:
2346  if (!pg_subscription_ownercheck(address.objectId, roleid))
2348  strVal((Value *) object));
2349  break;
2350  case OBJECT_TRANSFORM:
2351  {
2352  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2353  Oid typeid = typenameTypeId(NULL, typename);
2354 
2355  if (!pg_type_ownercheck(typeid, roleid))
2357  }
2358  break;
2359  case OBJECT_TABLESPACE:
2360  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2362  strVal((Value *) object));
2363  break;
2364  case OBJECT_TSDICTIONARY:
2365  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2367  NameListToString(castNode(List, object)));
2368  break;
2370  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2372  NameListToString(castNode(List, object)));
2373  break;
2374  case OBJECT_ROLE:
2375 
2376  /*
2377  * We treat roles as being "owned" by those with CREATEROLE priv,
2378  * except that superusers are only owned by superusers.
2379  */
2380  if (superuser_arg(address.objectId))
2381  {
2382  if (!superuser_arg(roleid))
2383  ereport(ERROR,
2384  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2385  errmsg("must be superuser")));
2386  }
2387  else
2388  {
2389  if (!has_createrole_privilege(roleid))
2390  ereport(ERROR,
2391  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2392  errmsg("must have CREATEROLE privilege")));
2393  }
2394  break;
2395  case OBJECT_TSPARSER:
2396  case OBJECT_TSTEMPLATE:
2397  case OBJECT_ACCESS_METHOD:
2398  /* We treat these object types as being owned by superusers */
2399  if (!superuser_arg(roleid))
2400  ereport(ERROR,
2401  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2402  errmsg("must be superuser")));
2403  break;
2404  case OBJECT_STATISTIC_EXT:
2405  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2407  break;
2408  default:
2409  elog(ERROR, "unrecognized object type: %d",
2410  (int) objtype);
2411  }
2412 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5171
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:4990
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4679
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4829
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4650
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4856
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4910
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5084
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4598
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:4722
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4572
#define linitial_node(type, l)
Definition: pg_list.h:114
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3457
bool lo_compat_privileges
Definition: be-fsstubs.c:57
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:4937
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5042
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RelationGetRelationName(relation)
Definition: rel.h:436
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4748
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4802
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:4964
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:3063
#define lsecond_node(type, l)
Definition: pg_list.h:119
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4775
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5016
#define NULL
Definition: c.h:229
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4546
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4883
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define RelationGetRelid(relation)
Definition: rel.h:416
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4624
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5110
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5136
HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

Definition at line 2608 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().

2609 {
2610  HeapTuple tuple;
2611  Oid classId = RelationGetRelid(catalog);
2612  int oidCacheId = get_object_catcache_oid(classId);
2613 
2614  if (oidCacheId > 0)
2615  {
2616  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2617  if (!HeapTupleIsValid(tuple)) /* should not happen */
2618  return NULL;
2619  }
2620  else
2621  {
2622  Oid oidIndexId = get_object_oid_index(classId);
2623  SysScanDesc scan;
2624  ScanKeyData skey;
2625 
2626  Assert(OidIsValid(oidIndexId));
2627 
2628  ScanKeyInit(&skey,
2630  BTEqualStrategyNumber, F_OIDEQ,
2631  ObjectIdGetDatum(objectId));
2632 
2633  scan = systable_beginscan(catalog, oidIndexId, true,
2634  NULL, 1, &skey);
2635  tuple = systable_getnext(scan);
2636  if (!HeapTupleIsValid(tuple))
2637  {
2638  systable_endscan(scan);
2639  return NULL;
2640  }
2641  tuple = heap_copytuple(tuple);
2642 
2643  systable_endscan(scan);
2644  }
2645 
2646  return tuple;
2647 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#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:538
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:165
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:416
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclObjectKind get_object_aclkind ( Oid  class_id)

Definition at line 2536 of file objectaddress.c.

References ObjectPropertyType::acl_kind, and get_object_property_data().

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

2537 {
2538  const ObjectPropertyType *prop = get_object_property_data(class_id);
2539 
2540  return prop->acl_kind;
2541 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AclObjectKind acl_kind
ObjectAddress get_object_address ( ObjectType  objtype,
Node object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 795 of file objectaddress.c.

References Assert, castNode, 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_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), LargeObjectRelationId, linitial_node, LockDatabaseObject(), LockSharedObject(), LookupAggWithArgs(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, 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_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), OperatorRelationId, ProcedureRelationId, RelationRelationId, SharedInvalidMessageCounter, StatisticExtRelationId, 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().

797 {
798  ObjectAddress address;
799  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
800  Relation relation = NULL;
801  uint64 inval_count;
802 
803  /* Some kind of lock must be taken. */
804  Assert(lockmode != NoLock);
805 
806  for (;;)
807  {
808  /*
809  * Remember this value, so that, after looking up the object name and
810  * locking it, we can check whether any invalidation messages have
811  * been processed that might require a do-over.
812  */
813  inval_count = SharedInvalidMessageCounter;
814 
815  /* Look up object address. */
816  switch (objtype)
817  {
818  case OBJECT_INDEX:
819  case OBJECT_SEQUENCE:
820  case OBJECT_TABLE:
821  case OBJECT_VIEW:
822  case OBJECT_MATVIEW:
824  address =
825  get_relation_by_qualified_name(objtype, castNode(List, object),
826  &relation, lockmode,
827  missing_ok);
828  break;
829  case OBJECT_COLUMN:
830  address =
831  get_object_address_attribute(objtype, castNode(List, object),
832  &relation, lockmode,
833  missing_ok);
834  break;
835  case OBJECT_DEFAULT:
836  address =
837  get_object_address_attrdef(objtype, castNode(List, object),
838  &relation, lockmode,
839  missing_ok);
840  break;
841  case OBJECT_RULE:
842  case OBJECT_TRIGGER:
844  case OBJECT_POLICY:
845  address = get_object_address_relobject(objtype, castNode(List, object),
846  &relation, missing_ok);
847  break;
849  {
850  List *objlist;
851  ObjectAddress domaddr;
852  char *constrname;
853 
854  objlist = castNode(List, object);
856  linitial_node(TypeName, objlist),
857  missing_ok);
858  constrname = strVal(lsecond(objlist));
859 
860  address.classId = ConstraintRelationId;
861  address.objectId = get_domain_constraint_oid(domaddr.objectId,
862  constrname, missing_ok);
863  address.objectSubId = 0;
864 
865  }
866  break;
867  case OBJECT_DATABASE:
868  case OBJECT_EXTENSION:
869  case OBJECT_TABLESPACE:
870  case OBJECT_ROLE:
871  case OBJECT_SCHEMA:
872  case OBJECT_LANGUAGE:
873  case OBJECT_FDW:
877  case OBJECT_PUBLICATION:
878  case OBJECT_SUBSCRIPTION:
879  address = get_object_address_unqualified(objtype,
880  (Value *) object, missing_ok);
881  break;
882  case OBJECT_TYPE:
883  case OBJECT_DOMAIN:
884  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
885  break;
886  case OBJECT_AGGREGATE:
887  address.classId = ProcedureRelationId;
888  address.objectId = LookupAggWithArgs(castNode(ObjectWithArgs, object), missing_ok);
889  address.objectSubId = 0;
890  break;
891  case OBJECT_FUNCTION:
892  address.classId = ProcedureRelationId;
893  address.objectId = LookupFuncWithArgs(castNode(ObjectWithArgs, object), missing_ok);
894  address.objectSubId = 0;
895  break;
896  case OBJECT_OPERATOR:
897  address.classId = OperatorRelationId;
898  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
899  address.objectSubId = 0;
900  break;
901  case OBJECT_COLLATION:
902  address.classId = CollationRelationId;
903  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
904  address.objectSubId = 0;
905  break;
906  case OBJECT_CONVERSION:
907  address.classId = ConversionRelationId;
908  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
909  address.objectSubId = 0;
910  break;
911  case OBJECT_OPCLASS:
912  case OBJECT_OPFAMILY:
913  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
914  break;
915  case OBJECT_AMOP:
916  case OBJECT_AMPROC:
917  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
918  break;
919  case OBJECT_LARGEOBJECT:
920  address.classId = LargeObjectRelationId;
921  address.objectId = oidparse(object);
922  address.objectSubId = 0;
923  if (!LargeObjectExists(address.objectId))
924  {
925  if (!missing_ok)
926  ereport(ERROR,
927  (errcode(ERRCODE_UNDEFINED_OBJECT),
928  errmsg("large object %u does not exist",
929  address.objectId)));
930  }
931  break;
932  case OBJECT_CAST:
933  {
934  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
935  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
936  Oid sourcetypeid;
937  Oid targettypeid;
938 
939  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
940  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
941  address.classId = CastRelationId;
942  address.objectId =
943  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
944  address.objectSubId = 0;
945  }
946  break;
947  case OBJECT_TRANSFORM:
948  {
949  TypeName *typename = linitial_node(TypeName, castNode(List, object));
950  char *langname = strVal(lsecond(castNode(List, object)));
951  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
952  Oid lang_id = get_language_oid(langname, missing_ok);
953 
954  address.classId = TransformRelationId;
955  address.objectId =
956  get_transform_oid(type_id, lang_id, missing_ok);
957  address.objectSubId = 0;
958  }
959  break;
960  case OBJECT_TSPARSER:
961  address.classId = TSParserRelationId;
962  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
963  address.objectSubId = 0;
964  break;
965  case OBJECT_TSDICTIONARY:
967  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
968  address.objectSubId = 0;
969  break;
970  case OBJECT_TSTEMPLATE:
971  address.classId = TSTemplateRelationId;
972  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
973  address.objectSubId = 0;
974  break;
976  address.classId = TSConfigRelationId;
977  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
978  address.objectSubId = 0;
979  break;
980  case OBJECT_USER_MAPPING:
981  address = get_object_address_usermapping(castNode(List, object),
982  missing_ok);
983  break;
986  &relation,
987  missing_ok);
988  break;
989  case OBJECT_DEFACL:
990  address = get_object_address_defacl(castNode(List, object),
991  missing_ok);
992  break;
995  address.objectId = get_statistics_object_oid(castNode(List, object),
996  missing_ok);
997  address.objectSubId = 0;
998  break;
999  default:
1000  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1001  /* placate compiler, in case it thinks elog might return */
1002  address.classId = InvalidOid;
1003  address.objectId = InvalidOid;
1004  address.objectSubId = 0;
1005  }
1006 
1007  /*
1008  * If we could not find the supplied object, return without locking.
1009  */
1010  if (!OidIsValid(address.objectId))
1011  {
1012  Assert(missing_ok);
1013  return address;
1014  }
1015 
1016  /*
1017  * If we're retrying, see if we got the same answer as last time. If
1018  * so, we're done; if not, we locked the wrong thing, so give up our
1019  * lock.
1020  */
1021  if (OidIsValid(old_address.classId))
1022  {
1023  if (old_address.classId == address.classId
1024  && old_address.objectId == address.objectId
1025  && old_address.objectSubId == address.objectSubId)
1026  break;
1027  if (old_address.classId != RelationRelationId)
1028  {
1029  if (IsSharedRelation(old_address.classId))
1030  UnlockSharedObject(old_address.classId,
1031  old_address.objectId,
1032  0, lockmode);
1033  else
1034  UnlockDatabaseObject(old_address.classId,
1035  old_address.objectId,
1036  0, lockmode);
1037  }
1038  }
1039 
1040  /*
1041  * If we're dealing with a relation or attribute, then the relation is
1042  * already locked. Otherwise, we lock it now.
1043  */
1044  if (address.classId != RelationRelationId)
1045  {
1046  if (IsSharedRelation(address.classId))
1047  LockSharedObject(address.classId, address.objectId, 0,
1048  lockmode);
1049  else
1050  LockDatabaseObject(address.classId, address.objectId, 0,
1051  lockmode);
1052  }
1053 
1054  /*
1055  * At this point, we've resolved the name to an OID and locked the
1056  * corresponding database object. However, it's possible that by the
1057  * time we acquire the lock on the object, concurrent DDL has modified
1058  * the database in such a way that the name we originally looked up no
1059  * longer resolves to that OID.
1060  *
1061  * We can be certain that this isn't an issue if (a) no shared
1062  * invalidation messages have been processed or (b) we've locked a
1063  * relation somewhere along the line. All the relation name lookups
1064  * in this module ultimately use RangeVarGetRelid() to acquire a
1065  * relation lock, and that function protects against the same kinds of
1066  * races we're worried about here. Even when operating on a
1067  * constraint, rule, or trigger, we still acquire AccessShareLock on
1068  * the relation, which is enough to freeze out any concurrent DDL.
1069  *
1070  * In all other cases, however, it's possible that the name we looked
1071  * up no longer refers to the object we locked, so we retry the lookup
1072  * and see whether we get the same answer.
1073  */
1074  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1075  break;
1076  old_address = address;
1077  }
1078 
1079  /* Return the object address and the relation. */
1080  *relp = relation;
1081  return address;
1082 }
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition: parse_oper.c:140
#define OperatorRelationId
Definition: pg_operator.h:32
static ObjectAddress get_object_address_usermapping(List *object, bool missing_ok)
static ObjectAddress get_object_address_publication_rel(List *object, Relation *relp, bool missing_ok)
Oid oidparse(Node *node)
Definition: oid.c:314
#define TransformRelationId
Definition: pg_transform.h:25
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
#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
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2639
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial_node(type, l)
Definition: pg_list.h:114
static ObjectAddress get_object_address_unqualified(ObjectType objtype, Value *strval, bool missing_ok)
#define OidIsValid(objectId)
Definition: c.h:538
#define lsecond(l)
Definition: pg_list.h:116
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define TSConfigRelationId
Definition: pg_ts_config.h:31
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2386
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
#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_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2138
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2513
#define NoLock
Definition: lockdefs.h:34
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:830
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *object, bool missing_ok)
#define ereport(elevel, rest)
Definition: elog.h:122
Oid LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
Definition: parse_func.c:1990
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:851
#define lsecond_node(type, l)
Definition: pg_list.h:119
Oid LookupAggWithArgs(ObjectWithArgs *agg, bool noError)
Definition: parse_func.c:2027
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:220
#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:229
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2260
#define Assert(condition)
Definition: c.h:675
#define StatisticExtRelationId
Definition: value.h:42
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
#define CastRelationId
Definition: pg_cast.h:31
Oid get_conversion_oid(List *name, bool missing_ok)
Definition: namespace.c:3547
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:3493
Definition: pg_list.h:45
#define ConversionRelationId
Definition: pg_conversion.h:38
#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 object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 1092 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1095 {
1096  if (rel)
1097  {
1098  object = lcons(makeString(rel->relname), object);
1099  if (rel->schemaname)
1100  object = lcons(makeString(rel->schemaname), object);
1101  if (rel->catalogname)
1102  object = lcons(makeString(rel->catalogname), object);
1103  }
1104 
1105  return get_object_address(objtype, (Node *) object,
1106  relp, lockmode, missing_ok);
1107 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:509
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:259
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
char * catalogname
Definition: primnodes.h:66
AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2528 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2529 {
2530  const ObjectPropertyType *prop = get_object_property_data(class_id);
2531 
2532  return prop->attnum_acl;
2533 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl
AttrNumber get_object_attnum_name ( Oid  class_id)

Definition at line 2504 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().

2505 {
2506  const ObjectPropertyType *prop = get_object_property_data(class_id);
2507 
2508  return prop->attnum_name;
2509 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber get_object_attnum_namespace ( Oid  class_id)

Definition at line 2512 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().

2513 {
2514  const ObjectPropertyType *prop = get_object_property_data(class_id);
2515 
2516  return prop->attnum_namespace;
2517 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace
AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2520 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2521 {
2522  const ObjectPropertyType *prop = get_object_property_data(class_id);
2523 
2524  return prop->attnum_owner;
2525 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_name ( Oid  class_id)

Definition at line 2496 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2497 {
2498  const ObjectPropertyType *prop = get_object_property_data(class_id);
2499 
2500  return prop->name_catcache_id;
2501 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_oid ( Oid  class_id)

Definition at line 2488 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().

2489 {
2490  const ObjectPropertyType *prop = get_object_property_data(class_id);
2491 
2492  return prop->oid_catcache_id;
2493 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2544 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2545 {
2546  const ObjectPropertyType *prop = get_object_property_data(class_id);
2547 
2548  return prop->is_nsp_name_unique;
2549 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2421 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().

2422 {
2423  int cache;
2424  HeapTuple tuple;
2425  bool isnull;
2426  Oid oid;
2427  const ObjectPropertyType *property;
2428 
2429  /* If not owned by a namespace, just return InvalidOid. */
2430  property = get_object_property_data(address->classId);
2431  if (property->attnum_namespace == InvalidAttrNumber)
2432  return InvalidOid;
2433 
2434  /* Currently, we can only handle object types with system caches. */
2435  cache = property->oid_catcache_id;
2436  Assert(cache != -1);
2437 
2438  /* Fetch tuple from syscache and extract namespace attribute. */
2439  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2440  if (!HeapTupleIsValid(tuple))
2441  elog(ERROR, "cache lookup failed for cache %d oid %u",
2442  cache, address->objectId);
2443  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2444  tuple,
2445  property->attnum_namespace,
2446  &isnull));
2447  Assert(!isnull);
2448  ReleaseSysCache(tuple);
2449 
2450  return oid;
2451 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1279
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:675
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 2480 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2481 {
2482  const ObjectPropertyType *prop = get_object_property_data(class_id);
2483 
2484  return prop->oid_index_oid;
2485 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
char* getObjectDescription ( const ObjectAddress object)

Definition at line 2655 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, buffer, CastOidIndexId, CastRelationId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DEFACLOBJ_FUNCTION, DEFACLOBJ_NAMESPACE, 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_STATISTIC_EXT, 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, STATEXTOID, 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().

2656 {
2658 
2659  initStringInfo(&buffer);
2660 
2661  switch (getObjectClass(object))
2662  {
2663  case OCLASS_CLASS:
2664  getRelationDescription(&buffer, object->objectId);
2665  if (object->objectSubId != 0)
2666  appendStringInfo(&buffer, _(" column %s"),
2668  object->objectSubId));
2669  break;
2670 
2671  case OCLASS_PROC:
2672  appendStringInfo(&buffer, _("function %s"),
2673  format_procedure(object->objectId));
2674  break;
2675 
2676  case OCLASS_TYPE:
2677  appendStringInfo(&buffer, _("type %s"),
2678  format_type_be(object->objectId));
2679  break;
2680 
2681  case OCLASS_CAST:
2682  {
2683  Relation castDesc;
2684  ScanKeyData skey[1];
2685  SysScanDesc rcscan;
2686  HeapTuple tup;
2687  Form_pg_cast castForm;
2688 
2690 
2691  ScanKeyInit(&skey[0],
2693  BTEqualStrategyNumber, F_OIDEQ,
2694  ObjectIdGetDatum(object->objectId));
2695 
2696  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2697  NULL, 1, skey);
2698 
2699  tup = systable_getnext(rcscan);
2700 
2701  if (!HeapTupleIsValid(tup))
2702  elog(ERROR, "could not find tuple for cast %u",
2703  object->objectId);
2704 
2705  castForm = (Form_pg_cast) GETSTRUCT(tup);
2706 
2707  appendStringInfo(&buffer, _("cast from %s to %s"),
2708  format_type_be(castForm->castsource),
2709  format_type_be(castForm->casttarget));
2710 
2711  systable_endscan(rcscan);
2712  heap_close(castDesc, AccessShareLock);
2713  break;
2714  }
2715 
2716  case OCLASS_COLLATION:
2717  {
2718  HeapTuple collTup;
2719  Form_pg_collation coll;
2720 
2721  collTup = SearchSysCache1(COLLOID,
2722  ObjectIdGetDatum(object->objectId));
2723  if (!HeapTupleIsValid(collTup))
2724  elog(ERROR, "cache lookup failed for collation %u",
2725  object->objectId);
2726  coll = (Form_pg_collation) GETSTRUCT(collTup);
2727  appendStringInfo(&buffer, _("collation %s"),
2728  NameStr(coll->collname));
2729  ReleaseSysCache(collTup);
2730  break;
2731  }
2732 
2733  case OCLASS_CONSTRAINT:
2734  {
2735  HeapTuple conTup;
2736  Form_pg_constraint con;
2737 
2738  conTup = SearchSysCache1(CONSTROID,
2739  ObjectIdGetDatum(object->objectId));
2740  if (!HeapTupleIsValid(conTup))
2741  elog(ERROR, "cache lookup failed for constraint %u",
2742  object->objectId);
2743  con = (Form_pg_constraint) GETSTRUCT(conTup);
2744 
2745  if (OidIsValid(con->conrelid))
2746  {
2747  StringInfoData rel;
2748 
2749  initStringInfo(&rel);
2750  getRelationDescription(&rel, con->conrelid);
2751  appendStringInfo(&buffer, _("constraint %s on %s"),
2752  NameStr(con->conname), rel.data);
2753  pfree(rel.data);
2754  }
2755  else
2756  {
2757  appendStringInfo(&buffer, _("constraint %s"),
2758  NameStr(con->conname));
2759  }
2760 
2761  ReleaseSysCache(conTup);
2762  break;
2763  }
2764 
2765  case OCLASS_CONVERSION:
2766  {
2767  HeapTuple conTup;
2768 
2769  conTup = SearchSysCache1(CONVOID,
2770  ObjectIdGetDatum(object->objectId));
2771  if (!HeapTupleIsValid(conTup))
2772  elog(ERROR, "cache lookup failed for conversion %u",
2773  object->objectId);
2774  appendStringInfo(&buffer, _("conversion %s"),
2775  NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2776  ReleaseSysCache(conTup);
2777  break;
2778  }
2779 
2780  case OCLASS_DEFAULT:
2781  {
2782  Relation attrdefDesc;
2783  ScanKeyData skey[1];
2784  SysScanDesc adscan;
2785  HeapTuple tup;
2786  Form_pg_attrdef attrdef;
2787  ObjectAddress colobject;
2788 
2790 
2791  ScanKeyInit(&skey[0],
2793  BTEqualStrategyNumber, F_OIDEQ,
2794  ObjectIdGetDatum(object->objectId));
2795 
2796  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2797  true, NULL, 1, skey);
2798 
2799  tup = systable_getnext(adscan);
2800 
2801  if (!HeapTupleIsValid(tup))
2802  elog(ERROR, "could not find tuple for attrdef %u",
2803  object->objectId);
2804 
2805  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2806 
2807  colobject.classId = RelationRelationId;
2808  colobject.objectId = attrdef->adrelid;
2809  colobject.objectSubId = attrdef->adnum;
2810 
2811  appendStringInfo(&buffer, _("default for %s"),
2812  getObjectDescription(&colobject));
2813 
2814  systable_endscan(adscan);
2815  heap_close(attrdefDesc, AccessShareLock);
2816  break;
2817  }
2818 
2819  case OCLASS_LANGUAGE:
2820  appendStringInfo(&buffer, _("language %s"),
2821  get_language_name(object->objectId, false));
2822  break;
2823 
2824  case OCLASS_LARGEOBJECT:
2825  appendStringInfo(&buffer, _("large object %u"),
2826  object->objectId);
2827  break;
2828 
2829  case OCLASS_OPERATOR:
2830  appendStringInfo(&buffer, _("operator %s"),
2831  format_operator(object->objectId));
2832  break;
2833 
2834  case OCLASS_OPCLASS:
2835  {
2836  HeapTuple opcTup;
2837  Form_pg_opclass opcForm;
2838  HeapTuple amTup;
2839  Form_pg_am amForm;
2840  char *nspname;
2841 
2842  opcTup = SearchSysCache1(CLAOID,
2843  ObjectIdGetDatum(object->objectId));
2844  if (!HeapTupleIsValid(opcTup))
2845  elog(ERROR, "cache lookup failed for opclass %u",
2846  object->objectId);
2847  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2848 
2849  amTup = SearchSysCache1(AMOID,
2850  ObjectIdGetDatum(opcForm->opcmethod));
2851  if (!HeapTupleIsValid(amTup))
2852  elog(ERROR, "cache lookup failed for access method %u",
2853  opcForm->opcmethod);
2854  amForm = (Form_pg_am) GETSTRUCT(amTup);
2855 
2856  /* Qualify the name if not visible in search path */
2857  if (OpclassIsVisible(object->objectId))
2858  nspname = NULL;
2859  else
2860  nspname = get_namespace_name(opcForm->opcnamespace);
2861 
2862  appendStringInfo(&buffer, _("operator class %s for access method %s"),
2864  NameStr(opcForm->opcname)),
2865  NameStr(amForm->amname));
2866 
2867  ReleaseSysCache(amTup);
2868  ReleaseSysCache(opcTup);
2869  break;
2870  }
2871 
2872  case OCLASS_OPFAMILY:
2873  getOpFamilyDescription(&buffer, object->objectId);
2874  break;
2875 
2876  case OCLASS_AM:
2877  {
2878  HeapTuple tup;
2879 
2880  tup = SearchSysCache1(AMOID,
2881  ObjectIdGetDatum(object->objectId));
2882  if (!HeapTupleIsValid(tup))
2883  elog(ERROR, "cache lookup failed for access method %u",
2884  object->objectId);
2885  appendStringInfo(&buffer, _("access method %s"),
2886  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
2887  ReleaseSysCache(tup);
2888  break;
2889  }
2890 
2891  case OCLASS_AMOP:
2892  {
2893  Relation amopDesc;
2894  HeapTuple tup;
2895  ScanKeyData skey[1];
2896  SysScanDesc amscan;
2897  Form_pg_amop amopForm;
2898  StringInfoData opfam;
2899 
2901  AccessShareLock);
2902 
2903  ScanKeyInit(&skey[0],
2905  BTEqualStrategyNumber, F_OIDEQ,
2906  ObjectIdGetDatum(object->objectId));
2907 
2908  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
2909  NULL, 1, skey);
2910 
2911  tup = systable_getnext(amscan);
2912 
2913  if (!HeapTupleIsValid(tup))
2914  elog(ERROR, "could not find tuple for amop entry %u",
2915  object->objectId);
2916 
2917  amopForm = (Form_pg_amop) GETSTRUCT(tup);
2918 
2919  initStringInfo(&opfam);
2920  getOpFamilyDescription(&opfam, amopForm->amopfamily);
2921 
2922  /*------
2923  translator: %d is the operator strategy (a number), the
2924  first two %s's are data type names, the third %s is the
2925  description of the operator family, and the last %s is the
2926  textual form of the operator with arguments. */
2927  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
2928  amopForm->amopstrategy,
2929  format_type_be(amopForm->amoplefttype),
2930  format_type_be(amopForm->amoprighttype),
2931  opfam.data,
2932  format_operator(amopForm->amopopr));
2933 
2934  pfree(opfam.data);
2935 
2936  systable_endscan(amscan);
2937  heap_close(amopDesc, AccessShareLock);
2938  break;
2939  }
2940 
2941  case OCLASS_AMPROC:
2942  {
2943  Relation amprocDesc;
2944  ScanKeyData skey[1];
2945  SysScanDesc amscan;
2946  HeapTuple tup;
2947  Form_pg_amproc amprocForm;
2948  StringInfoData opfam;
2949 
2951  AccessShareLock);
2952 
2953  ScanKeyInit(&skey[0],
2955  BTEqualStrategyNumber, F_OIDEQ,
2956  ObjectIdGetDatum(object->objectId));
2957 
2958  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
2959  NULL, 1, skey);
2960 
2961  tup = systable_getnext(amscan);
2962 
2963  if (!HeapTupleIsValid(tup))
2964  elog(ERROR, "could not find tuple for amproc entry %u",
2965  object->objectId);
2966 
2967  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
2968 
2969  initStringInfo(&opfam);
2970  getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
2971 
2972  /*------
2973  translator: %d is the function number, the first two %s's
2974  are data type names, the third %s is the description of the
2975  operator family, and the last %s is the textual form of the
2976  function with arguments. */
2977  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
2978  amprocForm->amprocnum,
2979  format_type_be(amprocForm->amproclefttype),
2980  format_type_be(amprocForm->amprocrighttype),
2981  opfam.data,
2982  format_procedure(amprocForm->amproc));
2983 
2984  pfree(opfam.data);
2985 
2986  systable_endscan(amscan);
2987  heap_close(amprocDesc, AccessShareLock);
2988  break;
2989  }
2990 
2991  case OCLASS_REWRITE:
2992  {
2993  Relation ruleDesc;
2994  ScanKeyData skey[1];
2995  SysScanDesc rcscan;
2996  HeapTuple tup;
2998 
3000 
3001  ScanKeyInit(&skey[0],
3003  BTEqualStrategyNumber, F_OIDEQ,
3004  ObjectIdGetDatum(object->objectId));
3005 
3006  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3007  NULL, 1, skey);
3008 
3009  tup = systable_getnext(rcscan);
3010 
3011  if (!HeapTupleIsValid(tup))
3012  elog(ERROR, "could not find tuple for rule %u",
3013  object->objectId);
3014 
3015  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3016 
3017  appendStringInfo(&buffer, _("rule %s on "),
3018  NameStr(rule->rulename));
3019  getRelationDescription(&buffer, rule->ev_class);
3020 
3021  systable_endscan(rcscan);
3022  heap_close(ruleDesc, AccessShareLock);
3023  break;
3024  }
3025 
3026  case OCLASS_TRIGGER:
3027  {
3028  Relation trigDesc;
3029  ScanKeyData skey[1];
3030  SysScanDesc tgscan;
3031  HeapTuple tup;
3032  Form_pg_trigger trig;
3033 
3035 
3036  ScanKeyInit(&skey[0],
3038  BTEqualStrategyNumber, F_OIDEQ,
3039  ObjectIdGetDatum(object->objectId));
3040 
3041  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3042  NULL, 1, skey);
3043 
3044  tup = systable_getnext(tgscan);
3045 
3046  if (!HeapTupleIsValid(tup))
3047  elog(ERROR, "could not find tuple for trigger %u",
3048  object->objectId);
3049 
3050  trig = (Form_pg_trigger) GETSTRUCT(tup);
3051 
3052  appendStringInfo(&buffer, _("trigger %s on "),
3053  NameStr(trig->tgname));
3054  getRelationDescription(&buffer, trig->tgrelid);
3055 
3056  systable_endscan(tgscan);
3057  heap_close(trigDesc, AccessShareLock);
3058  break;
3059  }
3060 
3061  case OCLASS_SCHEMA:
3062  {
3063  char *nspname;
3064 
3065  nspname = get_namespace_name(object->objectId);
3066  if (!nspname)
3067  elog(ERROR, "cache lookup failed for namespace %u",
3068  object->objectId);
3069  appendStringInfo(&buffer, _("schema %s"), nspname);
3070  break;
3071  }
3072 
3073  case OCLASS_STATISTIC_EXT:
3074  {
3075  HeapTuple stxTup;
3076  Form_pg_statistic_ext stxForm;
3077 
3078  stxTup = SearchSysCache1(STATEXTOID,
3079  ObjectIdGetDatum(object->objectId));
3080  if (!HeapTupleIsValid(stxTup))
3081  elog(ERROR, "could not find tuple for statistics object %u",
3082  object->objectId);
3083 
3084  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3085 
3086  appendStringInfo(&buffer, _("statistics object %s"),
3087  NameStr(stxForm->stxname));
3088 
3089  ReleaseSysCache(stxTup);
3090  break;
3091  }
3092 
3093  case OCLASS_TSPARSER:
3094  {
3095  HeapTuple tup;
3096 
3098  ObjectIdGetDatum(object->objectId));
3099  if (!HeapTupleIsValid(tup))
3100  elog(ERROR, "cache lookup failed for text search parser %u",
3101  object->objectId);
3102  appendStringInfo(&buffer, _("text search parser %s"),
3103  NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
3104  ReleaseSysCache(tup);
3105  break;
3106  }
3107 
3108  case OCLASS_TSDICT:
3109  {
3110  HeapTuple tup;
3111 
3112  tup = SearchSysCache1(TSDICTOID,
3113  ObjectIdGetDatum(object->objectId));
3114  if (!HeapTupleIsValid(tup))
3115  elog(ERROR, "cache lookup failed for text search dictionary %u",
3116  object->objectId);
3117  appendStringInfo(&buffer, _("text search dictionary %s"),
3118  NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
3119  ReleaseSysCache(tup);
3120  break;
3121  }
3122 
3123  case OCLASS_TSTEMPLATE:
3124  {
3125  HeapTuple tup;
3126 
3128  ObjectIdGetDatum(object->objectId));
3129  if (!HeapTupleIsValid(tup))
3130  elog(ERROR, "cache lookup failed for text search template %u",
3131  object->objectId);
3132  appendStringInfo(&buffer, _("text search template %s"),
3133  NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
3134  ReleaseSysCache(tup);
3135  break;
3136  }
3137 
3138  case OCLASS_TSCONFIG:
3139  {
3140  HeapTuple tup;
3141 
3143  ObjectIdGetDatum(object->objectId));
3144  if (!HeapTupleIsValid(tup))
3145  elog(ERROR, "cache lookup failed for text search configuration %u",
3146  object->objectId);
3147  appendStringInfo(&buffer, _("text search configuration %s"),
3148  NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
3149  ReleaseSysCache(tup);
3150  break;
3151  }
3152 
3153  case OCLASS_ROLE:
3154  {
3155  appendStringInfo(&buffer, _("role %s"),
3156  GetUserNameFromId(object->objectId, false));
3157  break;
3158  }
3159 
3160  case OCLASS_DATABASE:
3161  {
3162  char *datname;
3163 
3164  datname = get_database_name(object->objectId);
3165  if (!datname)
3166  elog(ERROR, "cache lookup failed for database %u",
3167  object->objectId);
3168  appendStringInfo(&buffer, _("database %s"), datname);
3169  break;
3170  }
3171 
3172  case OCLASS_TBLSPACE:
3173  {
3174  char *tblspace;
3175 
3176  tblspace = get_tablespace_name(object->objectId);
3177  if (!tblspace)
3178  elog(ERROR, "cache lookup failed for tablespace %u",
3179  object->objectId);
3180  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3181  break;
3182  }
3183 
3184  case OCLASS_FDW:
3185  {
3186  ForeignDataWrapper *fdw;
3187 
3188  fdw = GetForeignDataWrapper(object->objectId);
3189  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3190  break;
3191  }
3192 
3193  case OCLASS_FOREIGN_SERVER:
3194  {
3195  ForeignServer *srv;
3196 
3197  srv = GetForeignServer(object->objectId);
3198  appendStringInfo(&buffer, _("server %s"), srv->servername);
3199  break;
3200  }
3201 
3202  case OCLASS_USER_MAPPING:
3203  {
3204  HeapTuple tup;
3205  Oid useid;
3206  char *usename;
3207  Form_pg_user_mapping umform;
3208  ForeignServer *srv;
3209 
3211  ObjectIdGetDatum(object->objectId));
3212  if (!HeapTupleIsValid(tup))
3213  elog(ERROR, "cache lookup failed for user mapping %u",
3214  object->objectId);
3215  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3216  useid = umform->umuser;
3217  srv = GetForeignServer(umform->umserver);
3218 
3219  ReleaseSysCache(tup);
3220 
3221  if (OidIsValid(useid))
3222  usename = GetUserNameFromId(useid, false);
3223  else
3224  usename = "public";
3225 
3226  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3227  srv->servername);
3228  break;
3229  }
3230 
3231  case OCLASS_DEFACL:
3232  {
3233  Relation defaclrel;
3234  ScanKeyData skey[1];
3235  SysScanDesc rcscan;
3236  HeapTuple tup;
3237  Form_pg_default_acl defacl;
3238 
3240 
3241  ScanKeyInit(&skey[0],
3243  BTEqualStrategyNumber, F_OIDEQ,
3244  ObjectIdGetDatum(object->objectId));
3245 
3246  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3247  true, NULL, 1, skey);
3248 
3249  tup = systable_getnext(rcscan);
3250 
3251  if (!HeapTupleIsValid(tup))
3252  elog(ERROR, "could not find tuple for default ACL %u",
3253  object->objectId);
3254 
3255  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3256 
3257  switch (defacl->defaclobjtype)
3258  {
3259  case DEFACLOBJ_RELATION:
3260  appendStringInfo(&buffer,
3261  _("default privileges on new relations belonging to role %s"),
3262  GetUserNameFromId(defacl->defaclrole, false));
3263  break;
3264  case DEFACLOBJ_SEQUENCE:
3265  appendStringInfo(&buffer,
3266  _("default privileges on new sequences belonging to role %s"),
3267  GetUserNameFromId(defacl->defaclrole, false));
3268  break;
3269  case DEFACLOBJ_FUNCTION:
3270  appendStringInfo(&buffer,
3271  _("default privileges on new functions belonging to role %s"),
3272  GetUserNameFromId(defacl->defaclrole, false));
3273  break;
3274  case DEFACLOBJ_TYPE:
3275  appendStringInfo(&buffer,
3276  _("default privileges on new types belonging to role %s"),
3277  GetUserNameFromId(defacl->defaclrole, false));
3278  break;
3279  case DEFACLOBJ_NAMESPACE:
3280  appendStringInfo(&buffer,
3281  _("default privileges on new schemas belonging to role %s"),
3282  GetUserNameFromId(defacl->defaclrole, false));
3283  break;
3284  default:
3285  /* shouldn't get here */
3286  appendStringInfo(&buffer,
3287  _("default privileges belonging to role %s"),
3288  GetUserNameFromId(defacl->defaclrole, false));
3289  break;
3290  }
3291 
3292  if (OidIsValid(defacl->defaclnamespace))
3293  {
3294  appendStringInfo(&buffer,
3295  _(" in schema %s"),
3296  get_namespace_name(defacl->defaclnamespace));
3297  }
3298 
3299  systable_endscan(rcscan);
3300  heap_close(defaclrel, AccessShareLock);
3301  break;
3302  }
3303 
3304  case OCLASS_EXTENSION:
3305  {
3306  char *extname;
3307 
3308  extname = get_extension_name(object->objectId);
3309  if (!extname)
3310  elog(ERROR, "cache lookup failed for extension %u",
3311  object->objectId);
3312  appendStringInfo(&buffer, _("extension %s"), extname);
3313  break;
3314  }
3315 
3316  case OCLASS_EVENT_TRIGGER:
3317  {
3318  HeapTuple tup;
3319 
3321  ObjectIdGetDatum(object->objectId));
3322  if (!HeapTupleIsValid(tup))
3323  elog(ERROR, "cache lookup failed for event trigger %u",
3324  object->objectId);
3325  appendStringInfo(&buffer, _("event trigger %s"),
3326  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3327  ReleaseSysCache(tup);
3328  break;
3329  }
3330 
3331  case OCLASS_POLICY:
3332  {
3333  Relation policy_rel;
3334  ScanKeyData skey[1];
3335  SysScanDesc sscan;
3336  HeapTuple tuple;
3337  Form_pg_policy form_policy;
3338 
3340 
3341  ScanKeyInit(&skey[0],
3343  BTEqualStrategyNumber, F_OIDEQ,
3344  ObjectIdGetDatum(object->objectId));
3345 
3346  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3347  true, NULL, 1, skey);
3348 
3349  tuple = systable_getnext(sscan);
3350 
3351  if (!HeapTupleIsValid(tuple))
3352  elog(ERROR, "could not find tuple for policy %u",
3353  object->objectId);
3354 
3355  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3356 
3357  appendStringInfo(&buffer, _("policy %s on "),
3358  NameStr(form_policy->polname));
3359  getRelationDescription(&buffer, form_policy->polrelid);
3360 
3361  systable_endscan(sscan);
3362  heap_close(policy_rel, AccessShareLock);
3363  break;
3364  }
3365 
3366  case OCLASS_PUBLICATION:
3367  {
3368  appendStringInfo(&buffer, _("publication %s"),
3369  get_publication_name(object->objectId));
3370  break;
3371  }
3372 
3374  {
3375  HeapTuple tup;
3376  char *pubname;
3377  Form_pg_publication_rel prform;
3378 
3380  ObjectIdGetDatum(object->objectId));
3381  if (!HeapTupleIsValid(tup))
3382  elog(ERROR, "cache lookup failed for publication table %u",
3383  object->objectId);
3384 
3385  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3386  pubname = get_publication_name(prform->prpubid);
3387 
3388  appendStringInfo(&buffer, _("publication table %s in publication %s"),
3389  get_rel_name(prform->prrelid), pubname);
3390  ReleaseSysCache(tup);
3391  break;
3392  }
3393 
3394  case OCLASS_SUBSCRIPTION:
3395  {
3396  appendStringInfo(&buffer, _("subscription %s"),
3397  get_subscription_name(object->objectId));
3398  break;
3399  }
3400 
3401  case OCLASS_TRANSFORM:
3402  {
3403  HeapTuple trfTup;
3404  Form_pg_transform trfForm;
3405 
3406  trfTup = SearchSysCache1(TRFOID,
3407  ObjectIdGetDatum(object->objectId));
3408  if (!HeapTupleIsValid(trfTup))
3409  elog(ERROR, "could not find tuple for transform %u",
3410  object->objectId);
3411 
3412  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
3413 
3414  appendStringInfo(&buffer, _("transform for %s language %s"),
3415  format_type_be(trfForm->trftype),
3416  get_language_name(trfForm->trflang, false));
3417 
3418  ReleaseSysCache(trfTup);
3419  break;
3420  }
3421 
3422  /*
3423  * There's intentionally no default: case here; we want the
3424  * compiler to warn if a new OCLASS hasn't been handled above.
3425  */
3426  }
3427 
3428  return buffer.data;
3429 }
#define RewriteOidIndexId
Definition: indexing.h:221
#define TriggerOidIndexId
Definition: indexing.h:251
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1018
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:327
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:180
#define DefaultAclOidIndexId
Definition: indexing.h:307
#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:820
#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:2338
#define OidIsValid(objectId)
Definition: c.h:538
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
#define DefaultAclRelationId
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
char * getObjectDescription(const ObjectAddress *object)
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
Definition: localtime.c:82
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:84
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:950
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:35
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2056
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:3033
#define CastOidIndexId
Definition: indexing.h:107
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:42
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10490
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:1117
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:1284
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1793
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:40
#define PolicyRelationId
Definition: pg_policy.h:19
#define DEFACLOBJ_NAMESPACE
#define RewriteRelationId
Definition: pg_rewrite.h:32
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:323
#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:229
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:692
#define DEFACLOBJ_FUNCTION
#define TriggerRelationId
Definition: pg_trigger.h:34
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
#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:52
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:499
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:1726
#define _(x)
Definition: elog.c:84
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext
char * get_subscription_name(Oid subid)
char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3435 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3436 {
3437  ObjectAddress address;
3438 
3439  address.classId = classid;
3440  address.objectId = objid;
3441  address.objectSubId = 0;
3442 
3443  return getObjectDescription(&address);
3444 }
char * getObjectDescription(const ObjectAddress *object)
char* getObjectIdentityParts ( const ObjectAddress address,
List **  objname,
List **  objargs 
)

Definition at line 4056 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, buffer, CastRelationId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DEFACLOBJ_FUNCTION, DEFACLOBJ_NAMESPACE, 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_STATISTIC_EXT, 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, STATEXTOID, 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().

4058 {
4060 
4061  initStringInfo(&buffer);
4062 
4063  /*
4064  * Make sure that both objname and objargs were passed, or none was; and
4065  * initialize them to empty lists. For objname this is useless because it
4066  * will be initialized in all cases inside the switch; but we do it anyway
4067  * so that we can test below that no branch leaves it unset.
4068  */
4069  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4070  if (objname)
4071  {
4072  *objname = NIL;
4073  *objargs = NIL;
4074  }
4075 
4076  switch (getObjectClass(object))
4077  {
4078  case OCLASS_CLASS:
4079  getRelationIdentity(&buffer, object->objectId, objname);
4080  if (object->objectSubId != 0)
4081  {
4082  char *attr;
4083 
4084  attr = get_relid_attribute_name(object->objectId,
4085  object->objectSubId);
4086  appendStringInfo(&buffer, ".%s", quote_identifier(attr));
4087  if (objname)
4088  *objname = lappend(*objname, attr);
4089  }
4090  break;
4091 
4092  case OCLASS_PROC:
4093  appendStringInfoString(&buffer,
4094  format_procedure_qualified(object->objectId));
4095  if (objname)
4096  format_procedure_parts(object->objectId, objname, objargs);
4097  break;
4098 
4099  case OCLASS_TYPE:
4100  {
4101  char *typeout;
4102 
4103  typeout = format_type_be_qualified(object->objectId);
4104  appendStringInfoString(&buffer, typeout);
4105  if (objname)
4106  *objname = list_make1(typeout);
4107  }
4108  break;
4109 
4110  case OCLASS_CAST:
4111  {
4112  Relation castRel;
4113  HeapTuple tup;
4114  Form_pg_cast castForm;
4115 
4117 
4118  tup = get_catalog_object_by_oid(castRel, object->objectId);
4119 
4120  if (!HeapTupleIsValid(tup))
4121  elog(ERROR, "could not find tuple for cast %u",
4122  object->objectId);
4123 
4124  castForm = (Form_pg_cast) GETSTRUCT(tup);
4125 
4126  appendStringInfo(&buffer, "(%s AS %s)",
4127  format_type_be_qualified(castForm->castsource),
4128  format_type_be_qualified(castForm->casttarget));
4129 
4130  if (objname)
4131  {
4132  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4133  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4134  }
4135 
4136  heap_close(castRel, AccessShareLock);
4137  break;
4138  }
4139 
4140  case OCLASS_COLLATION:
4141  {
4142  HeapTuple collTup;
4143  Form_pg_collation coll;
4144  char *schema;
4145 
4146  collTup = SearchSysCache1(COLLOID,
4147  ObjectIdGetDatum(object->objectId));
4148  if (!HeapTupleIsValid(collTup))
4149  elog(ERROR, "cache lookup failed for collation %u",
4150  object->objectId);
4151  coll = (Form_pg_collation) GETSTRUCT(collTup);
4152  schema = get_namespace_name_or_temp(coll->collnamespace);
4153  appendStringInfoString(&buffer,
4155  NameStr(coll->collname)));
4156  if (objname)
4157  *objname = list_make2(schema,
4158  pstrdup(NameStr(coll->collname)));
4159  ReleaseSysCache(collTup);
4160  break;
4161  }
4162 
4163  case OCLASS_CONSTRAINT:
4164  {
4165  HeapTuple conTup;
4166  Form_pg_constraint con;
4167 
4168  conTup = SearchSysCache1(CONSTROID,
4169  ObjectIdGetDatum(object->objectId));
4170  if (!HeapTupleIsValid(conTup))
4171  elog(ERROR, "cache lookup failed for constraint %u",
4172  object->objectId);
4173  con = (Form_pg_constraint) GETSTRUCT(conTup);
4174 
4175  if (OidIsValid(con->conrelid))
4176  {
4177  appendStringInfo(&buffer, "%s on ",
4178  quote_identifier(NameStr(con->conname)));
4179  getRelationIdentity(&buffer, con->conrelid, objname);
4180  if (objname)
4181  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4182  }
4183  else
4184  {
4185  ObjectAddress domain;
4186 
4187  Assert(OidIsValid(con->contypid));
4188  domain.classId = TypeRelationId;
4189  domain.objectId = con->contypid;
4190  domain.objectSubId = 0;
4191 
4192  appendStringInfo(&buffer, "%s on %s",
4193  quote_identifier(NameStr(con->conname)),
4194  getObjectIdentityParts(&domain, objname, objargs));
4195 
4196  if (objname)
4197  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4198  }
4199 
4200  ReleaseSysCache(conTup);
4201  break;
4202  }
4203 
4204  case OCLASS_CONVERSION:
4205  {
4206  HeapTuple conTup;
4207  Form_pg_conversion conForm;
4208  char *schema;
4209 
4210  conTup = SearchSysCache1(CONVOID,
4211  ObjectIdGetDatum(object->objectId));
4212  if (!HeapTupleIsValid(conTup))
4213  elog(ERROR, "cache lookup failed for conversion %u",
4214  object->objectId);
4215  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4216  schema = get_namespace_name_or_temp(conForm->connamespace);
4217  appendStringInfoString(&buffer,
4219  NameStr(conForm->conname)));
4220  if (objname)
4221  *objname = list_make2(schema,
4222  pstrdup(NameStr(conForm->conname)));
4223  ReleaseSysCache(conTup);
4224  break;
4225  }
4226 
4227  case OCLASS_DEFAULT:
4228  {
4229  Relation attrdefDesc;
4230  ScanKeyData skey[1];
4231  SysScanDesc adscan;
4232 
4233  HeapTuple tup;
4234  Form_pg_attrdef attrdef;
4235  ObjectAddress colobject;
4236 
4238 
4239  ScanKeyInit(&skey[0],
4241  BTEqualStrategyNumber, F_OIDEQ,
4242  ObjectIdGetDatum(object->objectId));
4243 
4244  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4245  true, NULL, 1, skey);
4246 
4247  tup = systable_getnext(adscan);
4248 
4249  if (!HeapTupleIsValid(tup))
4250  elog(ERROR, "could not find tuple for attrdef %u",
4251  object->objectId);
4252 
4253  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4254 
4255  colobject.classId = RelationRelationId;
4256  colobject.objectId = attrdef->adrelid;
4257  colobject.objectSubId = attrdef->adnum;
4258 
4259  appendStringInfo(&buffer, "for %s",
4260  getObjectIdentityParts(&colobject,
4261  objname, objargs));
4262 
4263  systable_endscan(adscan);
4264  heap_close(attrdefDesc, AccessShareLock);
4265  break;
4266  }
4267 
4268  case OCLASS_LANGUAGE:
4269  {
4270  HeapTuple langTup;
4271  Form_pg_language langForm;
4272 
4273  langTup = SearchSysCache1(LANGOID,
4274  ObjectIdGetDatum(object->objectId));
4275  if (!HeapTupleIsValid(langTup))
4276  elog(ERROR, "cache lookup failed for language %u",
4277  object->objectId);
4278  langForm = (Form_pg_language) GETSTRUCT(langTup);
4279  appendStringInfoString(&buffer,
4280  quote_identifier(NameStr(langForm->lanname)));
4281  if (objname)
4282  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4283  ReleaseSysCache(langTup);
4284  break;
4285  }
4286  case OCLASS_LARGEOBJECT:
4287  appendStringInfo(&buffer, "%u",
4288  object->objectId);
4289  if (objname)
4290  *objname = list_make1(psprintf("%u", object->objectId));
4291  break;
4292 
4293  case OCLASS_OPERATOR:
4294  appendStringInfoString(&buffer,
4295  format_operator_qualified(object->objectId));
4296  if (objname)
4297  format_operator_parts(object->objectId, objname, objargs);
4298  break;
4299 
4300  case OCLASS_OPCLASS:
4301  {
4302  HeapTuple opcTup;
4303  Form_pg_opclass opcForm;
4304  HeapTuple amTup;
4305  Form_pg_am amForm;
4306  char *schema;
4307 
4308  opcTup = SearchSysCache1(CLAOID,
4309  ObjectIdGetDatum(object->objectId));
4310  if (!HeapTupleIsValid(opcTup))
4311  elog(ERROR, "cache lookup failed for opclass %u",
4312  object->objectId);
4313  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4314  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4315 
4316  amTup = SearchSysCache1(AMOID,
4317  ObjectIdGetDatum(opcForm->opcmethod));
4318  if (!HeapTupleIsValid(amTup))
4319  elog(ERROR, "cache lookup failed for access method %u",
4320  opcForm->opcmethod);
4321  amForm = (Form_pg_am) GETSTRUCT(amTup);
4322 
4323  appendStringInfo(&buffer, "%s USING %s",
4325  NameStr(opcForm->opcname)),
4326  quote_identifier(NameStr(amForm->amname)));
4327  if (objname)
4328  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
4329  schema,
4330  pstrdup(NameStr(opcForm->opcname)));
4331 
4332  ReleaseSysCache(amTup);
4333  ReleaseSysCache(opcTup);
4334  break;
4335  }
4336 
4337  case OCLASS_OPFAMILY:
4338  getOpFamilyIdentity(&buffer, object->objectId, objname);
4339  break;
4340 
4341  case OCLASS_AM:
4342  {
4343  char *amname;
4344 
4345  amname = get_am_name(object->objectId);
4346  if (!amname)
4347  elog(ERROR, "cache lookup failed for access method %u",
4348  object->objectId);
4349  appendStringInfoString(&buffer, quote_identifier(amname));
4350  if (objname)
4351  *objname = list_make1(amname);
4352  }
4353  break;
4354 
4355  case OCLASS_AMOP:
4356  {
4357  Relation amopDesc;
4358  HeapTuple tup;
4359  ScanKeyData skey[1];
4360  SysScanDesc amscan;
4361  Form_pg_amop amopForm;
4362  StringInfoData opfam;
4363  char *ltype;
4364  char *rtype;
4365 
4367  AccessShareLock);
4368 
4369  ScanKeyInit(&skey[0],
4371  BTEqualStrategyNumber, F_OIDEQ,
4372  ObjectIdGetDatum(object->objectId));
4373 
4374  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
4375  NULL, 1, skey);
4376 
4377  tup = systable_getnext(amscan);
4378 
4379  if (!HeapTupleIsValid(tup))
4380  elog(ERROR, "could not find tuple for amop entry %u",
4381  object->objectId);
4382 
4383  amopForm = (Form_pg_amop) GETSTRUCT(tup);
4384 
4385  initStringInfo(&opfam);
4386  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname);
4387 
4388  ltype = format_type_be_qualified(amopForm->amoplefttype);
4389  rtype = format_type_be_qualified(amopForm->amoprighttype);
4390 
4391  if (objname)
4392  {
4393  *objname = lappend(*objname,
4394  psprintf("%d", amopForm->amopstrategy));
4395  *objargs = list_make2(ltype, rtype);
4396  }
4397 
4398  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
4399  amopForm->amopstrategy,
4400  ltype, rtype, opfam.data);
4401 
4402  pfree(opfam.data);
4403 
4404  systable_endscan(amscan);
4405  heap_close(amopDesc, AccessShareLock);
4406  break;
4407  }
4408 
4409  case OCLASS_AMPROC:
4410  {
4411  Relation amprocDesc;
4412  ScanKeyData skey[1];
4413  SysScanDesc amscan;
4414  HeapTuple tup;
4415  Form_pg_amproc amprocForm;
4416  StringInfoData opfam;
4417  char *ltype;
4418  char *rtype;
4419 
4421  AccessShareLock);
4422 
4423  ScanKeyInit(&skey[0],
4425  BTEqualStrategyNumber, F_OIDEQ,
4426  ObjectIdGetDatum(object->objectId));
4427 
4428  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
4429  NULL, 1, skey);
4430 
4431  tup = systable_getnext(amscan);
4432 
4433  if (!HeapTupleIsValid(tup))
4434  elog(ERROR, "could not find tuple for amproc entry %u",
4435  object->objectId);
4436 
4437  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
4438 
4439  initStringInfo(&opfam);
4440  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname);
4441 
4442  ltype = format_type_be_qualified(amprocForm->amproclefttype);
4443  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
4444 
4445  if (objname)
4446  {
4447  *objname = lappend(*objname,
4448  psprintf("%d", amprocForm->amprocnum));
4449  *objargs = list_make2(ltype, rtype);
4450  }
4451 
4452  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
4453  amprocForm->amprocnum,
4454  ltype, rtype, opfam.data);
4455 
4456  pfree(opfam.data);
4457 
4458  systable_endscan(amscan);
4459  heap_close(amprocDesc, AccessShareLock);
4460  break;
4461  }
4462 
4463  case OCLASS_REWRITE:
4464  {
4465  Relation ruleDesc;
4466  HeapTuple tup;
4468 
4470 
4471  tup = get_catalog_object_by_oid(ruleDesc, object->objectId);
4472 
4473  if (!HeapTupleIsValid(tup))
4474  elog(ERROR, "could not find tuple for rule %u",
4475  object->objectId);
4476 
4477  rule = (Form_pg_rewrite) GETSTRUCT(tup);
4478 
4479  appendStringInfo(&buffer, "%s on ",
4480  quote_identifier(NameStr(rule->rulename)));
4481  getRelationIdentity(&buffer, rule->ev_class, objname);
4482  if (objname)
4483  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
4484 
4485  heap_close(ruleDesc, AccessShareLock);
4486  break;
4487  }
4488 
4489  case OCLASS_TRIGGER:
4490  {
4491  Relation trigDesc;
4492  HeapTuple tup;
4493  Form_pg_trigger trig;
4494 
4496 
4497  tup = get_catalog_object_by_oid(trigDesc, object->objectId);
4498 
4499  if (!HeapTupleIsValid(tup))
4500  elog(ERROR, "could not find tuple for trigger %u",
4501  object->objectId);
4502 
4503  trig = (Form_pg_trigger) GETSTRUCT(tup);
4504 
4505  appendStringInfo(&buffer, "%s on ",
4506  quote_identifier(NameStr(trig->tgname)));
4507  getRelationIdentity(&buffer, trig->tgrelid, objname);
4508  if (objname)
4509  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
4510 
4511  heap_close(trigDesc, AccessShareLock);
4512  break;
4513  }
4514 
4515  case OCLASS_SCHEMA:
4516  {
4517  char *nspname;
4518 
4519  nspname = get_namespace_name_or_temp(object->objectId);
4520  if (!nspname)
4521  elog(ERROR, "cache lookup failed for namespace %u",
4522  object->objectId);
4523  appendStringInfoString(&buffer,
4524  quote_identifier(nspname));
4525  if (objname)
4526  *objname = list_make1(nspname);
4527  break;
4528  }
4529 
4530  case OCLASS_STATISTIC_EXT:
4531  {
4532  HeapTuple tup;
4533  Form_pg_statistic_ext formStatistic;
4534  char *schema;
4535 
4537  ObjectIdGetDatum(object->objectId));
4538  if (!HeapTupleIsValid(tup))
4539  elog(ERROR, "cache lookup failed for statistics object %u",
4540  object->objectId);
4541  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
4542  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
4543  appendStringInfoString(&buffer,
4545  NameStr(formStatistic->stxname)));
4546  if (objname)
4547  *objname = list_make2(schema,
4548  pstrdup(NameStr(formStatistic->stxname)));
4549  ReleaseSysCache(tup);
4550  }
4551  break;
4552 
4553  case OCLASS_TSPARSER:
4554  {
4555  HeapTuple tup;
4556  Form_pg_ts_parser formParser;
4557  char *schema;
4558 
4560  ObjectIdGetDatum(object->objectId));
4561  if (!HeapTupleIsValid(tup))
4562  elog(ERROR, "cache lookup failed for text search parser %u",
4563  object->objectId);
4564  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4565  schema = get_namespace_name_or_temp(formParser->prsnamespace);
4566  appendStringInfoString(&buffer,
4568  NameStr(formParser->prsname)));
4569  if (objname)
4570  *objname = list_make2(schema,
4571  pstrdup(NameStr(formParser->prsname)));
4572  ReleaseSysCache(tup);
4573  break;
4574  }
4575 
4576  case OCLASS_TSDICT:
4577  {
4578  HeapTuple tup;
4579  Form_pg_ts_dict formDict;
4580  char *schema;
4581 
4582  tup = SearchSysCache1(TSDICTOID,
4583  ObjectIdGetDatum(object->objectId));
4584  if (!HeapTupleIsValid(tup))
4585  elog(ERROR, "cache lookup failed for text search dictionary %u",
4586  object->objectId);
4587  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4588  schema = get_namespace_name_or_temp(formDict->dictnamespace);
4589  appendStringInfoString(&buffer,
4591  NameStr(formDict->dictname)));
4592  if (objname)
4593  *objname = list_make2(schema,
4594  pstrdup(NameStr(formDict->dictname)));
4595  ReleaseSysCache(tup);
4596  break;
4597  }
4598 
4599  case OCLASS_TSTEMPLATE:
4600  {
4601  HeapTuple tup;
4602  Form_pg_ts_template formTmpl;
4603  char *schema;
4604 
4606  ObjectIdGetDatum(object->objectId));
4607  if (!HeapTupleIsValid(tup))
4608  elog(ERROR, "cache lookup failed for text search template %u",
4609  object->objectId);
4610  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4611  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4612  appendStringInfoString(&buffer,
4614  NameStr(formTmpl->tmplname)));
4615  if (objname)
4616  *objname = list_make2(schema,
4617  pstrdup(NameStr(formTmpl->tmplname)));
4618  ReleaseSysCache(tup);
4619  break;
4620  }
4621 
4622  case OCLASS_TSCONFIG:
4623  {
4624  HeapTuple tup;
4625  Form_pg_ts_config formCfg;
4626  char *schema;
4627 
4629  ObjectIdGetDatum(object->objectId));
4630  if (!HeapTupleIsValid(tup))
4631  elog(ERROR, "cache lookup failed for text search configuration %u",
4632  object->objectId);
4633  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4634  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4635  appendStringInfoString(&buffer,
4637  NameStr(formCfg->cfgname)));
4638  if (objname)
4639  *objname = list_make2(schema,
4640  pstrdup(NameStr(formCfg->cfgname)));
4641  ReleaseSysCache(tup);
4642  break;
4643  }
4644 
4645  case OCLASS_ROLE:
4646  {
4647  char *username;
4648 
4649  username = GetUserNameFromId(object->objectId, false);
4650  if (objname)
4651  *objname = list_make1(username);
4652  appendStringInfoString(&buffer,
4653  quote_identifier(username));
4654  break;
4655  }
4656 
4657  case OCLASS_DATABASE:
4658  {
4659  char *datname;
4660 
4661  datname = get_database_name(object->objectId);
4662  if (!datname)
4663  elog(ERROR, "cache lookup failed for database %u",
4664  object->objectId);
4665  if (objname)
4666  *objname = list_make1(datname);
4667  appendStringInfoString(&buffer,
4668  quote_identifier(datname));
4669  break;
4670  }
4671 
4672  case OCLASS_TBLSPACE:
4673  {
4674  char *tblspace;
4675 
4676  tblspace = get_tablespace_name(object->objectId);
4677  if (!tblspace)
4678  elog(ERROR, "cache lookup failed for tablespace %u",
4679  object->objectId);
4680  if (objname)
4681  *objname = list_make1(tblspace);
4682  appendStringInfoString(&buffer,
4683  quote_identifier(tblspace));
4684  break;
4685  }
4686 
4687  case OCLASS_FDW:
4688  {
4689  ForeignDataWrapper *fdw;
4690 
4691  fdw = GetForeignDataWrapper(object->objectId);
4693  if (objname)
4694  *objname = list_make1(pstrdup(fdw->fdwname));
4695  break;
4696  }
4697 
4698  case OCLASS_FOREIGN_SERVER:
4699  {
4700  ForeignServer *srv;
4701 
4702  srv = GetForeignServer(object->objectId);
4703  appendStringInfoString(&buffer,
4705  if (objname)
4706  *objname = list_make1(pstrdup(srv->servername));
4707  break;
4708  }
4709 
4710  case OCLASS_USER_MAPPING:
4711  {
4712  HeapTuple tup;
4713  Oid useid;
4714  Form_pg_user_mapping umform;
4715  ForeignServer *srv;
4716  const char *usename;
4717 
4719  ObjectIdGetDatum(object->objectId));
4720  if (!HeapTupleIsValid(tup))
4721  elog(ERROR, "cache lookup failed for user mapping %u",
4722  object->objectId);
4723  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
4724  useid = umform->umuser;
4725  srv = GetForeignServer(umform->umserver);
4726 
4727  ReleaseSysCache(tup);
4728 
4729  if (OidIsValid(useid))
4730  usename = GetUserNameFromId(useid, false);
4731  else
4732  usename = "public";
4733 
4734  if (objname)
4735  {
4736  *objname = list_make1(pstrdup(usename));
4737  *objargs = list_make1(pstrdup(srv->servername));
4738  }
4739 
4740  appendStringInfo(&buffer, "%s on server %s",
4741  quote_identifier(usename),
4742  srv->servername);
4743  break;
4744  }
4745 
4746  case OCLASS_DEFACL:
4747  {
4748  Relation defaclrel;
4749  ScanKeyData skey[1];
4750  SysScanDesc rcscan;
4751  HeapTuple tup;
4752  Form_pg_default_acl defacl;
4753  char *schema;
4754  char *username;
4755 
4757 
4758  ScanKeyInit(&skey[0],
4760  BTEqualStrategyNumber, F_OIDEQ,
4761  ObjectIdGetDatum(object->objectId));
4762 
4763  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
4764  true, NULL, 1, skey);
4765 
4766  tup = systable_getnext(rcscan);
4767 
4768  if (!HeapTupleIsValid(tup))
4769  elog(ERROR, "could not find tuple for default ACL %u",
4770  object->objectId);
4771 
4772  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
4773 
4774  username = GetUserNameFromId(defacl->defaclrole, false);
4775  appendStringInfo(&buffer,
4776  "for role %s",
4777  quote_identifier(username));
4778 
4779  if (OidIsValid(defacl->defaclnamespace))
4780  {
4781  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
4782  appendStringInfo(&buffer,
4783  " in schema %s",
4784  quote_identifier(schema));
4785  }
4786  else
4787  schema = NULL;
4788 
4789  switch (defacl->defaclobjtype)
4790  {
4791  case DEFACLOBJ_RELATION:
4792  appendStringInfoString(&buffer,
4793  " on tables");
4794  break;
4795  case DEFACLOBJ_SEQUENCE:
4796  appendStringInfoString(&buffer,
4797  " on sequences");
4798  break;
4799  case DEFACLOBJ_FUNCTION:
4800  appendStringInfoString(&buffer,
4801  " on functions");
4802  break;
4803  case DEFACLOBJ_TYPE:
4804  appendStringInfoString(&buffer,
4805  " on types");
4806  break;
4807  case DEFACLOBJ_NAMESPACE:
4808  appendStringInfoString(&buffer,
4809  " on schemas");
4810  break;
4811  }
4812 
4813  if (objname)
4814  {
4815  *objname = list_make1(username);
4816  if (schema)
4817  *objname = lappend(*objname, schema);
4818  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
4819  }
4820 
4821  systable_endscan(rcscan);
4822  heap_close(defaclrel, AccessShareLock);
4823  break;
4824  }
4825 
4826  case OCLASS_EXTENSION:
4827  {
4828  char *extname;
4829 
4830  extname = get_extension_name(object->objectId);
4831  if (!extname)
4832  elog(ERROR, "cache lookup failed for extension %u",
4833  object->objectId);
4834  appendStringInfoString(&buffer, quote_identifier(extname));
4835  if (objname)
4836  *objname = list_make1(extname);
4837  break;
4838  }
4839 
4840  case OCLASS_EVENT_TRIGGER:
4841  {
4842  HeapTuple tup;
4843  Form_pg_event_trigger trigForm;
4844 
4845  /* no objname support here */
4846  if (objname)
4847  *objname = NIL;
4848 
4850  ObjectIdGetDatum(object->objectId));
4851  if (!HeapTupleIsValid(tup))
4852  elog(ERROR, "cache lookup failed for event trigger %u",
4853  object->objectId);
4854  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
4855  appendStringInfoString(&buffer,
4856  quote_identifier(NameStr(trigForm->evtname)));
4857  ReleaseSysCache(tup);
4858  break;
4859  }
4860 
4861  case OCLASS_POLICY:
4862  {
4863  Relation polDesc;
4864  HeapTuple tup;
4865  Form_pg_policy policy;
4866 
4868 
4869  tup = get_catalog_object_by_oid(polDesc, object->objectId);
4870 
4871  if (!HeapTupleIsValid(tup))
4872  elog(ERROR, "could not find tuple for policy %u",
4873  object->objectId);
4874 
4875  policy = (Form_pg_policy) GETSTRUCT(tup);
4876 
4877  appendStringInfo(&buffer, "%s on ",
4878  quote_identifier(NameStr(policy->polname)));
4879  getRelationIdentity(&buffer, policy->polrelid, objname);
4880  if (objname)
4881  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
4882 
4883  heap_close(polDesc, AccessShareLock);
4884  break;
4885  }
4886 
4887  case OCLASS_PUBLICATION:
4888  {
4889  char *pubname;
4890 
4891  pubname = get_publication_name(object->objectId);
4892  appendStringInfoString(&buffer,
4893  quote_identifier(pubname));
4894  if (objname)
4895  *objname = list_make1(pubname);
4896  break;
4897  }
4898 
4900  {
4901  HeapTuple tup;
4902  char *pubname;
4903  Form_pg_publication_rel prform;
4904 
4906  ObjectIdGetDatum(object->objectId));
4907  if (!HeapTupleIsValid(tup))
4908  elog(ERROR, "cache lookup failed for publication table %u",
4909  object->objectId);
4910 
4911  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
4912  pubname = get_publication_name(prform->prpubid);
4913 
4914  appendStringInfo(&buffer, _("%s in publication %s"),
4915  get_rel_name(prform->prrelid), pubname);
4916 
4917  if (objname)
4918  {
4919  getRelationIdentity(&buffer, prform->prrelid, objname);
4920  *objargs = list_make1(pubname);
4921  }
4922 
4923  ReleaseSysCache(tup);
4924  break;
4925  }
4926 
4927  case OCLASS_SUBSCRIPTION:
4928  {
4929  char *subname;
4930 
4931  subname = get_subscription_name(object->objectId);
4932  appendStringInfoString(&buffer,
4933  quote_identifier(subname));
4934  if (objname)
4935  *objname = list_make1(subname);
4936  break;
4937  }
4938 
4939  case OCLASS_TRANSFORM:
4940  {
4941  Relation transformDesc;
4942  HeapTuple tup;
4943  Form_pg_transform transform;
4944  char *transformLang;
4945  char *transformType;
4946 
4947  transformDesc = heap_open(TransformRelationId, AccessShareLock);
4948 
4949  tup = get_catalog_object_by_oid(transformDesc, object->objectId);
4950 
4951  if (!HeapTupleIsValid(tup))
4952  elog(ERROR, "could not find tuple for transform %u",
4953  object->objectId);
4954 
4955  transform = (Form_pg_transform) GETSTRUCT(tup);
4956 
4957  transformType = format_type_be_qualified(transform->trftype);
4958  transformLang = get_language_name(transform->trflang, false);
4959 
4960  appendStringInfo(&buffer, "for %s on language %s",
4961  transformType,
4962  transformLang);
4963  if (objname)
4964  {
4965  *objname = list_make1(transformType);
4966  *objargs = list_make1(pstrdup(transformLang));
4967  }
4968 
4969  heap_close(transformDesc, AccessShareLock);
4970  }
4971  break;
4972 
4973  /*
4974  * There's intentionally no default: case here; we want the
4975  * compiler to warn if a new OCLASS hasn't been handled above.
4976  */
4977  }
4978 
4979  /*
4980  * If a get_object_address representation was requested, make sure we are
4981  * providing one. We don't check objargs, because many of the cases above
4982  * leave it as NIL.
4983  */
4984  if (objname && *objname == NIL)
4985  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
4986  (int) getObjectClass(object), buffer.data);
4987 
4988  return buffer.data;
4989 }
#define list_make2(x1, x2)
Definition: pg_list.h:140
#define list_make3(x1, x2, x3)
Definition: pg_list.h:141
#define NIL
Definition: pg_list.h:69
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
Definition: syscache.h:36
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10404
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1018
#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:1077
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:180
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs)
#define DefaultAclOidIndexId
Definition: indexing.h:307
#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:2338
#define OidIsValid(objectId)
Definition: c.h:538
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
#define DefaultAclRelationId
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
Definition: localtime.c:82
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:84
#define list_make1(x1)
Definition: pg_list.h:139
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:950
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs)
Definition: regproc.c:832
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:78
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:35
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
char * format_operator_qualified(Oid operator_oid)
Definition: regproc.c:826
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2056
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:157
#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:408
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:42
char * format_procedure_qualified(Oid procedure_oid)
Definition: regproc.c:329
List * lappend(List *list, void *datum)
Definition: list.c:128
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10490
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:1117
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:1284
static char * username
Definition: initdb.c:131
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:40
#define PolicyRelationId
Definition: pg_policy.h:19
#define DEFACLOBJ_NAMESPACE
#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:229
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:692
#define Assert(condition)
Definition: c.h:675
#define DEFACLOBJ_FUNCTION
#define TriggerRelationId
Definition: pg_trigger.h:34
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
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:52
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:3057
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:499
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:1726
#define PointerIsValid(pointer)
Definition: c.h:526
#define _(x)
Definition: elog.c:84
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext
char * get_subscription_name(Oid subid)
char* getObjectTypeDescription ( const ObjectAddress object)

Definition at line 3761 of file objectaddress.c.

References appendStringInfoString(), buffer, 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_STATISTIC_EXT, 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().

3762 {
3764 
3765  initStringInfo(&buffer);
3766 
3767  switch (getObjectClass(object))
3768  {
3769  case OCLASS_CLASS:
3770  getRelationTypeDescription(&buffer, object->objectId,
3771  object->objectSubId);
3772  break;
3773 
3774  case OCLASS_PROC:
3775  getProcedureTypeDescription(&buffer, object->objectId);
3776  break;
3777 
3778  case OCLASS_TYPE:
3779  appendStringInfoString(&buffer, "type");
3780  break;
3781 
3782  case OCLASS_CAST:
3783  appendStringInfoString(&buffer, "cast");
3784  break;
3785 
3786  case OCLASS_COLLATION:
3787  appendStringInfoString(&buffer, "collation");
3788  break;
3789 
3790  case OCLASS_CONSTRAINT:
3791  getConstraintTypeDescription(&buffer, object->objectId);
3792  break;
3793 
3794  case OCLASS_CONVERSION:
3795  appendStringInfoString(&buffer, "conversion");
3796  break;
3797 
3798  case OCLASS_DEFAULT:
3799  appendStringInfoString(&buffer, "default value");
3800  break;
3801 
3802  case OCLASS_LANGUAGE:
3803  appendStringInfoString(&buffer, "language");
3804  break;
3805 
3806  case OCLASS_LARGEOBJECT:
3807  appendStringInfoString(&buffer, "large object");
3808  break;
3809 
3810  case OCLASS_OPERATOR:
3811  appendStringInfoString(&buffer, "operator");
3812  break;
3813 
3814  case OCLASS_OPCLASS:
3815  appendStringInfoString(&buffer, "operator class");
3816  break;
3817 
3818  case OCLASS_OPFAMILY:
3819  appendStringInfoString(&buffer, "operator family");
3820  break;
3821 
3822  case OCLASS_AM:
3823  appendStringInfoString(&buffer, "access method");
3824  break;
3825 
3826  case OCLASS_AMOP:
3827  appendStringInfoString(&buffer, "operator of access method");
3828  break;
3829 
3830  case OCLASS_AMPROC:
3831  appendStringInfoString(&buffer, "function of access method");
3832  break;
3833 
3834  case OCLASS_REWRITE:
3835  appendStringInfoString(&buffer, "rule");
3836  break;
3837 
3838  case OCLASS_TRIGGER:
3839  appendStringInfoString(&buffer, "trigger");
3840  break;
3841 
3842  case OCLASS_SCHEMA:
3843  appendStringInfoString(&buffer, "schema");
3844  break;
3845 
3846  case OCLASS_STATISTIC_EXT:
3847  appendStringInfoString(&buffer, "statistics object");
3848  break;
3849 
3850  case OCLASS_TSPARSER:
3851  appendStringInfoString(&buffer, "text search parser");
3852  break;
3853 
3854  case OCLASS_TSDICT:
3855  appendStringInfoString(&buffer, "text search dictionary");
3856  break;
3857 
3858  case OCLASS_TSTEMPLATE:
3859  appendStringInfoString(&buffer, "text search template");
3860  break;
3861 
3862  case OCLASS_TSCONFIG:
3863  appendStringInfoString(&buffer, "text search configuration");
3864  break;
3865 
3866  case OCLASS_ROLE:
3867  appendStringInfoString(&buffer, "role");
3868  break;
3869 
3870  case OCLASS_DATABASE:
3871  appendStringInfoString(&buffer, "database");
3872  break;
3873 
3874  case OCLASS_TBLSPACE:
3875  appendStringInfoString(&buffer, "tablespace");
3876  break;
3877 
3878  case OCLASS_FDW:
3879  appendStringInfoString(&buffer, "foreign-data wrapper");
3880  break;
3881 
3882  case OCLASS_FOREIGN_SERVER:
3883  appendStringInfoString(&buffer, "server");
3884  break;
3885 
3886  case OCLASS_USER_MAPPING:
3887  appendStringInfoString(&buffer, "user mapping");
3888  break;
3889 
3890  case OCLASS_DEFACL:
3891  appendStringInfoString(&buffer, "default acl");
3892  break;
3893 
3894  case OCLASS_EXTENSION:
3895  appendStringInfoString(&buffer, "extension");
3896  break;
3897 
3898  case OCLASS_EVENT_TRIGGER:
3899  appendStringInfoString(&buffer, "event trigger");
3900  break;
3901 
3902  case OCLASS_POLICY:
3903  appendStringInfoString(&buffer, "policy");
3904  break;
3905 
3906  case OCLASS_PUBLICATION:
3907  appendStringInfoString(&buffer, "publication");
3908  break;
3909 
3911  appendStringInfoString(&buffer, "publication relation");
3912  break;
3913 
3914  case OCLASS_SUBSCRIPTION:
3915  appendStringInfoString(&buffer, "subscription");
3916  break;
3917 
3918  case OCLASS_TRANSFORM:
3919  appendStringInfoString(&buffer, "transform");
3920  break;
3921 
3922  /*
3923  * There's intentionally no default: case here; we want the
3924  * compiler to warn if a new OCLASS hasn't been handled above.
3925  */
3926  }
3927 
3928  return buffer.data;
3929 }
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid)
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId)
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2338
static void getProcedureTypeDescription(StringInfo buffer, Oid procid)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:214
bool is_objectclass_supported ( Oid  class_id)

Definition at line 2556 of file objectaddress.c.

References lengthof.

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

2557 {
2558  int index;
2559 
2560  for (index = 0; index < lengthof(ObjectProperty); index++)
2561  {
2562  if (ObjectProperty[index].class_oid == class_id)
2563  return true;
2564  }
2565 
2566  return false;
2567 }
#define lengthof(array)
Definition: c.h:562
Definition: type.h:89
static const ObjectPropertyType ObjectProperty[]
int read_objtype_from_string ( const char *  objtype)

Definition at line 2460 of file objectaddress.c.

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

Referenced by pg_get_object_address().

2461 {
2462  int i;
2463 
2464  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2465  {
2466  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2467  return ObjectTypeMap[i].tm_type;
2468  }
2469  ereport(ERROR,
2470  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2471  errmsg("unrecognized object type \"%s\"", objtype)));
2472 
2473  return -1; /* keep compiler quiet */
2474 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:562
#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 5057 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().

5058 {
5059  ArrayType *arr;
5060  Datum *datums;
5061  int j = 0;
5062  ListCell *cell;
5063  MemoryContext memcxt;
5064  MemoryContext oldcxt;
5065 
5067  "strlist to array",
5069  oldcxt = MemoryContextSwitchTo(memcxt);
5070 
5071  datums = palloc(sizeof(text *) * list_length(list));
5072  foreach(cell, list)
5073  {
5074  char *name = lfirst(cell);
5075 
5076  datums[j++] = CStringGetTextDatum(name);
5077  }
5078 
5079  MemoryContextSwitchTo(oldcxt);
5080 
5081  arr = construct_array(datums, list_length(list),
5082  TEXTOID, -1, false, 'i');
5083  MemoryContextDelete(memcxt);
5084 
5085  return arr;
5086 }
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:165
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
uintptr_t Datum
Definition: postgres.h:372
#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:849
#define CStringGetTextDatum(s)
Definition: builtins.h:91
Definition: c.h:439

Variable Documentation