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(), 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 2218 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().

2220 {
2221  switch (objtype)
2222  {
2223  case OBJECT_INDEX:
2224  case OBJECT_SEQUENCE:
2225  case OBJECT_TABLE:
2226  case OBJECT_VIEW:
2227  case OBJECT_MATVIEW:
2228  case OBJECT_FOREIGN_TABLE:
2229  case OBJECT_COLUMN:
2230  case OBJECT_RULE:
2231  case OBJECT_TRIGGER:
2232  case OBJECT_POLICY:
2233  case OBJECT_TABCONSTRAINT:
2234  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2236  RelationGetRelationName(relation));
2237  break;
2238  case OBJECT_DATABASE:
2239  if (!pg_database_ownercheck(address.objectId, roleid))
2241  strVal((Value *) object));
2242  break;
2243  case OBJECT_TYPE:
2244  case OBJECT_DOMAIN:
2245  case OBJECT_ATTRIBUTE:
2246  case OBJECT_DOMCONSTRAINT:
2247  if (!pg_type_ownercheck(address.objectId, roleid))
2249  break;
2250  case OBJECT_AGGREGATE:
2251  case OBJECT_FUNCTION:
2252  if (!pg_proc_ownercheck(address.objectId, roleid))
2254  NameListToString((castNode(ObjectWithArgs, object))->objname));
2255  break;
2256  case OBJECT_OPERATOR:
2257  if (!pg_oper_ownercheck(address.objectId, roleid))
2259  NameListToString((castNode(ObjectWithArgs, object))->objname));
2260  break;
2261  case OBJECT_SCHEMA:
2262  if (!pg_namespace_ownercheck(address.objectId, roleid))
2264  strVal((Value *) object));
2265  break;
2266  case OBJECT_COLLATION:
2267  if (!pg_collation_ownercheck(address.objectId, roleid))
2269  NameListToString(castNode(List, object)));
2270  break;
2271  case OBJECT_CONVERSION:
2272  if (!pg_conversion_ownercheck(address.objectId, roleid))
2274  NameListToString(castNode(List, object)));
2275  break;
2276  case OBJECT_EXTENSION:
2277  if (!pg_extension_ownercheck(address.objectId, roleid))
2279  strVal((Value *) object));
2280  break;
2281  case OBJECT_FDW:
2282  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2284  strVal((Value *) object));
2285  break;
2286  case OBJECT_FOREIGN_SERVER:
2287  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2289  strVal((Value *) object));
2290  break;
2291  case OBJECT_EVENT_TRIGGER:
2292  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2294  strVal((Value *) object));
2295  break;
2296  case OBJECT_LANGUAGE:
2297  if (!pg_language_ownercheck(address.objectId, roleid))
2299  strVal((Value *) object));
2300  break;
2301  case OBJECT_OPCLASS:
2302  if (!pg_opclass_ownercheck(address.objectId, roleid))
2304  NameListToString(castNode(List, object)));
2305  break;
2306  case OBJECT_OPFAMILY:
2307  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2309  NameListToString(castNode(List, object)));
2310  break;
2311  case OBJECT_LARGEOBJECT:
2312  if (!lo_compat_privileges &&
2313  !pg_largeobject_ownercheck(address.objectId, roleid))
2314  ereport(ERROR,
2315  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2316  errmsg("must be owner of large object %u",
2317  address.objectId)));
2318  break;
2319  case OBJECT_CAST:
2320  {
2321  /* We can only check permissions on the source/target types */
2322  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2323  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2324  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2325  Oid targettypeid = typenameTypeId(NULL, targettype);
2326 
2327  if (!pg_type_ownercheck(sourcetypeid, roleid)
2328  && !pg_type_ownercheck(targettypeid, roleid))
2329  ereport(ERROR,
2330  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2331  errmsg("must be owner of type %s or type %s",
2332  format_type_be(sourcetypeid),
2333  format_type_be(targettypeid))));
2334  }
2335  break;
2336  case OBJECT_PUBLICATION:
2337  if (!pg_publication_ownercheck(address.objectId, roleid))
2339  strVal((Value *) object));
2340  break;
2341  case OBJECT_SUBSCRIPTION:
2342  if (!pg_subscription_ownercheck(address.objectId, roleid))
2344  strVal((Value *) object));
2345  break;
2346  case OBJECT_TRANSFORM:
2347  {
2348  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2349  Oid typeid = typenameTypeId(NULL, typename);
2350 
2351  if (!pg_type_ownercheck(typeid, roleid))
2353  }
2354  break;
2355  case OBJECT_TABLESPACE:
2356  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2358  strVal((Value *) object));
2359  break;
2360  case OBJECT_TSDICTIONARY:
2361  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2363  NameListToString(castNode(List, object)));
2364  break;
2366  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2368  NameListToString(castNode(List, object)));
2369  break;
2370  case OBJECT_ROLE:
2371 
2372  /*
2373  * We treat roles as being "owned" by those with CREATEROLE priv,
2374  * except that superusers are only owned by superusers.
2375  */
2376  if (superuser_arg(address.objectId))
2377  {
2378  if (!superuser_arg(roleid))
2379  ereport(ERROR,
2380  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2381  errmsg("must be superuser")));
2382  }
2383  else
2384  {
2385  if (!has_createrole_privilege(roleid))
2386  ereport(ERROR,
2387  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2388  errmsg("must have CREATEROLE privilege")));
2389  }
2390  break;
2391  case OBJECT_TSPARSER:
2392  case OBJECT_TSTEMPLATE:
2393  case OBJECT_ACCESS_METHOD:
2394  /* We treat these object types as being owned by superusers */
2395  if (!superuser_arg(roleid))
2396  ereport(ERROR,
2397  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2398  errmsg("must be superuser")));
2399  break;
2400  case OBJECT_STATISTIC_EXT:
2401  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2403  break;
2404  default:
2405  elog(ERROR, "unrecognized object type: %d",
2406  (int) objtype);
2407  }
2408 }
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:437
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:3020
#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:417
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 2604 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().

