PostgreSQL Source Code  git master
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)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, 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)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

#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(), ATExecAttachPartitionIdx(), ATExecClusterOn(), ATExecDetachPartition(), ATExecDropInherit(), ATExecValidateConstraint(), CloneForeignKeyConstraints(), ConstraintSetParentConstraint(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTrigger(), 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(), index_constraint_create(), IndexSetParentIndex(), pg_event_trigger_ddl_commands(), publication_add_relation(), PublicationDropTables(), rename_constraint_internal(), rename_policy(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), SetFunctionArgType(), SetFunctionReturnType(), TypeCreate(), and TypeShellMake().

◆ ObjectAddressSubSet

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

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

◆ ObjectAddress

Function Documentation

◆ check_object_ownership()

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

Definition at line 2229 of file objectaddress.c.

References 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(), 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_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_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().

2231 {
2232  switch (objtype)
2233  {
2234  case OBJECT_INDEX:
2235  case OBJECT_SEQUENCE:
2236  case OBJECT_TABLE:
2237  case OBJECT_VIEW:
2238  case OBJECT_MATVIEW:
2239  case OBJECT_FOREIGN_TABLE:
2240  case OBJECT_COLUMN:
2241  case OBJECT_RULE:
2242  case OBJECT_TRIGGER:
2243  case OBJECT_POLICY:
2244  case OBJECT_TABCONSTRAINT:
2245  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2247  RelationGetRelationName(relation));
2248  break;
2249  case OBJECT_DATABASE:
2250  if (!pg_database_ownercheck(address.objectId, roleid))
2252  strVal((Value *) object));
2253  break;
2254  case OBJECT_TYPE:
2255  case OBJECT_DOMAIN:
2256  case OBJECT_ATTRIBUTE:
2257  case OBJECT_DOMCONSTRAINT:
2258  if (!pg_type_ownercheck(address.objectId, roleid))
2260  break;
2261  case OBJECT_AGGREGATE:
2262  case OBJECT_FUNCTION:
2263  case OBJECT_PROCEDURE:
2264  case OBJECT_ROUTINE:
2265  if (!pg_proc_ownercheck(address.objectId, roleid))
2267  NameListToString((castNode(ObjectWithArgs, object))->objname));
2268  break;
2269  case OBJECT_OPERATOR:
2270  if (!pg_oper_ownercheck(address.objectId, roleid))
2272  NameListToString((castNode(ObjectWithArgs, object))->objname));
2273  break;
2274  case OBJECT_SCHEMA:
2275  if (!pg_namespace_ownercheck(address.objectId, roleid))
2277  strVal((Value *) object));
2278  break;
2279  case OBJECT_COLLATION:
2280  if (!pg_collation_ownercheck(address.objectId, roleid))
2282  NameListToString(castNode(List, object)));
2283  break;
2284  case OBJECT_CONVERSION:
2285  if (!pg_conversion_ownercheck(address.objectId, roleid))
2287  NameListToString(castNode(List, object)));
2288  break;
2289  case OBJECT_EXTENSION:
2290  if (!pg_extension_ownercheck(address.objectId, roleid))
2292  strVal((Value *) object));
2293  break;
2294  case OBJECT_FDW:
2295  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2297  strVal((Value *) object));
2298  break;
2299  case OBJECT_FOREIGN_SERVER:
2300  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2302  strVal((Value *) object));
2303  break;
2304  case OBJECT_EVENT_TRIGGER:
2305  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2307  strVal((Value *) object));
2308  break;
2309  case OBJECT_LANGUAGE:
2310  if (!pg_language_ownercheck(address.objectId, roleid))
2312  strVal((Value *) object));
2313  break;
2314  case OBJECT_OPCLASS:
2315  if (!pg_opclass_ownercheck(address.objectId, roleid))
2317  NameListToString(castNode(List, object)));
2318  break;
2319  case OBJECT_OPFAMILY:
2320  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2322  NameListToString(castNode(List, object)));
2323  break;
2324  case OBJECT_LARGEOBJECT:
2325  if (!lo_compat_privileges &&
2326  !pg_largeobject_ownercheck(address.objectId, roleid))
2327  ereport(ERROR,
2328  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2329  errmsg("must be owner of large object %u",
2330  address.objectId)));
2331  break;
2332  case OBJECT_CAST:
2333  {
2334  /* We can only check permissions on the source/target types */
2335  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2336  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2337  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2338  Oid targettypeid = typenameTypeId(NULL, targettype);
2339 
2340  if (!pg_type_ownercheck(sourcetypeid, roleid)
2341  && !pg_type_ownercheck(targettypeid, roleid))
2342  ereport(ERROR,
2343  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2344  errmsg("must be owner of type %s or type %s",
2345  format_type_be(sourcetypeid),
2346  format_type_be(targettypeid))));
2347  }
2348  break;
2349  case OBJECT_PUBLICATION:
2350  if (!pg_publication_ownercheck(address.objectId, roleid))
2352  strVal((Value *) object));
2353  break;
2354  case OBJECT_SUBSCRIPTION:
2355  if (!pg_subscription_ownercheck(address.objectId, roleid))
2357  strVal((Value *) object));
2358  break;
2359  case OBJECT_TRANSFORM:
2360  {
2361  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2362  Oid typeid = typenameTypeId(NULL, typename);
2363 
2364  if (!pg_type_ownercheck(typeid, roleid))
2366  }
2367  break;
2368  case OBJECT_TABLESPACE:
2369  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2371  strVal((Value *) object));
2372  break;
2373  case OBJECT_TSDICTIONARY:
2374  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2376  NameListToString(castNode(List, object)));
2377  break;
2379  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2381  NameListToString(castNode(List, object)));
2382  break;
2383  case OBJECT_ROLE:
2384 
2385  /*
2386  * We treat roles as being "owned" by those with CREATEROLE priv,
2387  * except that superusers are only owned by superusers.
2388  */
2389  if (superuser_arg(address.objectId))
2390  {
2391  if (!superuser_arg(roleid))
2392  ereport(ERROR,
2393  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2394  errmsg("must be superuser")));
2395  }
2396  else
2397  {
2398  if (!has_createrole_privilege(roleid))
2399  ereport(ERROR,
2400  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2401  errmsg("must have CREATEROLE privilege")));
2402  }
2403  break;
2404  case OBJECT_TSPARSER:
2405  case OBJECT_TSTEMPLATE:
2406  case OBJECT_ACCESS_METHOD:
2407  /* We treat these object types as being owned by superusers */
2408  if (!superuser_arg(roleid))
2409  ereport(ERROR,
2410  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2411  errmsg("must be superuser")));
2412  break;
2413  case OBJECT_STATISTIC_EXT:
2414  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2416  break;
2417  default:
2418  elog(ERROR, "unrecognized object type: %d",
2419  (int) objtype);
2420  }
2421 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5373
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5192
bool lo_compat_privileges
Definition: inv_api.c:57
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4881
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5031
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4852
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5058
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5112
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5286
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4800
int errcode(int sqlerrcode)
Definition: elog.c:575
char * format_type_be(Oid type_oid)
Definition: format_type.c:328
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4924
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4774
#define linitial_node(type, l)
Definition: pg_list.h:114
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3659
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3348
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5139
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5244
#define RelationGetRelationName(relation)
Definition: rel.h:441
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4950
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5004
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5166
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:3082
#define lsecond_node(type, l)
Definition: pg_list.h:119
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4977
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5218
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4748
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5085
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:407
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4826
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5312
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5338