2605 {
2606  HeapTuple tuple;
2607  Oid classId = RelationGetRelid(catalog);
2608  int oidCacheId = get_object_catcache_oid(classId);
2609 
2610  if (oidCacheId > 0)
2611  {
2612  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2613  if (!HeapTupleIsValid(tuple)) /* should not happen */
2614  return NULL;
2615  }
2616  else
2617  {
2618  Oid oidIndexId = get_object_oid_index(classId);
2619  SysScanDesc scan;
2620  ScanKeyData skey;
2621 
2622  Assert(OidIsValid(oidIndexId));
2623 
2624  ScanKeyInit(&skey,
2626  BTEqualStrategyNumber, F_OIDEQ,
2627  ObjectIdGetDatum(objectId));
2628 
2629  scan = systable_beginscan(catalog, oidIndexId, true,
2630  NULL, 1, &skey);
2631  tuple = systable_getnext(scan);
2632  if (!HeapTupleIsValid(tuple))
2633  {
2634  systable_endscan(scan);
2635  return NULL;
2636  }
2637  tuple = heap_copytuple(tuple);
2638 
2639  systable_endscan(scan);
2640  }
2641 
2642  return tuple;
2643 }
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:417
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclObjectKind get_object_aclkind ( Oid  class_id)

Definition at line 2532 of file objectaddress.c.

References ObjectPropertyType::acl_kind, and get_object_property_data().

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

2533 {
2534  const ObjectPropertyType *prop = get_object_property_data(class_id);
2535 
2536  return prop->acl_kind;
2537 }
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 796 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().

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

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

Referenced by ExecAlterObjectDependsStmt().

1096 {
1097  if (rel)
1098  {
1099  object = lcons(makeString(rel->relname), object);
1100  if (rel->schemaname)
1101  object = lcons(makeString(rel->schemaname), object);
1102  if (rel->catalogname)
1103  object = lcons(makeString(rel->catalogname), object);
1104  }
1105 
1106  return get_object_address(objtype, (Node *) object,
1107  relp, lockmode, missing_ok);
1108 }
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 2524 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2525 {
2526  const ObjectPropertyType *prop = get_object_property_data(class_id);
2527 
2528  return prop->attnum_acl;
2529 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl
AttrNumber get_object_attnum_name ( Oid  class_id)

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

2501 {
2502  const ObjectPropertyType *prop = get_object_property_data(class_id);
2503 
2504  return prop->attnum_name;
2505 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber get_object_attnum_namespace ( Oid  class_id)

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

2509 {
2510  const ObjectPropertyType *prop = get_object_property_data(class_id);
2511 
2512  return prop->attnum_namespace;
2513 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace
AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2516 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2517 {
2518  const ObjectPropertyType *prop = get_object_property_data(class_id);
2519 
2520  return prop->attnum_owner;
2521 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_name ( Oid  class_id)

Definition at line 2492 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2493 {
2494  const ObjectPropertyType *prop = get_object_property_data(class_id);
2495 
2496  return prop->name_catcache_id;
2497 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_oid ( Oid  class_id)

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

2485 {
2486  const ObjectPropertyType *prop = get_object_property_data(class_id);
2487 
2488  return prop->oid_catcache_id;
2489 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2540 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2541 {
2542  const ObjectPropertyType *prop = get_object_property_data(class_id);
2543 
2544  return prop->is_nsp_name_unique;
2545 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
Oid get_object_namespace ( const ObjectAddress address)

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

2418 {
2419  int cache;
2420  HeapTuple tuple;
2421  bool isnull;
2422  Oid oid;
2423  const ObjectPropertyType *property;
2424 
2425  /* If not owned by a namespace, just return InvalidOid. */
2426  property = get_object_property_data(address->classId);
2427  if (property->attnum_namespace == InvalidAttrNumber)
2428  return InvalidOid;
2429 
2430  /* Currently, we can only handle object types with system caches. */
2431  cache = property->oid_catcache_id;
2432  Assert(cache != -1);
2433 
2434  /* Fetch tuple from syscache and extract namespace attribute. */
2435  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2436  if (!HeapTupleIsValid(tuple))
2437  elog(ERROR, "cache lookup failed for cache %d oid %u",
2438  cache, address->objectId);
2439  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2440  tuple,
2441  property->attnum_namespace,
2442  &isnull));
2443  Assert(!isnull);
2444  ReleaseSysCache(tuple);
2445 
2446  return oid;
2447 }
#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 2476 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2477 {
2478  const ObjectPropertyType *prop = get_object_property_data(class_id);
2479 
2480  return prop->oid_index_oid;
2481 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
char* getObjectDescription ( const ObjectAddress object)

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

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

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

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

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

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

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

Definition at line 2552 of file objectaddress.c.

References lengthof.

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

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

Definition at line 2456 of file objectaddress.c.

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

Referenced by pg_get_object_address().

2457 {
2458  int i;
2459 
2460  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2461  {
2462  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2463  return ObjectTypeMap[i].tm_type;
2464  }
2465  ereport(ERROR,
2466  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2467  errmsg("unrecognized object type \"%s\"", objtype)));
2468 
2469  return -1; /* keep compiler quiet */
2470 }
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 5053 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().

5054 {
5055  ArrayType *arr;
5056  Datum *datums;
5057  int j = 0;
5058  ListCell *cell;
5059  MemoryContext memcxt;
5060  MemoryContext oldcxt;
5061 
5063  "strlist to array",
5065  oldcxt = MemoryContextSwitchTo(memcxt);
5066 
5067  datums = palloc(sizeof(text *) * list_length(list));
5068  foreach(cell, list)
5069  {
5070  char *name = lfirst(cell);
5071 
5072  datums[j++] = CStringGetTextDatum(name);
5073  }
5074 
5075  MemoryContextSwitchTo(oldcxt);
5076 
5077  arr = construct_array(datums, list_length(list),
5078  TEXTOID, -1, false, 'i');
5079  MemoryContextDelete(memcxt);
5080 
5081  return arr;
5082 }
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