◆ get_catalog_object_by_oid()

HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

Definition at line 2627 of file objectaddress.c.

References Assert, BTEqualStrategyNumber, get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, 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().

2628 {
2629  HeapTuple tuple;
2630  Oid classId = RelationGetRelid(catalog);
2631  int oidCacheId = get_object_catcache_oid(classId);
2632 
2633  if (oidCacheId > 0)
2634  {
2635  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2636  if (!HeapTupleIsValid(tuple)) /* should not happen */
2637  return NULL;
2638  }
2639  else
2640  {
2641  Oid oidIndexId = get_object_oid_index(classId);
2642  SysScanDesc scan;
2643  ScanKeyData skey;
2644 
2645  Assert(OidIsValid(oidIndexId));
2646 
2647  ScanKeyInit(&skey,
2649  BTEqualStrategyNumber, F_OIDEQ,
2650  ObjectIdGetDatum(objectId));
2651 
2652  scan = systable_beginscan(catalog, oidIndexId, true,
2653  NULL, 1, &skey);
2654  tuple = systable_getnext(scan);
2655  if (!HeapTupleIsValid(tuple))
2656  {
2657  systable_endscan(scan);
2658  return NULL;
2659  }
2660  tuple = heap_copytuple(tuple);
2661 
2662  systable_endscan(scan);
2663  }
2664 
2665  return tuple;
2666 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:722
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:502
#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:605
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:331
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:699
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:173
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:407
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address()

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

Definition at line 797 of file objectaddress.c.

References Assert, castNode, ObjectAddress::classId, 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(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, 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_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), SharedInvalidMessageCounter, strVal, UnlockDatabaseObject(), and UnlockSharedObject().

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

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

◆ get_object_address_rv()

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

Definition at line 1092 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1095 {
1096  if (rel)
1097  {
1098  object = lcons(makeString(rel->relname), object);
1099  if (rel->schemaname)
1100  object = lcons(makeString(rel->schemaname), object);
1101  if (rel->catalogname)
1102  object = lcons(makeString(rel->catalogname), object);
1103  }
1104 
1105  return get_object_address(objtype, (Node *) object,
1106  relp, lockmode, missing_ok);
1107 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:517
char * schemaname
Definition: primnodes.h:68
char * relname
Definition: primnodes.h:69
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:67

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2537 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2538 {
2539  const ObjectPropertyType *prop = get_object_property_data(class_id);
2540 
2541  return prop->attnum_acl;
2542 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

◆ get_object_attnum_name()

AttrNumber get_object_attnum_name ( Oid  class_id)

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

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

◆ get_object_attnum_namespace()

AttrNumber get_object_attnum_namespace ( Oid  class_id)

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

2522 {
2523  const ObjectPropertyType *prop = get_object_property_data(class_id);
2524 
2525  return prop->attnum_namespace;
2526 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace

◆ get_object_attnum_owner()

AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2529 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

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

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2505 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2506 {
2507  const ObjectPropertyType *prop = get_object_property_data(class_id);
2508 
2509  return prop->name_catcache_id;
2510 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_catcache_oid()

int get_object_catcache_oid ( Oid  class_id)

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

2498 {
2499  const ObjectPropertyType *prop = get_object_property_data(class_id);
2500 
2501  return prop->oid_catcache_id;
2502 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2563 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2564 {
2565  const ObjectPropertyType *prop = get_object_property_data(class_id);
2566 
2567  return prop->is_nsp_name_unique;
2568 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

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

2431 {
2432  int cache;
2433  HeapTuple tuple;
2434  bool isnull;
2435  Oid oid;
2436  const ObjectPropertyType *property;
2437 
2438  /* If not owned by a namespace, just return InvalidOid. */
2439  property = get_object_property_data(address->classId);
2440  if (property->attnum_namespace == InvalidAttrNumber)
2441  return InvalidOid;
2442 
2443  /* Currently, we can only handle object types with system caches. */
2444  cache = property->oid_catcache_id;
2445  Assert(cache != -1);
2446 
2447  /* Fetch tuple from syscache and extract namespace attribute. */
2448  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2449  if (!HeapTupleIsValid(tuple))
2450  elog(ERROR, "cache lookup failed for cache %d oid %u",
2451  cache, address->objectId);
2452  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2453  tuple,
2454  property->attnum_namespace,
2455  &isnull));
2456  Assert(!isnull);
2457  ReleaseSysCache(tuple);
2458 
2459  return oid;
2460 }
#define DatumGetObjectId(X)
Definition: postgres.h:483
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:490
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:699
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog
Definition: elog.h:219

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2489 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2490 {
2491  const ObjectPropertyType *prop = get_object_property_data(class_id);
2492 
2493  return prop->oid_index_oid;
2494 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2545 of file objectaddress.c.

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

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

2546 {
2547  const ObjectPropertyType *prop = get_object_property_data(class_id);
2548 
2549  if (prop->objtype == OBJECT_TABLE)
2550  {
2551  /*
2552  * If the property data says it's a table, dig a little deeper to get
2553  * the real relation kind, so that callers can produce more precise
2554  * error messages.
2555  */
2556  return get_relkind_objtype(get_rel_relkind(object_id));
2557  }
2558  else
2559  return prop->objtype;
2560 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1805
static const ObjectPropertyType * get_object_property_data(Oid class_id)
ObjectType get_relkind_objtype(char relkind)

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 5116 of file objectaddress.c.

References elog, ERROR, OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, and OBJECT_VIEW.

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATPrepSetStatistics(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTrigger(), currtid_byrelname(), currtid_byreloid(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckRTPerms(), get_object_type(), get_rel_from_relname(), LockTableRecurse(), LockViewRecurse_walker(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), transformTableLikeClause(), and truncate_check_rel().

5117 {
5118  switch (relkind)
5119  {
5120  case RELKIND_RELATION:
5121  case RELKIND_PARTITIONED_TABLE:
5122  return OBJECT_TABLE;
5123  case RELKIND_INDEX:
5124  return OBJECT_INDEX;
5125  case RELKIND_SEQUENCE:
5126  return OBJECT_SEQUENCE;
5127  case RELKIND_VIEW:
5128  return OBJECT_VIEW;
5129  case RELKIND_MATVIEW:
5130  return OBJECT_MATVIEW;
5131  case RELKIND_FOREIGN_TABLE:
5132  return OBJECT_FOREIGN_TABLE;
5133  /* other relkinds are not supported here because they don't map to OBJECT_* values */
5134  default:
5135  elog(ERROR, "unexpected relkind: %d", relkind);
5136  return 0;
5137  }
5138 }
char relkind
Definition: pg_class.h:51
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

Definition at line 2674 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), AttrDefaultOidIndexId, BTEqualStrategyNumber, buffer, CastOidIndexId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_procedure(), format_type_be(), get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_rel_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), NameStr, 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, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), RewriteOidIndexId, ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, systable_beginscan(), systable_endscan(), systable_getnext(), TRFOID, TriggerOidIndexId, 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().

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3455 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3456 {
3457  ObjectAddress address;
3458 
3459  address.classId = classid;
3460  address.objectId = objid;
3461  address.objectSubId = 0;
3462 
3463  return getObjectDescription(&address);
3464 }
char * getObjectDescription(const ObjectAddress *object)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

char* getObjectIdentityParts ( const ObjectAddress address,
List **  objname,
List **  objargs 
)

Definition at line 4080 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, BTEqualStrategyNumber, buffer, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DefaultAclOidIndexId, 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_attname(), 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_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, 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, psprintf(), pstrdup(), PUBLICATIONREL, quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, subname, systable_beginscan(), systable_endscan(), systable_getnext(), TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, USERMAPPINGOID, and username.

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

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

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object)

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

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

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2575 of file objectaddress.c.

References lengthof.

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

2576 {
2577  int index;
2578 
2579  for (index = 0; index < lengthof(ObjectProperty); index++)
2580  {
2581  if (ObjectProperty[index].class_oid == class_id)
2582  return true;
2583  }
2584 
2585  return false;
2586 }
#define lengthof(array)
Definition: c.h:629
Definition: type.h:89
static const ObjectPropertyType ObjectProperty[]

◆ read_objtype_from_string()

int read_objtype_from_string ( const char *  objtype)

Definition at line 2469 of file objectaddress.c.

References ereport, errcode(), errmsg(), ERROR, i, lengthof, ObjectTypeMap, object_type_map::tm_name, and object_type_map::tm_type.

Referenced by pg_get_object_address().

2470 {
2471  int i;
2472 
2473  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2474  {
2475  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2476  return ObjectTypeMap[i].tm_type;
2477  }
2478  ereport(ERROR,
2479  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2480  errmsg("unrecognized object type \"%s\"", objtype)));
2481 
2482  return -1; /* keep compiler quiet */
2483 }
int errcode(int sqlerrcode)
Definition: elog.c:575
#define lengthof(array)
Definition: c.h:629
#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

◆ strlist_to_textarray()

ArrayType* strlist_to_textarray ( List list)

Definition at line 5081 of file objectaddress.c.

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

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

5082 {
5083  ArrayType *arr;
5084  Datum *datums;
5085  int j = 0;
5086  ListCell *cell;
5087  MemoryContext memcxt;
5088  MemoryContext oldcxt;
5089 
5090  /* Work in a temp context; easier than individually pfree'ing the Datums */
5092  "strlist to array",
5094  oldcxt = MemoryContextSwitchTo(memcxt);
5095 
5096  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5097 
5098  foreach(cell, list)
5099  {
5100  char *name = lfirst(cell);
5101 
5102  datums[j++] = CStringGetTextDatum(name);
5103  }
5104 
5105  MemoryContextSwitchTo(oldcxt);
5106 
5107  arr = construct_array(datums, list_length(list),
5108  TEXTOID, -1, false, 'i');
5109 
5110  MemoryContextDelete(memcxt);
5111 
5112  return arr;
5113 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
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:3279
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:170
uintptr_t Datum
Definition: postgres.h:365
#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:924
#define CStringGetTextDatum(s)
Definition: builtins.h:95

Variable Documentation

◆ InvalidObjectAddress