PostgreSQL Source Code  git master
objectaddress.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/relation.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_namespace.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "storage/large_object.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
Include dependency graph for objectaddress.c:

Go to the source code of this file.

Data Structures

struct  ObjectPropertyType
 
struct  object_type_map
 

Functions

static ObjectAddress get_object_address_unqualified (ObjectType objtype, String *strval, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (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)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
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)
 
static ObjectAddress get_object_address_publication_schema (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid, bool missing_ok)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid, bool missing_ok)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid, bool missing_ok)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid, bool missing_ok)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object, bool missing_ok)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object, bool missing_ok)
 
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)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
const char * get_object_class_descr (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_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
bool is_objectclass_supported (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
static bool getPublicationSchemaInfo (const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
 
char * getObjectDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
Datum pg_describe_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object_as_address (PG_FUNCTION_ARGS)
 
Datum pg_get_acl (PG_FUNCTION_ARGS)
 
char * getObjectTypeDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

static const ObjectPropertyType ObjectProperty []
 
static const struct object_type_map ObjectTypeMap []
 
const ObjectAddress InvalidObjectAddress
 

Function Documentation

◆ check_object_ownership()

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

Definition at line 2387 of file objectaddress.c.

2389 {
2390  switch (objtype)
2391  {
2392  case OBJECT_INDEX:
2393  case OBJECT_SEQUENCE:
2394  case OBJECT_TABLE:
2395  case OBJECT_VIEW:
2396  case OBJECT_MATVIEW:
2397  case OBJECT_FOREIGN_TABLE:
2398  case OBJECT_COLUMN:
2399  case OBJECT_RULE:
2400  case OBJECT_TRIGGER:
2401  case OBJECT_POLICY:
2402  case OBJECT_TABCONSTRAINT:
2403  if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2405  RelationGetRelationName(relation));
2406  break;
2407  case OBJECT_TYPE:
2408  case OBJECT_DOMAIN:
2409  case OBJECT_ATTRIBUTE:
2410  if (!object_ownercheck(address.classId, address.objectId, roleid))
2412  break;
2413  case OBJECT_DOMCONSTRAINT:
2414  {
2415  HeapTuple tuple;
2416  Oid contypid;
2417 
2418  tuple = SearchSysCache1(CONSTROID,
2419  ObjectIdGetDatum(address.objectId));
2420  if (!HeapTupleIsValid(tuple))
2421  elog(ERROR, "constraint with OID %u does not exist",
2422  address.objectId);
2423 
2424  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2425 
2426  ReleaseSysCache(tuple);
2427 
2428  /*
2429  * Fallback to type ownership check in this case as this is
2430  * what domain constraints rely on.
2431  */
2432  if (!object_ownercheck(TypeRelationId, contypid, roleid))
2434  }
2435  break;
2436  case OBJECT_AGGREGATE:
2437  case OBJECT_FUNCTION:
2438  case OBJECT_PROCEDURE:
2439  case OBJECT_ROUTINE:
2440  case OBJECT_OPERATOR:
2441  if (!object_ownercheck(address.classId, address.objectId, roleid))
2443  NameListToString((castNode(ObjectWithArgs, object))->objname));
2444  break;
2445  case OBJECT_DATABASE:
2446  case OBJECT_EVENT_TRIGGER:
2447  case OBJECT_EXTENSION:
2448  case OBJECT_FDW:
2449  case OBJECT_FOREIGN_SERVER:
2450  case OBJECT_LANGUAGE:
2451  case OBJECT_PUBLICATION:
2452  case OBJECT_SCHEMA:
2453  case OBJECT_SUBSCRIPTION:
2454  case OBJECT_TABLESPACE:
2455  if (!object_ownercheck(address.classId, address.objectId, roleid))
2457  strVal(object));
2458  break;
2459  case OBJECT_COLLATION:
2460  case OBJECT_CONVERSION:
2461  case OBJECT_OPCLASS:
2462  case OBJECT_OPFAMILY:
2463  case OBJECT_STATISTIC_EXT:
2464  case OBJECT_TSDICTIONARY:
2466  if (!object_ownercheck(address.classId, address.objectId, roleid))
2468  NameListToString(castNode(List, object)));
2469  break;
2470  case OBJECT_LARGEOBJECT:
2471  if (!lo_compat_privileges &&
2472  !object_ownercheck(address.classId, address.objectId, roleid))
2473  ereport(ERROR,
2474  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2475  errmsg("must be owner of large object %u",
2476  address.objectId)));
2477  break;
2478  case OBJECT_CAST:
2479  {
2480  /* We can only check permissions on the source/target types */
2481  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2482  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2483  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2484  Oid targettypeid = typenameTypeId(NULL, targettype);
2485 
2486  if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
2487  && !object_ownercheck(TypeRelationId, targettypeid, roleid))
2488  ereport(ERROR,
2489  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2490  errmsg("must be owner of type %s or type %s",
2491  format_type_be(sourcetypeid),
2492  format_type_be(targettypeid))));
2493  }
2494  break;
2495  case OBJECT_TRANSFORM:
2496  {
2497  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2498  Oid typeid = typenameTypeId(NULL, typename);
2499 
2500  if (!object_ownercheck(TypeRelationId, typeid, roleid))
2502  }
2503  break;
2504  case OBJECT_ROLE:
2505 
2506  /*
2507  * We treat roles as being "owned" by those with CREATEROLE priv,
2508  * provided that they also have admin option on the role.
2509  *
2510  * However, superusers are only owned by superusers.
2511  */
2512  if (superuser_arg(address.objectId))
2513  {
2514  if (!superuser_arg(roleid))
2515  ereport(ERROR,
2516  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2517  errmsg("permission denied"),
2518  errdetail("The current user must have the %s attribute.",
2519  "SUPERUSER")));
2520  }
2521  else
2522  {
2523  if (!has_createrole_privilege(roleid))
2524  ereport(ERROR,
2525  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2526  errmsg("permission denied"),
2527  errdetail("The current user must have the %s attribute.",
2528  "CREATEROLE")));
2529  if (!is_admin_of_role(roleid, address.objectId))
2530  ereport(ERROR,
2531  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2532  errmsg("permission denied"),
2533  errdetail("The current user must have the %s option on role \"%s\".",
2534  "ADMIN",
2535  GetUserNameFromId(address.objectId,
2536  true))));
2537  }
2538  break;
2539  case OBJECT_TSPARSER:
2540  case OBJECT_TSTEMPLATE:
2541  case OBJECT_ACCESS_METHOD:
2542  case OBJECT_PARAMETER_ACL:
2543  /* We treat these object types as being owned by superusers */
2544  if (!superuser_arg(roleid))
2545  ereport(ERROR,
2546  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2547  errmsg("must be superuser")));
2548  break;
2549  case OBJECT_AMOP:
2550  case OBJECT_AMPROC:
2551  case OBJECT_DEFAULT:
2552  case OBJECT_DEFACL:
2555  case OBJECT_USER_MAPPING:
2556  /* These are currently not supported or don't make sense here. */
2557  elog(ERROR, "unsupported object type: %d", (int) objtype);
2558  break;
2559  }
2560 }
bool is_admin_of_role(Oid member, Oid role)
Definition: acl.c:5398
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2622
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4064
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:2941
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:4145
int errdetail(const char *fmt,...)
Definition: elog.c:1203
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
bool lo_compat_privileges
Definition: inv_api.c:56
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:1041
char * NameListToString(const List *names)
Definition: namespace.c:3594
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2282
@ OBJECT_FDW
Definition: parsenodes.h:2284
@ OBJECT_TSPARSER
Definition: parsenodes.h:2315
@ OBJECT_COLLATION
Definition: parsenodes.h:2275
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2318
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2268
@ OBJECT_OPCLASS
Definition: parsenodes.h:2292
@ OBJECT_DEFACL
Definition: parsenodes.h:2279
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2269
@ OBJECT_MATVIEW
Definition: parsenodes.h:2291
@ OBJECT_SCHEMA
Definition: parsenodes.h:2304
@ OBJECT_POLICY
Definition: parsenodes.h:2296
@ OBJECT_OPERATOR
Definition: parsenodes.h:2293
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2286
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2313
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2294
@ OBJECT_DOMAIN
Definition: parsenodes.h:2280
@ OBJECT_COLUMN
Definition: parsenodes.h:2274
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2310
@ OBJECT_ROLE
Definition: parsenodes.h:2301
@ OBJECT_ROUTINE
Definition: parsenodes.h:2302
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2290
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2299
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2297
@ OBJECT_EXTENSION
Definition: parsenodes.h:2283
@ OBJECT_INDEX
Definition: parsenodes.h:2288
@ OBJECT_DEFAULT
Definition: parsenodes.h:2278
@ OBJECT_DATABASE
Definition: parsenodes.h:2277
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2305
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2316
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2289
@ OBJECT_AMOP
Definition: parsenodes.h:2270
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2300
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2285
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2314
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2272
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2298
@ OBJECT_RULE
Definition: parsenodes.h:2303
@ OBJECT_CONVERSION
Definition: parsenodes.h:2276
@ OBJECT_AMPROC
Definition: parsenodes.h:2271
@ OBJECT_TABLE
Definition: parsenodes.h:2309
@ OBJECT_VIEW
Definition: parsenodes.h:2319
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2295
@ OBJECT_TYPE
Definition: parsenodes.h:2317
@ OBJECT_FUNCTION
Definition: parsenodes.h:2287
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2308
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2281
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2306
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2307
@ OBJECT_CAST
Definition: parsenodes.h:2273
@ OBJECT_TRIGGER
Definition: parsenodes.h:2312
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2311
FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition: pg_list.h:181
#define lsecond_node(type, l)
Definition: pg_list.h:186
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:505
#define RelationGetRelationName(relation)
Definition: rel.h:539
Definition: pg_list.h:54
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221
#define strVal(v)
Definition: value.h:82

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

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

◆ get_catalog_object_by_oid()

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

Definition at line 2786 of file objectaddress.c.

2787 {
2788  HeapTuple tuple;
2789  Oid classId = RelationGetRelid(catalog);
2790  int oidCacheId = get_object_catcache_oid(classId);
2791 
2792  if (oidCacheId > 0)
2793  {
2794  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2795  if (!HeapTupleIsValid(tuple)) /* should not happen */
2796  return NULL;
2797  }
2798  else
2799  {
2800  Oid oidIndexId = get_object_oid_index(classId);
2801  SysScanDesc scan;
2802  ScanKeyData skey;
2803 
2804  Assert(OidIsValid(oidIndexId));
2805 
2806  ScanKeyInit(&skey,
2807  oidcol,
2808  BTEqualStrategyNumber, F_OIDEQ,
2809  ObjectIdGetDatum(objectId));
2810 
2811  scan = systable_beginscan(catalog, oidIndexId, true,
2812  NULL, 1, &skey);
2813  tuple = systable_getnext(scan);
2814  if (!HeapTupleIsValid(tuple))
2815  {
2816  systable_endscan(scan);
2817  return NULL;
2818  }
2819  tuple = heap_copytuple(tuple);
2820 
2821  systable_endscan(scan);
2822  }
2823 
2824  return tuple;
2825 }
#define Assert(condition)
Definition: c.h:812
#define OidIsValid(objectId)
Definition: c.h:729
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:606
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:513
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:776
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(Oid class_id)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:91

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

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

◆ get_object_address()

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

Definition at line 923 of file objectaddress.c.

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

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_publication_schema(), get_object_address_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), SharedInvalidMessageCounter, strVal, UnlockDatabaseObject(), and UnlockSharedObject().

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

◆ get_object_address_attrdef()

static ObjectAddress get_object_address_attrdef ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1550 of file objectaddress.c.

1553 {
1554  ObjectAddress address;
1555  List *relname;
1556  Oid reloid;
1557  Relation relation;
1558  const char *attname;
1560  TupleDesc tupdesc;
1561  Oid defoid;
1562 
1563  /* Extract relation name and open relation. */
1564  if (list_length(object) < 2)
1565  ereport(ERROR,
1566  (errcode(ERRCODE_SYNTAX_ERROR),
1567  errmsg("column name must be qualified")));
1568  attname = strVal(llast(object));
1569  relname = list_copy_head(object, list_length(object) - 1);
1570  /* XXX no missing_ok support here */
1571  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1572  reloid = RelationGetRelid(relation);
1573 
1574  tupdesc = RelationGetDescr(relation);
1575 
1576  /* Look up attribute number and fetch the pg_attrdef OID */
1577  attnum = get_attnum(reloid, attname);
1578  defoid = InvalidOid;
1579  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1580  defoid = GetAttrDefaultOid(reloid, attnum);
1581  if (!OidIsValid(defoid))
1582  {
1583  if (!missing_ok)
1584  ereport(ERROR,
1585  (errcode(ERRCODE_UNDEFINED_COLUMN),
1586  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1588 
1589  address.classId = AttrDefaultRelationId;
1590  address.objectId = InvalidOid;
1591  address.objectSubId = InvalidAttrNumber;
1592  relation_close(relation, lockmode);
1593  return address;
1594  }
1595 
1596  address.classId = AttrDefaultRelationId;
1597  address.objectId = defoid;
1598  address.objectSubId = 0;
1599 
1600  *relp = relation;
1601  return address;
1602 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
List * list_copy_head(const List *oldlist, int len)
Definition: list.c:1593
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:858
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3554
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Definition: pg_attrdef.c:339
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:74
NameData relname
Definition: pg_class.h:38
#define llast(l)
Definition: pg_list.h:198
static int list_length(const List *l)
Definition: pg_list.h:152
#define RelationGetDescr(relation)
Definition: rel.h:531
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:137
TupleConstr * constr
Definition: tupdesc.h:85

References attname, attnum, ObjectAddress::classId, TupleDescData::constr, ereport, errcode(), errmsg(), ERROR, get_attnum(), GetAttrDefaultOid(), InvalidAttrNumber, InvalidOid, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, relation_close(), relation_openrv(), RelationGetDescr, RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_attribute()

static ObjectAddress get_object_address_attribute ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1499 of file objectaddress.c.

1502 {
1503  ObjectAddress address;
1504  List *relname;
1505  Oid reloid;
1506  Relation relation;
1507  const char *attname;
1509 
1510  /* Extract relation name and open relation. */
1511  if (list_length(object) < 2)
1512  ereport(ERROR,
1513  (errcode(ERRCODE_SYNTAX_ERROR),
1514  errmsg("column name must be qualified")));
1515  attname = strVal(llast(object));
1516  relname = list_copy_head(object, list_length(object) - 1);
1517  /* XXX no missing_ok support here */
1518  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1519  reloid = RelationGetRelid(relation);
1520 
1521  /* Look up attribute and construct return value. */
1522  attnum = get_attnum(reloid, attname);
1523  if (attnum == InvalidAttrNumber)
1524  {
1525  if (!missing_ok)
1526  ereport(ERROR,
1527  (errcode(ERRCODE_UNDEFINED_COLUMN),
1528  errmsg("column \"%s\" of relation \"%s\" does not exist",
1530 
1531  address.classId = RelationRelationId;
1532  address.objectId = InvalidOid;
1533  address.objectSubId = InvalidAttrNumber;
1534  relation_close(relation, lockmode);
1535  return address;
1536  }
1537 
1538  address.classId = RelationRelationId;
1539  address.objectId = reloid;
1540  address.objectSubId = attnum;
1541 
1542  *relp = relation;
1543  return address;
1544 }

References attname, attnum, ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, get_attnum(), InvalidAttrNumber, InvalidOid, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, relation_close(), relation_openrv(), RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 1963 of file objectaddress.c.

1964 {
1965  HeapTuple tp;
1966  Oid userid;
1967  Oid schemaid;
1968  char *username;
1969  char *schema;
1970  char objtype;
1971  char *objtype_str;
1972  ObjectAddress address;
1973 
1974  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1975 
1976  /*
1977  * First figure out the textual attributes so that they can be used for
1978  * error reporting.
1979  */
1980  username = strVal(lsecond(object));
1981  if (list_length(object) >= 3)
1982  schema = (char *) strVal(lthird(object));
1983  else
1984  schema = NULL;
1985 
1986  /*
1987  * Decode defaclobjtype. Only first char is considered; the rest of the
1988  * string, if any, is blissfully ignored.
1989  */
1990  objtype = ((char *) strVal(linitial(object)))[0];
1991  switch (objtype)
1992  {
1993  case DEFACLOBJ_RELATION:
1994  objtype_str = "tables";
1995  break;
1996  case DEFACLOBJ_SEQUENCE:
1997  objtype_str = "sequences";
1998  break;
1999  case DEFACLOBJ_FUNCTION:
2000  objtype_str = "functions";
2001  break;
2002  case DEFACLOBJ_TYPE:
2003  objtype_str = "types";
2004  break;
2005  case DEFACLOBJ_NAMESPACE:
2006  objtype_str = "schemas";
2007  break;
2008  default:
2009  ereport(ERROR,
2010  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2011  errmsg("unrecognized default ACL object type \"%c\"", objtype),
2012  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2013  DEFACLOBJ_RELATION,
2014  DEFACLOBJ_SEQUENCE,
2015  DEFACLOBJ_FUNCTION,
2016  DEFACLOBJ_TYPE,
2017  DEFACLOBJ_NAMESPACE)));
2018  }
2019 
2020  /*
2021  * Look up user ID. Behave as "default ACL not found" if the user doesn't
2022  * exist.
2023  */
2024  tp = SearchSysCache1(AUTHNAME,
2026  if (!HeapTupleIsValid(tp))
2027  goto not_found;
2028  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2029  ReleaseSysCache(tp);
2030 
2031  /*
2032  * If a schema name was given, look up its OID. If it doesn't exist,
2033  * behave as "default ACL not found".
2034  */
2035  if (schema)
2036  {
2037  schemaid = get_namespace_oid(schema, true);
2038  if (schemaid == InvalidOid)
2039  goto not_found;
2040  }
2041  else
2042  schemaid = InvalidOid;
2043 
2044  /* Finally, look up the pg_default_acl object */
2045  tp = SearchSysCache3(DEFACLROLENSPOBJ,
2046  ObjectIdGetDatum(userid),
2047  ObjectIdGetDatum(schemaid),
2048  CharGetDatum(objtype));
2049  if (!HeapTupleIsValid(tp))
2050  goto not_found;
2051 
2052  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2053  ReleaseSysCache(tp);
2054 
2055  return address;
2056 
2057 not_found:
2058  if (!missing_ok)
2059  {
2060  if (schema)
2061  ereport(ERROR,
2062  (errcode(ERRCODE_UNDEFINED_OBJECT),
2063  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2064  username, schema, objtype_str)));
2065  else
2066  ereport(ERROR,
2067  (errcode(ERRCODE_UNDEFINED_OBJECT),
2068  errmsg("default ACL for user \"%s\" on %s does not exist",
2069  username, objtype_str)));
2070  }
2071  return address;
2072 }
int errhint(const char *fmt,...)
Definition: elog.c:1317
static char * username
Definition: initdb.c:153
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3535
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
FormData_pg_default_acl * Form_pg_default_acl
#define lthird(l)
Definition: pg_list.h:188
#define linitial(l)
Definition: pg_list.h:178
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum CharGetDatum(char X)
Definition: postgres.h:122
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:243

References CharGetDatum(), CStringGetDatum(), ereport, errcode(), errhint(), errmsg(), ERROR, get_namespace_oid(), GETSTRUCT, HeapTupleIsValid, InvalidOid, linitial, list_length(), lsecond, lthird, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), SearchSysCache3(), strVal, and username.

Referenced by get_object_address().

◆ get_object_address_opcf()

static ObjectAddress get_object_address_opcf ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1647 of file objectaddress.c.

1648 {
1649  Oid amoid;
1650  ObjectAddress address;
1651 
1652  /* XXX no missing_ok support here */
1653  amoid = get_index_am_oid(strVal(linitial(object)), false);
1654  object = list_copy_tail(object, 1);
1655 
1656  switch (objtype)
1657  {
1658  case OBJECT_OPCLASS:
1659  address.classId = OperatorClassRelationId;
1660  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1661  address.objectSubId = 0;
1662  break;
1663  case OBJECT_OPFAMILY:
1664  address.classId = OperatorFamilyRelationId;
1665  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1666  address.objectSubId = 0;
1667  break;
1668  default:
1669  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1670  /* placate compiler, which doesn't know elog won't return */
1671  address.classId = InvalidOid;
1672  address.objectId = InvalidOid;
1673  address.objectSubId = 0;
1674  }
1675 
1676  return address;
1677 }
Oid get_index_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:163
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1613
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:220
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:139

References ObjectAddress::classId, elog, ERROR, get_index_am_oid(), get_opclass_oid(), get_opfamily_oid(), InvalidOid, linitial, list_copy_tail(), OBJECT_OPCLASS, OBJECT_OPFAMILY, ObjectAddress::objectId, ObjectAddress::objectSubId, and strVal.

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_opf_member()

static ObjectAddress get_object_address_opf_member ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1685 of file objectaddress.c.

1687 {
1688  ObjectAddress famaddr;
1689  ObjectAddress address;
1690  ListCell *cell;
1691  List *copy;
1692  TypeName *typenames[2];
1693  Oid typeoids[2];
1694  int membernum;
1695  int i;
1696 
1697  /*
1698  * The last element of the object list contains the strategy or procedure
1699  * number. We need to strip that out before getting the opclass/family
1700  * address. The rest can be used directly by get_object_address_opcf().
1701  */
1702  membernum = atoi(strVal(llast(linitial(object))));
1703  copy = list_copy_head(linitial(object), list_length(linitial(object)) - 1);
1704 
1705  /* no missing_ok support here */
1706  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1707 
1708  /* find out left/right type names and OIDs */
1709  typenames[0] = typenames[1] = NULL;
1710  typeoids[0] = typeoids[1] = InvalidOid;
1711  i = 0;
1712  foreach(cell, lsecond(object))
1713  {
1714  ObjectAddress typaddr;
1715 
1716  typenames[i] = lfirst_node(TypeName, cell);
1717  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1718  typeoids[i] = typaddr.objectId;
1719  if (++i >= 2)
1720  break;
1721  }
1722 
1723  switch (objtype)
1724  {
1725  case OBJECT_AMOP:
1726  {
1727  HeapTuple tp;
1728 
1729  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1730  InvalidOid);
1731 
1732  tp = SearchSysCache4(AMOPSTRATEGY,
1733  ObjectIdGetDatum(famaddr.objectId),
1734  ObjectIdGetDatum(typeoids[0]),
1735  ObjectIdGetDatum(typeoids[1]),
1736  Int16GetDatum(membernum));
1737  if (!HeapTupleIsValid(tp))
1738  {
1739  if (!missing_ok)
1740  ereport(ERROR,
1741  (errcode(ERRCODE_UNDEFINED_OBJECT),
1742  errmsg("operator %d (%s, %s) of %s does not exist",
1743  membernum,
1746  getObjectDescription(&famaddr, false))));
1747  }
1748  else
1749  {
1750  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1751  ReleaseSysCache(tp);
1752  }
1753  }
1754  break;
1755 
1756  case OBJECT_AMPROC:
1757  {
1758  HeapTuple tp;
1759 
1760  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1761  InvalidOid);
1762 
1763  tp = SearchSysCache4(AMPROCNUM,
1764  ObjectIdGetDatum(famaddr.objectId),
1765  ObjectIdGetDatum(typeoids[0]),
1766  ObjectIdGetDatum(typeoids[1]),
1767  Int16GetDatum(membernum));
1768  if (!HeapTupleIsValid(tp))
1769  {
1770  if (!missing_ok)
1771  ereport(ERROR,
1772  (errcode(ERRCODE_UNDEFINED_OBJECT),
1773  errmsg("function %d (%s, %s) of %s does not exist",
1774  membernum,
1777  getObjectDescription(&famaddr, false))));
1778  }
1779  else
1780  {
1781  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1782  ReleaseSysCache(tp);
1783  }
1784  }
1785  break;
1786  default:
1787  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1788  }
1789 
1790  return address;
1791 }
int i
Definition: isn.c:72
const char ** typenames
Definition: lexi.c:115
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:478
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:254

References elog, ereport, errcode(), errmsg(), ERROR, get_object_address_opcf(), get_object_address_type(), getObjectDescription(), GETSTRUCT, HeapTupleIsValid, i, Int16GetDatum(), InvalidOid, lfirst_node, linitial, list_copy_head(), list_length(), llast, lsecond, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_OPFAMILY, OBJECT_TYPE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache4(), strVal, typenames, and TypeNameToString().

Referenced by get_object_address().

◆ get_object_address_publication_rel()

static ObjectAddress get_object_address_publication_rel ( List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1868 of file objectaddress.c.

1870 {
1871  ObjectAddress address;
1872  Relation relation;
1873  List *relname;
1874  char *pubname;
1875  Publication *pub;
1876 
1877  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1878 
1879  relname = linitial(object);
1881  AccessShareLock, missing_ok);
1882  if (!relation)
1883  return address;
1884 
1885  /* fetch publication name from input list */
1886  pubname = strVal(lsecond(object));
1887 
1888  /* Now look up the pg_publication tuple */
1889  pub = GetPublicationByName(pubname, missing_ok);
1890  if (!pub)
1891  {
1892  relation_close(relation, AccessShareLock);
1893  return address;
1894  }
1895 
1896  /* Find the publication relation mapping in syscache. */
1897  address.objectId =
1898  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1900  ObjectIdGetDatum(pub->oid));
1901  if (!OidIsValid(address.objectId))
1902  {
1903  if (!missing_ok)
1904  ereport(ERROR,
1905  (errcode(ERRCODE_UNDEFINED_OBJECT),
1906  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1907  RelationGetRelationName(relation), pubname)));
1908  relation_close(relation, AccessShareLock);
1909  return address;
1910  }
1911 
1912  *relp = relation;
1913  return address;
1914 }
#define AccessShareLock
Definition: lockdefs.h:36
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:172
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:111

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, makeRangeVarFromNameList(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, relation_close(), relation_openrv_extended(), RelationGetRelationName, RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_publication_schema()

static ObjectAddress get_object_address_publication_schema ( List object,
bool  missing_ok 
)
static

Definition at line 1921 of file objectaddress.c.

1922 {
1923  ObjectAddress address;
1924  Publication *pub;
1925  char *pubname;
1926  char *schemaname;
1927  Oid schemaid;
1928 
1929  ObjectAddressSet(address, PublicationNamespaceRelationId, InvalidOid);
1930 
1931  /* Fetch schema name and publication name from input list */
1932  schemaname = strVal(linitial(object));
1933  pubname = strVal(lsecond(object));
1934 
1935  schemaid = get_namespace_oid(schemaname, missing_ok);
1936  if (!OidIsValid(schemaid))
1937  return address;
1938 
1939  /* Now look up the pg_publication tuple */
1940  pub = GetPublicationByName(pubname, missing_ok);
1941  if (!pub)
1942  return address;
1943 
1944  /* Find the publication schema mapping in syscache */
1945  address.objectId =
1946  GetSysCacheOid2(PUBLICATIONNAMESPACEMAP,
1947  Anum_pg_publication_namespace_oid,
1948  ObjectIdGetDatum(schemaid),
1949  ObjectIdGetDatum(pub->oid));
1950  if (!OidIsValid(address.objectId) && !missing_ok)
1951  ereport(ERROR,
1952  (errcode(ERRCODE_UNDEFINED_OBJECT),
1953  errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
1954  schemaname, pubname)));
1955 
1956  return address;
1957 }

References ereport, errcode(), errmsg(), ERROR, get_namespace_oid(), GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, and strVal.

Referenced by get_object_address().

◆ get_object_address_relobject()

static ObjectAddress get_object_address_relobject ( ObjectType  objtype,
List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1420 of file objectaddress.c.

1422 {
1423  ObjectAddress address;
1424  Relation relation = NULL;
1425  int nnames;
1426  const char *depname;
1427  List *relname;
1428  Oid reloid;
1429 
1430  /* Extract name of dependent object. */
1431  depname = strVal(llast(object));
1432 
1433  /* Separate relation name from dependent object name. */
1434  nnames = list_length(object);
1435  if (nnames < 2)
1436  ereport(ERROR,
1437  (errcode(ERRCODE_SYNTAX_ERROR),
1438  errmsg("must specify relation and object name")));
1439 
1440  /* Extract relation name and open relation. */
1441  relname = list_copy_head(object, nnames - 1);
1444  missing_ok);
1445 
1446  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1447 
1448  switch (objtype)
1449  {
1450  case OBJECT_RULE:
1451  address.classId = RewriteRelationId;
1452  address.objectId = relation ?
1453  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1454  address.objectSubId = 0;
1455  break;
1456  case OBJECT_TRIGGER:
1457  address.classId = TriggerRelationId;
1458  address.objectId = relation ?
1459  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1460  address.objectSubId = 0;
1461  break;
1462  case OBJECT_TABCONSTRAINT:
1463  address.classId = ConstraintRelationId;
1464  address.objectId = relation ?
1465  get_relation_constraint_oid(reloid, depname, missing_ok) :
1466  InvalidOid;
1467  address.objectSubId = 0;
1468  break;
1469  case OBJECT_POLICY:
1470  address.classId = PolicyRelationId;
1471  address.objectId = relation ?
1472  get_relation_policy_oid(reloid, depname, missing_ok) :
1473  InvalidOid;
1474  address.objectSubId = 0;
1475  break;
1476  default:
1477  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1478  }
1479 
1480  /* Avoid relcache leak when object not found. */
1481  if (!OidIsValid(address.objectId))
1482  {
1483  if (relation != NULL)
1484  table_close(relation, AccessShareLock);
1485 
1486  relation = NULL; /* department of accident prevention */
1487  return address;
1488  }
1489 
1490  /* Done. */
1491  *relp = relation;
1492  return address;
1493 }
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1204
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: table.c:103
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1366

References AccessShareLock, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, get_relation_constraint_oid(), get_relation_policy_oid(), get_rewrite_oid(), get_trigger_oid(), InvalidOid, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), OBJECT_POLICY, OBJECT_RULE, OBJECT_TABCONSTRAINT, OBJECT_TRIGGER, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, RelationGetRelid, relname, strVal, table_close(), and table_openrv_extended().

Referenced by get_object_address().

◆ 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 1225 of file objectaddress.c.

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

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

Referenced by ExecAlterObjectDependsStmt().

◆ get_object_address_type()

static ObjectAddress get_object_address_type ( ObjectType  objtype,
TypeName typename,
bool  missing_ok 
)
static

Definition at line 1608 of file objectaddress.c.

1609 {
1610  ObjectAddress address;
1611  Type tup;
1612 
1613  address.classId = TypeRelationId;
1614  address.objectId = InvalidOid;
1615  address.objectSubId = 0;
1616 
1617  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1618  if (!HeapTupleIsValid(tup))
1619  {
1620  if (!missing_ok)
1621  ereport(ERROR,
1622  (errcode(ERRCODE_UNDEFINED_OBJECT),
1623  errmsg("type \"%s\" does not exist",
1624  TypeNameToString(typename))));
1625  return address;
1626  }
1627  address.objectId = typeTypeId(tup);
1628 
1629  if (objtype == OBJECT_DOMAIN)
1630  {
1631  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1632  ereport(ERROR,
1633  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1634  errmsg("\"%s\" is not a domain",
1635  TypeNameToString(typename))));
1636  }
1637 
1638  ReleaseSysCache(tup);
1639 
1640  return address;
1641 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
Oid typeTypeId(Type tp)
Definition: parse_type.c:590
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261

References ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, InvalidOid, LookupTypeName(), OBJECT_DOMAIN, ObjectAddress::objectId, ObjectAddress::objectSubId, ReleaseSysCache(), TypeNameToString(), and typeTypeId().

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_unqualified()

static ObjectAddress get_object_address_unqualified ( ObjectType  objtype,
String strval,
bool  missing_ok 
)
static

Definition at line 1247 of file objectaddress.c.

1249 {
1250  const char *name;
1251  ObjectAddress address;
1252 
1253  name = strVal(strval);
1254 
1255  /* Translate name to OID. */
1256  switch (objtype)
1257  {
1258  case OBJECT_ACCESS_METHOD:
1259  address.classId = AccessMethodRelationId;
1260  address.objectId = get_am_oid(name, missing_ok);
1261  address.objectSubId = 0;
1262  break;
1263  case OBJECT_DATABASE:
1264  address.classId = DatabaseRelationId;
1265  address.objectId = get_database_oid(name, missing_ok);
1266  address.objectSubId = 0;
1267  break;
1268  case OBJECT_EXTENSION:
1269  address.classId = ExtensionRelationId;
1270  address.objectId = get_extension_oid(name, missing_ok);
1271  address.objectSubId = 0;
1272  break;
1273  case OBJECT_TABLESPACE:
1274  address.classId = TableSpaceRelationId;
1275  address.objectId = get_tablespace_oid(name, missing_ok);
1276  address.objectSubId = 0;
1277  break;
1278  case OBJECT_ROLE:
1279  address.classId = AuthIdRelationId;
1280  address.objectId = get_role_oid(name, missing_ok);
1281  address.objectSubId = 0;
1282  break;
1283  case OBJECT_SCHEMA:
1284  address.classId = NamespaceRelationId;
1285  address.objectId = get_namespace_oid(name, missing_ok);
1286  address.objectSubId = 0;
1287  break;
1288  case OBJECT_LANGUAGE:
1289  address.classId = LanguageRelationId;
1290  address.objectId = get_language_oid(name, missing_ok);
1291  address.objectSubId = 0;
1292  break;
1293  case OBJECT_FDW:
1294  address.classId = ForeignDataWrapperRelationId;
1295  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1296  address.objectSubId = 0;
1297  break;
1298  case OBJECT_FOREIGN_SERVER:
1299  address.classId = ForeignServerRelationId;
1300  address.objectId = get_foreign_server_oid(name, missing_ok);
1301  address.objectSubId = 0;
1302  break;
1303  case OBJECT_EVENT_TRIGGER:
1304  address.classId = EventTriggerRelationId;
1305  address.objectId = get_event_trigger_oid(name, missing_ok);
1306  address.objectSubId = 0;
1307  break;
1308  case OBJECT_PARAMETER_ACL:
1309  address.classId = ParameterAclRelationId;
1310  address.objectId = ParameterAclLookup(name, missing_ok);
1311  address.objectSubId = 0;
1312  break;
1313  case OBJECT_PUBLICATION:
1314  address.classId = PublicationRelationId;
1315  address.objectId = get_publication_oid(name, missing_ok);
1316  address.objectSubId = 0;
1317  break;
1318  case OBJECT_SUBSCRIPTION:
1319  address.classId = SubscriptionRelationId;
1320  address.objectId = get_subscription_oid(name, missing_ok);
1321  address.objectSubId = 0;
1322  break;
1323  default:
1324  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1325  /* placate compiler, which doesn't know elog won't return */
1326  address.classId = InvalidOid;
1327  address.objectId = InvalidOid;
1328  address.objectSubId = 0;
1329  }
1330 
1331  return address;
1332 }
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5554
Oid get_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:183
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1426
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:3140
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:158
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:704
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:681
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition: lsyscache.c:3625
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition: lsyscache.c:3675
Oid ParameterAclLookup(const char *parameter, bool missing_ok)
const char * name

References ObjectAddress::classId, elog, ERROR, get_am_oid(), get_database_oid(), get_event_trigger_oid(), get_extension_oid(), get_foreign_data_wrapper_oid(), get_foreign_server_oid(), get_language_oid(), get_namespace_oid(), get_publication_oid(), get_role_oid(), get_subscription_oid(), get_tablespace_oid(), InvalidOid, name, OBJECT_ACCESS_METHOD, OBJECT_DATABASE, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_LANGUAGE, OBJECT_PARAMETER_ACL, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_SCHEMA, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, ObjectAddress::objectId, ObjectAddress::objectSubId, ParameterAclLookup(), and strVal.

Referenced by get_object_address().

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1797 of file objectaddress.c.

1798 {
1799  ObjectAddress address;
1800  Oid userid;
1801  char *username;
1802  char *servername;
1803  ForeignServer *server;
1804  HeapTuple tp;
1805 
1806  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1807 
1808  /* fetch string names from input lists, for error messages */
1809  username = strVal(linitial(object));
1810  servername = strVal(lsecond(object));
1811 
1812  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1813  if (strcmp(username, "public") == 0)
1814  userid = InvalidOid;
1815  else
1816  {
1817  tp = SearchSysCache1(AUTHNAME,
1819  if (!HeapTupleIsValid(tp))
1820  {
1821  if (!missing_ok)
1822  ereport(ERROR,
1823  (errcode(ERRCODE_UNDEFINED_OBJECT),
1824  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1825  username, servername)));
1826  return address;
1827  }
1828  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1829  ReleaseSysCache(tp);
1830  }
1831 
1832  /* Now look up the pg_user_mapping tuple */
1833  server = GetForeignServerByName(servername, true);
1834  if (!server)
1835  {
1836  if (!missing_ok)
1837  ereport(ERROR,
1838  (errcode(ERRCODE_UNDEFINED_OBJECT),
1839  errmsg("server \"%s\" does not exist", servername)));
1840  return address;
1841  }
1842  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1843  ObjectIdGetDatum(userid),
1844  ObjectIdGetDatum(server->serverid));
1845  if (!HeapTupleIsValid(tp))
1846  {
1847  if (!missing_ok)
1848  ereport(ERROR,
1849  (errcode(ERRCODE_UNDEFINED_OBJECT),
1850  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1851  username, servername)));
1852  return address;
1853  }
1854 
1855  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1856 
1857  ReleaseSysCache(tp);
1858 
1859  return address;
1860 }
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:182
FormData_pg_user_mapping * Form_pg_user_mapping
Oid serverid
Definition: foreign.h:36
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:232

References CStringGetDatum(), ereport, errcode(), errmsg(), ERROR, GetForeignServerByName(), GETSTRUCT, HeapTupleIsValid, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), SearchSysCache2(), ForeignServer::serverid, strVal, and username.

Referenced by get_object_address().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2689 of file objectaddress.c.

2690 {
2691  const ObjectPropertyType *prop = get_object_property_data(class_id);
2692 
2693  return prop->attnum_acl;
2694 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

References ObjectPropertyType::attnum_acl, and get_object_property_data().

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

◆ get_object_attnum_name()

AttrNumber get_object_attnum_name ( Oid  class_id)

◆ get_object_attnum_namespace()

◆ get_object_attnum_oid()

AttrNumber get_object_attnum_oid ( Oid  class_id)

◆ get_object_attnum_owner()

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2649 of file objectaddress.c.

2650 {
2651  const ObjectPropertyType *prop = get_object_property_data(class_id);
2652 
2653  return prop->name_catcache_id;
2654 }

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2722 of file objectaddress.c.

2723 {
2724  const ObjectPropertyType *prop = get_object_property_data(class_id);
2725 
2726  return prop->is_nsp_name_unique;
2727 }

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2569 of file objectaddress.c.

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

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

Referenced by RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2633 of file objectaddress.c.

2634 {
2635  const ObjectPropertyType *prop = get_object_property_data(class_id);
2636 
2637  return prop->oid_index_oid;
2638 }

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), get_catalog_object_by_oid(), and object_ownercheck().

◆ get_object_property_data()

static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2751 of file objectaddress.c.

2752 {
2753  static const ObjectPropertyType *prop_last = NULL;
2754  int index;
2755 
2756  /*
2757  * A shortcut to speed up multiple consecutive lookups of a particular
2758  * object class.
2759  */
2760  if (prop_last && prop_last->class_oid == class_id)
2761  return prop_last;
2762 
2763  for (index = 0; index < lengthof(ObjectProperty); index++)
2764  {
2765  if (ObjectProperty[index].class_oid == class_id)
2766  {
2767  prop_last = &ObjectProperty[index];
2768  return &ObjectProperty[index];
2769  }
2770  }
2771 
2772  ereport(ERROR,
2773  (errmsg_internal("unrecognized class ID: %u", class_id)));
2774 
2775  return NULL; /* keep MSC compiler happy */
2776 }
#define lengthof(array)
Definition: c.h:742
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1157
static const ObjectPropertyType ObjectProperty[]
Definition: type.h:96

References ObjectPropertyType::class_oid, ereport, errmsg_internal(), ERROR, lengthof, and ObjectProperty.

Referenced by get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_attnum_owner(), get_object_catcache_name(), get_object_catcache_oid(), get_object_class_descr(), get_object_namensp_unique(), get_object_namespace(), get_object_oid_index(), and get_object_type().

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2704 of file objectaddress.c.

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

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

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

◆ get_relation_by_qualified_name()

static ObjectAddress get_relation_by_qualified_name ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1338 of file objectaddress.c.

1341 {
1342  Relation relation;
1343  ObjectAddress address;
1344 
1345  address.classId = RelationRelationId;
1346  address.objectId = InvalidOid;
1347  address.objectSubId = 0;
1348 
1350  lockmode, missing_ok);
1351  if (!relation)
1352  return address;
1353 
1354  switch (objtype)
1355  {
1356  case OBJECT_INDEX:
1357  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1358  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1359  ereport(ERROR,
1360  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1361  errmsg("\"%s\" is not an index",
1362  RelationGetRelationName(relation))));
1363  break;
1364  case OBJECT_SEQUENCE:
1365  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1366  ereport(ERROR,
1367  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1368  errmsg("\"%s\" is not a sequence",
1369  RelationGetRelationName(relation))));
1370  break;
1371  case OBJECT_TABLE:
1372  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1373  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1374  ereport(ERROR,
1375  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1376  errmsg("\"%s\" is not a table",
1377  RelationGetRelationName(relation))));
1378  break;
1379  case OBJECT_VIEW:
1380  if (relation->rd_rel->relkind != RELKIND_VIEW)
1381  ereport(ERROR,
1382  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1383  errmsg("\"%s\" is not a view",
1384  RelationGetRelationName(relation))));
1385  break;
1386  case OBJECT_MATVIEW:
1387  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1388  ereport(ERROR,
1389  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1390  errmsg("\"%s\" is not a materialized view",
1391  RelationGetRelationName(relation))));
1392  break;
1393  case OBJECT_FOREIGN_TABLE:
1394  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1395  ereport(ERROR,
1396  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1397  errmsg("\"%s\" is not a foreign table",
1398  RelationGetRelationName(relation))));
1399  break;
1400  default:
1401  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1402  break;
1403  }
1404 
1405  /* Done. */
1406  address.objectId = RelationGetRelid(relation);
1407  *relp = relation;
1408 
1409  return address;
1410 }
Form_pg_class rd_rel
Definition: rel.h:111

References ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, InvalidOid, makeRangeVarFromNameList(), OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, RelationData::rd_rel, relation_openrv_extended(), RelationGetRelationName, and RelationGetRelid.

Referenced by get_object_address().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 6147 of file objectaddress.c.

6148 {
6149  switch (relkind)
6150  {
6151  case RELKIND_RELATION:
6152  case RELKIND_PARTITIONED_TABLE:
6153  return OBJECT_TABLE;
6154  case RELKIND_INDEX:
6155  case RELKIND_PARTITIONED_INDEX:
6156  return OBJECT_INDEX;
6157  case RELKIND_SEQUENCE:
6158  return OBJECT_SEQUENCE;
6159  case RELKIND_VIEW:
6160  return OBJECT_VIEW;
6161  case RELKIND_MATVIEW:
6162  return OBJECT_MATVIEW;
6163  case RELKIND_FOREIGN_TABLE:
6164  return OBJECT_FOREIGN_TABLE;
6165  case RELKIND_TOASTVALUE:
6166  return OBJECT_TABLE;
6167  default:
6168  /* Per above, don't raise an error */
6169  return OBJECT_TABLE;
6170  }
6171 }

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

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

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid,
bool  missing_ok 
)
static

Definition at line 4715 of file objectaddress.c.

4716 {
4717  Relation constrRel;
4718  HeapTuple constrTup;
4719  Form_pg_constraint constrForm;
4720 
4721  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4722  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4723  constroid);
4724  if (!HeapTupleIsValid(constrTup))
4725  {
4726  if (!missing_ok)
4727  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4728 
4729  table_close(constrRel, AccessShareLock);
4730 
4731  /* fallback to "constraint" for an undefined object */
4732  appendStringInfoString(buffer, "constraint");
4733  return;
4734  }
4735 
4736  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4737 
4738  if (OidIsValid(constrForm->conrelid))
4739  appendStringInfoString(buffer, "table constraint");
4740  else if (OidIsValid(constrForm->contypid))
4741  appendStringInfoString(buffer, "domain constraint");
4742  else
4743  elog(ERROR, "invalid constraint %u", constrForm->oid);
4744 
4745  table_close(constrRel, AccessShareLock);
4746 }
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:179
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References AccessShareLock, appendStringInfoString(), elog, ERROR, get_catalog_object_by_oid(), GETSTRUCT, HeapTupleIsValid, OidIsValid, table_close(), and table_open().

Referenced by getObjectTypeDescription().

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2883 of file objectaddress.c.

2884 {
2885  StringInfoData buffer;
2886 
2887  initStringInfo(&buffer);
2888 
2889  switch (object->classId)
2890  {
2891  case RelationRelationId:
2892  if (object->objectSubId == 0)
2893  getRelationDescription(&buffer, object->objectId, missing_ok);
2894  else
2895  {
2896  /* column, not whole relation */
2897  StringInfoData rel;
2898  char *attname = get_attname(object->objectId,
2899  object->objectSubId,
2900  missing_ok);
2901 
2902  if (!attname)
2903  break;
2904 
2905  initStringInfo(&rel);
2906  getRelationDescription(&rel, object->objectId, missing_ok);
2907  /* translator: second %s is, e.g., "table %s" */
2908  appendStringInfo(&buffer, _("column %s of %s"),
2909  attname, rel.data);
2910  pfree(rel.data);
2911  }
2912  break;
2913 
2914  case ProcedureRelationId:
2915  {
2917  char *proname = format_procedure_extended(object->objectId,
2918  flags);
2919 
2920  if (proname == NULL)
2921  break;
2922 
2923  appendStringInfo(&buffer, _("function %s"), proname);
2924  break;
2925  }
2926 
2927  case TypeRelationId:
2928  {
2930  char *typname = format_type_extended(object->objectId, -1,
2931  flags);
2932 
2933  if (typname == NULL)
2934  break;
2935 
2936  appendStringInfo(&buffer, _("type %s"), typname);
2937  break;
2938  }
2939 
2940  case CastRelationId:
2941  {
2942  Relation castDesc;
2943  ScanKeyData skey[1];
2944  SysScanDesc rcscan;
2945  HeapTuple tup;
2946  Form_pg_cast castForm;
2947 
2948  castDesc = table_open(CastRelationId, AccessShareLock);
2949 
2950  ScanKeyInit(&skey[0],
2951  Anum_pg_cast_oid,
2952  BTEqualStrategyNumber, F_OIDEQ,
2953  ObjectIdGetDatum(object->objectId));
2954 
2955  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2956  NULL, 1, skey);
2957 
2958  tup = systable_getnext(rcscan);
2959 
2960  if (!HeapTupleIsValid(tup))
2961  {
2962  if (!missing_ok)
2963  elog(ERROR, "could not find tuple for cast %u",
2964  object->objectId);
2965 
2966  systable_endscan(rcscan);
2967  table_close(castDesc, AccessShareLock);
2968  break;
2969  }
2970 
2971  castForm = (Form_pg_cast) GETSTRUCT(tup);
2972 
2973  appendStringInfo(&buffer, _("cast from %s to %s"),
2974  format_type_be(castForm->castsource),
2975  format_type_be(castForm->casttarget));
2976 
2977  systable_endscan(rcscan);
2978  table_close(castDesc, AccessShareLock);
2979  break;
2980  }
2981 
2982  case CollationRelationId:
2983  {
2984  HeapTuple collTup;
2985  Form_pg_collation coll;
2986  char *nspname;
2987 
2988  collTup = SearchSysCache1(COLLOID,
2989  ObjectIdGetDatum(object->objectId));
2990  if (!HeapTupleIsValid(collTup))
2991  {
2992  if (!missing_ok)
2993  elog(ERROR, "cache lookup failed for collation %u",
2994  object->objectId);
2995  break;
2996  }
2997 
2998  coll = (Form_pg_collation) GETSTRUCT(collTup);
2999 
3000  /* Qualify the name if not visible in search path */
3001  if (CollationIsVisible(object->objectId))
3002  nspname = NULL;
3003  else
3004  nspname = get_namespace_name(coll->collnamespace);
3005 
3006  appendStringInfo(&buffer, _("collation %s"),
3008  NameStr(coll->collname)));
3009  ReleaseSysCache(collTup);
3010  break;
3011  }
3012 
3013  case ConstraintRelationId:
3014  {
3015  HeapTuple conTup;
3016  Form_pg_constraint con;
3017 
3018  conTup = SearchSysCache1(CONSTROID,
3019  ObjectIdGetDatum(object->objectId));
3020  if (!HeapTupleIsValid(conTup))
3021  {
3022  if (!missing_ok)
3023  elog(ERROR, "cache lookup failed for constraint %u",
3024  object->objectId);
3025  break;
3026  }
3027 
3028  con = (Form_pg_constraint) GETSTRUCT(conTup);
3029 
3030  if (OidIsValid(con->conrelid))
3031  {
3032  StringInfoData rel;
3033 
3034  initStringInfo(&rel);
3035  getRelationDescription(&rel, con->conrelid, false);
3036  /* translator: second %s is, e.g., "table %s" */
3037  appendStringInfo(&buffer, _("constraint %s on %s"),
3038  NameStr(con->conname), rel.data);
3039  pfree(rel.data);
3040  }
3041  else
3042  {
3043  appendStringInfo(&buffer, _("constraint %s"),
3044  NameStr(con->conname));
3045  }
3046 
3047  ReleaseSysCache(conTup);
3048  break;
3049  }
3050 
3051  case ConversionRelationId:
3052  {
3053  HeapTuple conTup;
3054  Form_pg_conversion conv;
3055  char *nspname;
3056 
3057  conTup = SearchSysCache1(CONVOID,
3058  ObjectIdGetDatum(object->objectId));
3059  if (!HeapTupleIsValid(conTup))
3060  {
3061  if (!missing_ok)
3062  elog(ERROR, "cache lookup failed for conversion %u",
3063  object->objectId);
3064  break;
3065  }
3066 
3067  conv = (Form_pg_conversion) GETSTRUCT(conTup);
3068 
3069  /* Qualify the name if not visible in search path */
3070  if (ConversionIsVisible(object->objectId))
3071  nspname = NULL;
3072  else
3073  nspname = get_namespace_name(conv->connamespace);
3074 
3075  appendStringInfo(&buffer, _("conversion %s"),
3077  NameStr(conv->conname)));
3078  ReleaseSysCache(conTup);
3079  break;
3080  }
3081 
3082  case AttrDefaultRelationId:
3083  {
3084  ObjectAddress colobject;
3085 
3086  colobject = GetAttrDefaultColumnAddress(object->objectId);
3087 
3088  if (!OidIsValid(colobject.objectId))
3089  {
3090  if (!missing_ok)
3091  elog(ERROR, "could not find tuple for attrdef %u",
3092  object->objectId);
3093  break;
3094  }
3095 
3096  /* translator: %s is typically "column %s of table %s" */
3097  appendStringInfo(&buffer, _("default value for %s"),
3098  getObjectDescription(&colobject, false));
3099  break;
3100  }
3101 
3102  case LanguageRelationId:
3103  {
3104  char *langname = get_language_name(object->objectId,
3105  missing_ok);
3106 
3107  if (langname)
3108  appendStringInfo(&buffer, _("language %s"),
3109  get_language_name(object->objectId, false));
3110  break;
3111  }
3112 
3113  case LargeObjectRelationId:
3114  if (!LargeObjectExists(object->objectId))
3115  break;
3116  appendStringInfo(&buffer, _("large object %u"),
3117  object->objectId);
3118  break;
3119 
3120  case OperatorRelationId:
3121  {
3123  char *oprname = format_operator_extended(object->objectId,
3124  flags);
3125 
3126  if (oprname == NULL)
3127  break;
3128 
3129  appendStringInfo(&buffer, _("operator %s"), oprname);
3130  break;
3131  }
3132 
3133  case OperatorClassRelationId:
3134  {
3135  HeapTuple opcTup;
3136  Form_pg_opclass opcForm;
3137  HeapTuple amTup;
3138  Form_pg_am amForm;
3139  char *nspname;
3140 
3141  opcTup = SearchSysCache1(CLAOID,
3142  ObjectIdGetDatum(object->objectId));
3143  if (!HeapTupleIsValid(opcTup))
3144  {
3145  if (!missing_ok)
3146  elog(ERROR, "cache lookup failed for opclass %u",
3147  object->objectId);
3148  break;
3149  }
3150 
3151  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3152 
3153  amTup = SearchSysCache1(AMOID,
3154  ObjectIdGetDatum(opcForm->opcmethod));
3155  if (!HeapTupleIsValid(amTup))
3156  elog(ERROR, "cache lookup failed for access method %u",
3157  opcForm->opcmethod);
3158  amForm = (Form_pg_am) GETSTRUCT(amTup);
3159 
3160  /* Qualify the name if not visible in search path */
3161  if (OpclassIsVisible(object->objectId))
3162  nspname = NULL;
3163  else
3164  nspname = get_namespace_name(opcForm->opcnamespace);
3165 
3166  appendStringInfo(&buffer, _("operator class %s for access method %s"),
3168  NameStr(opcForm->opcname)),
3169  NameStr(amForm->amname));
3170 
3171  ReleaseSysCache(amTup);
3172  ReleaseSysCache(opcTup);
3173  break;
3174  }
3175 
3176  case OperatorFamilyRelationId:
3177  getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3178  break;
3179 
3180  case AccessMethodRelationId:
3181  {
3182  HeapTuple tup;
3183 
3184  tup = SearchSysCache1(AMOID,
3185  ObjectIdGetDatum(object->objectId));
3186  if (!HeapTupleIsValid(tup))
3187  {
3188  if (!missing_ok)
3189  elog(ERROR, "cache lookup failed for access method %u",
3190  object->objectId);
3191  break;
3192  }
3193 
3194  appendStringInfo(&buffer, _("access method %s"),
3195  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3196  ReleaseSysCache(tup);
3197  break;
3198  }
3199 
3200  case AccessMethodOperatorRelationId:
3201  {
3202  Relation amopDesc;
3203  HeapTuple tup;
3204  ScanKeyData skey[1];
3205  SysScanDesc amscan;
3206  Form_pg_amop amopForm;
3207  StringInfoData opfam;
3208 
3209  amopDesc = table_open(AccessMethodOperatorRelationId,
3210  AccessShareLock);
3211 
3212  ScanKeyInit(&skey[0],
3213  Anum_pg_amop_oid,
3214  BTEqualStrategyNumber, F_OIDEQ,
3215  ObjectIdGetDatum(object->objectId));
3216 
3217  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3218  NULL, 1, skey);
3219 
3220  tup = systable_getnext(amscan);
3221 
3222  if (!HeapTupleIsValid(tup))
3223  {
3224  if (!missing_ok)
3225  elog(ERROR, "could not find tuple for amop entry %u",
3226  object->objectId);
3227 
3228  systable_endscan(amscan);
3229  table_close(amopDesc, AccessShareLock);
3230  break;
3231  }
3232 
3233  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3234 
3235  initStringInfo(&opfam);
3236  getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3237 
3238  /*
3239  * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3240  * completely if the type links are dangling, which is a form
3241  * of catalog corruption that could occur due to old bugs.
3242  */
3243 
3244  /*------
3245  translator: %d is the operator strategy (a number), the
3246  first two %s's are data type names, the third %s is the
3247  description of the operator family, and the last %s is the
3248  textual form of the operator with arguments. */
3249  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3250  amopForm->amopstrategy,
3251  format_type_extended(amopForm->amoplefttype,
3253  format_type_extended(amopForm->amoprighttype,
3255  opfam.data,
3256  format_operator(amopForm->amopopr));
3257 
3258  pfree(opfam.data);
3259 
3260  systable_endscan(amscan);
3261  table_close(amopDesc, AccessShareLock);
3262  break;
3263  }
3264 
3265  case AccessMethodProcedureRelationId:
3266  {
3267  Relation amprocDesc;
3268  ScanKeyData skey[1];
3269  SysScanDesc amscan;
3270  HeapTuple tup;
3271  Form_pg_amproc amprocForm;
3272  StringInfoData opfam;
3273 
3274  amprocDesc = table_open(AccessMethodProcedureRelationId,
3275  AccessShareLock);
3276 
3277  ScanKeyInit(&skey[0],
3278  Anum_pg_amproc_oid,
3279  BTEqualStrategyNumber, F_OIDEQ,
3280  ObjectIdGetDatum(object->objectId));
3281 
3282  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3283  NULL, 1, skey);
3284 
3285  tup = systable_getnext(amscan);
3286 
3287  if (!HeapTupleIsValid(tup))
3288  {
3289  if (!missing_ok)
3290  elog(ERROR, "could not find tuple for amproc entry %u",
3291  object->objectId);
3292 
3293  systable_endscan(amscan);
3294  table_close(amprocDesc, AccessShareLock);
3295  break;
3296  }
3297 
3298  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3299 
3300  initStringInfo(&opfam);
3301  getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3302 
3303  /*
3304  * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3305  * completely if the type links are dangling, which is a form
3306  * of catalog corruption that could occur due to old bugs.
3307  */
3308 
3309  /*------
3310  translator: %d is the function number, the first two %s's
3311  are data type names, the third %s is the description of the
3312  operator family, and the last %s is the textual form of the
3313  function with arguments. */
3314  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3315  amprocForm->amprocnum,
3316  format_type_extended(amprocForm->amproclefttype,
3318  format_type_extended(amprocForm->amprocrighttype,
3320  opfam.data,
3321  format_procedure(amprocForm->amproc));
3322 
3323  pfree(opfam.data);
3324 
3325  systable_endscan(amscan);
3326  table_close(amprocDesc, AccessShareLock);
3327  break;
3328  }
3329 
3330  case RewriteRelationId:
3331  {
3332  Relation ruleDesc;
3333  ScanKeyData skey[1];
3334  SysScanDesc rcscan;
3335  HeapTuple tup;
3337  StringInfoData rel;
3338 
3339  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3340 
3341  ScanKeyInit(&skey[0],
3342  Anum_pg_rewrite_oid,
3343  BTEqualStrategyNumber, F_OIDEQ,
3344  ObjectIdGetDatum(object->objectId));
3345 
3346  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3347  NULL, 1, skey);
3348 
3349  tup = systable_getnext(rcscan);
3350 
3351  if (!HeapTupleIsValid(tup))
3352  {
3353  if (!missing_ok)
3354  elog(ERROR, "could not find tuple for rule %u",
3355  object->objectId);
3356 
3357  systable_endscan(rcscan);
3358  table_close(ruleDesc, AccessShareLock);
3359  break;
3360  }
3361 
3362  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3363 
3364  initStringInfo(&rel);
3365  getRelationDescription(&rel, rule->ev_class, false);
3366 
3367  /* translator: second %s is, e.g., "table %s" */
3368  appendStringInfo(&buffer, _("rule %s on %s"),
3369  NameStr(rule->rulename), rel.data);
3370  pfree(rel.data);
3371  systable_endscan(rcscan);
3372  table_close(ruleDesc, AccessShareLock);
3373  break;
3374  }
3375 
3376  case TriggerRelationId:
3377  {
3378  Relation trigDesc;
3379  ScanKeyData skey[1];
3380  SysScanDesc tgscan;
3381  HeapTuple tup;
3382  Form_pg_trigger trig;
3383  StringInfoData rel;
3384 
3385  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3386 
3387  ScanKeyInit(&skey[0],
3388  Anum_pg_trigger_oid,
3389  BTEqualStrategyNumber, F_OIDEQ,
3390  ObjectIdGetDatum(object->objectId));
3391 
3392  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3393  NULL, 1, skey);
3394 
3395  tup = systable_getnext(tgscan);
3396 
3397  if (!HeapTupleIsValid(tup))
3398  {
3399  if (!missing_ok)
3400  elog(ERROR, "could not find tuple for trigger %u",
3401  object->objectId);
3402 
3403  systable_endscan(tgscan);
3404  table_close(trigDesc, AccessShareLock);
3405  break;
3406  }
3407 
3408  trig = (Form_pg_trigger) GETSTRUCT(tup);
3409 
3410  initStringInfo(&rel);
3411  getRelationDescription(&rel, trig->tgrelid, false);
3412 
3413  /* translator: second %s is, e.g., "table %s" */
3414  appendStringInfo(&buffer, _("trigger %s on %s"),
3415  NameStr(trig->tgname), rel.data);
3416  pfree(rel.data);
3417  systable_endscan(tgscan);
3418  table_close(trigDesc, AccessShareLock);
3419  break;
3420  }
3421 
3422  case NamespaceRelationId:
3423  {
3424  char *nspname;
3425 
3426  nspname = get_namespace_name(object->objectId);
3427  if (!nspname)
3428  {
3429  if (!missing_ok)
3430  elog(ERROR, "cache lookup failed for namespace %u",
3431  object->objectId);
3432  break;
3433  }
3434  appendStringInfo(&buffer, _("schema %s"), nspname);
3435  break;
3436  }
3437 
3438  case StatisticExtRelationId:
3439  {
3440  HeapTuple stxTup;
3441  Form_pg_statistic_ext stxForm;
3442  char *nspname;
3443 
3444  stxTup = SearchSysCache1(STATEXTOID,
3445  ObjectIdGetDatum(object->objectId));
3446  if (!HeapTupleIsValid(stxTup))
3447  {
3448  if (!missing_ok)
3449  elog(ERROR, "could not find tuple for statistics object %u",
3450  object->objectId);
3451  break;
3452  }
3453 
3454  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3455 
3456  /* Qualify the name if not visible in search path */
3457  if (StatisticsObjIsVisible(object->objectId))
3458  nspname = NULL;
3459  else
3460  nspname = get_namespace_name(stxForm->stxnamespace);
3461 
3462  appendStringInfo(&buffer, _("statistics object %s"),
3464  NameStr(stxForm->stxname)));
3465 
3466  ReleaseSysCache(stxTup);
3467  break;
3468  }
3469 
3470  case TSParserRelationId:
3471  {
3472  HeapTuple tup;
3473  Form_pg_ts_parser prsForm;
3474  char *nspname;
3475 
3476  tup = SearchSysCache1(TSPARSEROID,
3477  ObjectIdGetDatum(object->objectId));
3478  if (!HeapTupleIsValid(tup))
3479  {
3480  if (!missing_ok)
3481  elog(ERROR, "cache lookup failed for text search parser %u",
3482  object->objectId);
3483  break;
3484  }
3485  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3486 
3487  /* Qualify the name if not visible in search path */
3488  if (TSParserIsVisible(object->objectId))
3489  nspname = NULL;
3490  else
3491  nspname = get_namespace_name(prsForm->prsnamespace);
3492 
3493  appendStringInfo(&buffer, _("text search parser %s"),
3495  NameStr(prsForm->prsname)));
3496  ReleaseSysCache(tup);
3497  break;
3498  }
3499 
3500  case TSDictionaryRelationId:
3501  {
3502  HeapTuple tup;
3503  Form_pg_ts_dict dictForm;
3504  char *nspname;
3505 
3506  tup = SearchSysCache1(TSDICTOID,
3507  ObjectIdGetDatum(object->objectId));
3508  if (!HeapTupleIsValid(tup))
3509  {
3510  if (!missing_ok)
3511  elog(ERROR, "cache lookup failed for text search dictionary %u",
3512  object->objectId);
3513  break;
3514  }
3515 
3516  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3517 
3518  /* Qualify the name if not visible in search path */
3519  if (TSDictionaryIsVisible(object->objectId))
3520  nspname = NULL;
3521  else
3522  nspname = get_namespace_name(dictForm->dictnamespace);
3523 
3524  appendStringInfo(&buffer, _("text search dictionary %s"),
3526  NameStr(dictForm->dictname)));
3527  ReleaseSysCache(tup);
3528  break;
3529  }
3530 
3531  case TSTemplateRelationId:
3532  {
3533  HeapTuple tup;
3534  Form_pg_ts_template tmplForm;
3535  char *nspname;
3536 
3537  tup = SearchSysCache1(TSTEMPLATEOID,
3538  ObjectIdGetDatum(object->objectId));
3539  if (!HeapTupleIsValid(tup))
3540  {
3541  if (!missing_ok)
3542  elog(ERROR, "cache lookup failed for text search template %u",
3543  object->objectId);
3544  break;
3545  }
3546 
3547  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3548 
3549  /* Qualify the name if not visible in search path */
3550  if (TSTemplateIsVisible(object->objectId))
3551  nspname = NULL;
3552  else
3553  nspname = get_namespace_name(tmplForm->tmplnamespace);
3554 
3555  appendStringInfo(&buffer, _("text search template %s"),
3557  NameStr(tmplForm->tmplname)));
3558  ReleaseSysCache(tup);
3559  break;
3560  }
3561 
3562  case TSConfigRelationId:
3563  {
3564  HeapTuple tup;
3565  Form_pg_ts_config cfgForm;
3566  char *nspname;
3567 
3568  tup = SearchSysCache1(TSCONFIGOID,
3569  ObjectIdGetDatum(object->objectId));
3570  if (!HeapTupleIsValid(tup))
3571  {
3572  if (!missing_ok)
3573  elog(ERROR, "cache lookup failed for text search configuration %u",
3574  object->objectId);
3575  break;
3576  }
3577 
3578  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3579 
3580  /* Qualify the name if not visible in search path */
3581  if (TSConfigIsVisible(object->objectId))
3582  nspname = NULL;
3583  else
3584  nspname = get_namespace_name(cfgForm->cfgnamespace);
3585 
3586  appendStringInfo(&buffer, _("text search configuration %s"),
3588  NameStr(cfgForm->cfgname)));
3589  ReleaseSysCache(tup);
3590  break;
3591  }
3592 
3593  case AuthIdRelationId:
3594  {
3595  char *username = GetUserNameFromId(object->objectId,
3596  missing_ok);
3597 
3598  if (username)
3599  appendStringInfo(&buffer, _("role %s"), username);
3600  break;
3601  }
3602 
3603  case AuthMemRelationId:
3604  {
3605  Relation amDesc;
3606  ScanKeyData skey[1];
3607  SysScanDesc rcscan;
3608  HeapTuple tup;
3609  Form_pg_auth_members amForm;
3610 
3611  amDesc = table_open(AuthMemRelationId, AccessShareLock);
3612 
3613  ScanKeyInit(&skey[0],
3614  Anum_pg_auth_members_oid,
3615  BTEqualStrategyNumber, F_OIDEQ,
3616  ObjectIdGetDatum(object->objectId));
3617 
3618  rcscan = systable_beginscan(amDesc, AuthMemOidIndexId, true,
3619  NULL, 1, skey);
3620 
3621  tup = systable_getnext(rcscan);
3622 
3623  if (!HeapTupleIsValid(tup))
3624  {
3625  if (!missing_ok)
3626  elog(ERROR, "could not find tuple for role membership %u",
3627  object->objectId);
3628 
3629  systable_endscan(rcscan);
3630  table_close(amDesc, AccessShareLock);
3631  break;
3632  }
3633 
3634  amForm = (Form_pg_auth_members) GETSTRUCT(tup);
3635 
3636  appendStringInfo(&buffer, _("membership of role %s in role %s"),
3637  GetUserNameFromId(amForm->member, false),
3638  GetUserNameFromId(amForm->roleid, false));
3639 
3640  systable_endscan(rcscan);
3641  table_close(amDesc, AccessShareLock);
3642  break;
3643  }
3644 
3645  case DatabaseRelationId:
3646  {
3647  char *datname;
3648 
3649  datname = get_database_name(object->objectId);
3650  if (!datname)
3651  {
3652  if (!missing_ok)
3653  elog(ERROR, "cache lookup failed for database %u",
3654  object->objectId);
3655  break;
3656  }
3657  appendStringInfo(&buffer, _("database %s"), datname);
3658  break;
3659  }
3660 
3661  case TableSpaceRelationId:
3662  {
3663  char *tblspace;
3664 
3665  tblspace = get_tablespace_name(object->objectId);
3666  if (!tblspace)
3667  {
3668  if (!missing_ok)
3669  elog(ERROR, "cache lookup failed for tablespace %u",
3670  object->objectId);
3671  break;
3672  }
3673  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3674  break;
3675  }
3676 
3677  case ForeignDataWrapperRelationId:
3678  {
3679  ForeignDataWrapper *fdw;
3680 
3682  missing_ok);
3683  if (fdw)
3684  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3685  break;
3686  }
3687 
3688  case ForeignServerRelationId:
3689  {
3690  ForeignServer *srv;
3691 
3692  srv = GetForeignServerExtended(object->objectId, missing_ok);
3693  if (srv)
3694  appendStringInfo(&buffer, _("server %s"), srv->servername);
3695  break;
3696  }
3697 
3698  case UserMappingRelationId:
3699  {
3700  HeapTuple tup;
3701  Oid useid;
3702  char *usename;
3703  Form_pg_user_mapping umform;
3704  ForeignServer *srv;
3705 
3706  tup = SearchSysCache1(USERMAPPINGOID,
3707  ObjectIdGetDatum(object->objectId));
3708  if (!HeapTupleIsValid(tup))
3709  {
3710  if (!missing_ok)
3711  elog(ERROR, "cache lookup failed for user mapping %u",
3712  object->objectId);
3713  break;
3714  }
3715 
3716  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3717  useid = umform->umuser;
3718  srv = GetForeignServer(umform->umserver);
3719 
3720  ReleaseSysCache(tup);
3721 
3722  if (OidIsValid(useid))
3723  usename = GetUserNameFromId(useid, false);
3724  else
3725  usename = "public";
3726 
3727  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3728  srv->servername);
3729  break;
3730  }
3731 
3732  case DefaultAclRelationId:
3733  {
3734  Relation defaclrel;
3735  ScanKeyData skey[1];
3736  SysScanDesc rcscan;
3737  HeapTuple tup;
3738  Form_pg_default_acl defacl;
3739  char *rolename;
3740  char *nspname;
3741 
3742  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3743 
3744  ScanKeyInit(&skey[0],
3745  Anum_pg_default_acl_oid,
3746  BTEqualStrategyNumber, F_OIDEQ,
3747  ObjectIdGetDatum(object->objectId));
3748 
3749  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3750  true, NULL, 1, skey);
3751 
3752  tup = systable_getnext(rcscan);
3753 
3754  if (!HeapTupleIsValid(tup))
3755  {
3756  if (!missing_ok)
3757  elog(ERROR, "could not find tuple for default ACL %u",
3758  object->objectId);
3759 
3760  systable_endscan(rcscan);
3761  table_close(defaclrel, AccessShareLock);
3762  break;
3763  }
3764 
3765  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3766 
3767  rolename = GetUserNameFromId(defacl->defaclrole, false);
3768 
3769  if (OidIsValid(defacl->defaclnamespace))
3770  nspname = get_namespace_name(defacl->defaclnamespace);
3771  else
3772  nspname = NULL;
3773 
3774  switch (defacl->defaclobjtype)
3775  {
3776  case DEFACLOBJ_RELATION:
3777  if (nspname)
3778  appendStringInfo(&buffer,
3779  _("default privileges on new relations belonging to role %s in schema %s"),
3780  rolename, nspname);
3781  else
3782  appendStringInfo(&buffer,
3783  _("default privileges on new relations belonging to role %s"),
3784  rolename);
3785  break;
3786  case DEFACLOBJ_SEQUENCE:
3787  if (nspname)
3788  appendStringInfo(&buffer,
3789  _("default privileges on new sequences belonging to role %s in schema %s"),
3790  rolename, nspname);
3791  else
3792  appendStringInfo(&buffer,
3793  _("default privileges on new sequences belonging to role %s"),
3794  rolename);
3795  break;
3796  case DEFACLOBJ_FUNCTION:
3797  if (nspname)
3798  appendStringInfo(&buffer,
3799  _("default privileges on new functions belonging to role %s in schema %s"),
3800  rolename, nspname);
3801  else
3802  appendStringInfo(&buffer,
3803  _("default privileges on new functions belonging to role %s"),
3804  rolename);
3805  break;
3806  case DEFACLOBJ_TYPE:
3807  if (nspname)
3808  appendStringInfo(&buffer,
3809  _("default privileges on new types belonging to role %s in schema %s"),
3810  rolename, nspname);
3811  else
3812  appendStringInfo(&buffer,
3813  _("default privileges on new types belonging to role %s"),
3814  rolename);
3815  break;
3816  case DEFACLOBJ_NAMESPACE:
3817  Assert(!nspname);
3818  appendStringInfo(&buffer,
3819  _("default privileges on new schemas belonging to role %s"),
3820  rolename);
3821  break;
3822  default:
3823  /* shouldn't get here */
3824  if (nspname)
3825  appendStringInfo(&buffer,
3826  _("default privileges belonging to role %s in schema %s"),
3827  rolename, nspname);
3828  else
3829  appendStringInfo(&buffer,
3830  _("default privileges belonging to role %s"),
3831  rolename);
3832  break;
3833  }
3834 
3835  systable_endscan(rcscan);
3836  table_close(defaclrel, AccessShareLock);
3837  break;
3838  }
3839 
3840  case ExtensionRelationId:
3841  {
3842  char *extname;
3843 
3844  extname = get_extension_name(object->objectId);
3845  if (!extname)
3846  {
3847  if (!missing_ok)
3848  elog(ERROR, "cache lookup failed for extension %u",
3849  object->objectId);
3850  break;
3851  }
3852  appendStringInfo(&buffer, _("extension %s"), extname);
3853  break;
3854  }
3855 
3856  case EventTriggerRelationId:
3857  {
3858  HeapTuple tup;
3859 
3860  tup = SearchSysCache1(EVENTTRIGGEROID,
3861  ObjectIdGetDatum(object->objectId));
3862  if (!HeapTupleIsValid(tup))
3863  {
3864  if (!missing_ok)
3865  elog(ERROR, "cache lookup failed for event trigger %u",
3866  object->objectId);
3867  break;
3868  }
3869  appendStringInfo(&buffer, _("event trigger %s"),
3870  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3871  ReleaseSysCache(tup);
3872  break;
3873  }
3874 
3875  case ParameterAclRelationId:
3876  {
3877  HeapTuple tup;
3878  Datum nameDatum;
3879  char *parname;
3880 
3881  tup = SearchSysCache1(PARAMETERACLOID,
3882  ObjectIdGetDatum(object->objectId));
3883  if (!HeapTupleIsValid(tup))
3884  {
3885  if (!missing_ok)
3886  elog(ERROR, "cache lookup failed for parameter ACL %u",
3887  object->objectId);
3888  break;
3889  }
3890  nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
3891  Anum_pg_parameter_acl_parname);
3892  parname = TextDatumGetCString(nameDatum);
3893  appendStringInfo(&buffer, _("parameter %s"), parname);
3894  ReleaseSysCache(tup);
3895  break;
3896  }
3897 
3898  case PolicyRelationId:
3899  {
3900  Relation policy_rel;
3901  ScanKeyData skey[1];
3902  SysScanDesc sscan;
3903  HeapTuple tuple;
3904  Form_pg_policy form_policy;
3905  StringInfoData rel;
3906 
3907  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3908 
3909  ScanKeyInit(&skey[0],
3910  Anum_pg_policy_oid,
3911  BTEqualStrategyNumber, F_OIDEQ,
3912  ObjectIdGetDatum(object->objectId));
3913 
3914  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3915  true, NULL, 1, skey);
3916 
3917  tuple = systable_getnext(sscan);
3918 
3919  if (!HeapTupleIsValid(tuple))
3920  {
3921  if (!missing_ok)
3922  elog(ERROR, "could not find tuple for policy %u",
3923  object->objectId);
3924 
3925  systable_endscan(sscan);
3926  table_close(policy_rel, AccessShareLock);
3927  break;
3928  }
3929 
3930  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3931 
3932  initStringInfo(&rel);
3933  getRelationDescription(&rel, form_policy->polrelid, false);
3934 
3935  /* translator: second %s is, e.g., "table %s" */
3936  appendStringInfo(&buffer, _("policy %s on %s"),
3937  NameStr(form_policy->polname), rel.data);
3938  pfree(rel.data);
3939  systable_endscan(sscan);
3940  table_close(policy_rel, AccessShareLock);
3941  break;
3942  }
3943 
3944  case PublicationRelationId:
3945  {
3946  char *pubname = get_publication_name(object->objectId,
3947  missing_ok);
3948 
3949  if (pubname)
3950  appendStringInfo(&buffer, _("publication %s"), pubname);
3951  break;
3952  }
3953 
3954  case PublicationNamespaceRelationId:
3955  {
3956  char *pubname;
3957  char *nspname;
3958 
3959  if (!getPublicationSchemaInfo(object, missing_ok,
3960  &pubname, &nspname))
3961  break;
3962 
3963  appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
3964  nspname, pubname);
3965  pfree(pubname);
3966  pfree(nspname);
3967  break;
3968  }
3969 
3970  case PublicationRelRelationId:
3971  {
3972  HeapTuple tup;
3973  char *pubname;
3974  Form_pg_publication_rel prform;
3975  StringInfoData rel;
3976 
3977  tup = SearchSysCache1(PUBLICATIONREL,
3978  ObjectIdGetDatum(object->objectId));
3979  if (!HeapTupleIsValid(tup))
3980  {
3981  if (!missing_ok)
3982  elog(ERROR, "cache lookup failed for publication table %u",
3983  object->objectId);
3984  break;
3985  }
3986 
3987  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3988  pubname = get_publication_name(prform->prpubid, false);
3989 
3990  initStringInfo(&rel);
3991  getRelationDescription(&rel, prform->prrelid, false);
3992 
3993  /* translator: first %s is, e.g., "table %s" */
3994  appendStringInfo(&buffer, _("publication of %s in publication %s"),
3995  rel.data, pubname);
3996  pfree(rel.data);
3997  ReleaseSysCache(tup);
3998  break;
3999  }
4000 
4001  case SubscriptionRelationId:
4002  {
4003  char *subname = get_subscription_name(object->objectId,
4004  missing_ok);
4005 
4006  if (subname)
4007  appendStringInfo(&buffer, _("subscription %s"), subname);
4008  break;
4009  }
4010 
4011  case TransformRelationId:
4012  {
4013  HeapTuple trfTup;
4014  Form_pg_transform trfForm;
4015 
4016  trfTup = SearchSysCache1(TRFOID,
4017  ObjectIdGetDatum(object->objectId));
4018  if (!HeapTupleIsValid(trfTup))
4019  {
4020  if (!missing_ok)
4021  elog(ERROR, "could not find tuple for transform %u",
4022  object->objectId);
4023  break;
4024  }
4025 
4026  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
4027 
4028  appendStringInfo(&buffer, _("transform for %s language %s"),
4029  format_type_be(trfForm->trftype),
4030  get_language_name(trfForm->trflang, false));
4031 
4032  ReleaseSysCache(trfTup);
4033  break;
4034  }
4035 
4036  default:
4037  elog(ERROR, "unsupported object class: %u", object->classId);
4038  }
4039 
4040  /* an empty buffer is equivalent to no object found */
4041  if (buffer.len == 0)
4042  return NULL;
4043 
4044  return buffer.data;
4045 }
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1472
#define FORMAT_TYPE_ALLOW_INVALID
Definition: builtins.h:125
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:127
#define NameStr(name)
Definition: c.h:700
uint16 bits16
Definition: c.h:493
char * get_database_name(Oid dbid)
Definition: dbcommands.c:3187
#define _(x)
Definition: elog.c:90
char * get_extension_name(Oid ext_oid)
Definition: extension.c:180
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:123
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:49
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:111
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:112
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1161
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
char * get_publication_name(Oid pubid, bool missing_ok)
Definition: lsyscache.c:3645
char * get_subscription_name(Oid subid, bool missing_ok)
Definition: lsyscache.c:3695
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:827
void pfree(void *pointer)
Definition: mcxt.c:1521
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:3065
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2407
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2509
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:2154
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2774
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:3210
bool StatisticsObjIsVisible(Oid stxid)
Definition: namespace.c:2632
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2919
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
static bool getPublicationSchemaInfo(const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
Definition: pg_attrdef.c:381
FormData_pg_auth_members * Form_pg_auth_members
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:58
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
NameData datname
Definition: pg_database.h:35
FormData_pg_event_trigger * Form_pg_event_trigger
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:51
NameData proname
Definition: pg_proc.h:35
FormData_pg_publication_rel * Form_pg_publication_rel
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
FormData_pg_statistic_ext * Form_pg_statistic_ext
NameData subname
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:80
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_ts_template * Form_pg_ts_template
NameData typname
Definition: pg_type.h:41
uintptr_t Datum
Definition: postgres.h:64
char * format_operator(Oid operator_oid)
Definition: regproc.c:793
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:299
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:722
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:326
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:12952
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:94
void initStringInfo(StringInfo str)
Definition: stringinfo.c:56
char * fdwname
Definition: foreign.h:28
char * servername
Definition: foreign.h:39
Definition: localtime.c:73

References _, AccessShareLock, appendStringInfo(), Assert, attname, BTEqualStrategyNumber, ObjectAddress::classId, CollationIsVisible(), ConversionIsVisible(), StringInfoData::data, datname, elog, ERROR, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), FORMAT_TYPE_ALLOW_INVALID, format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, OpclassIsVisible(), pfree(), proname, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, StatisticsObjIsVisible(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typname, and username.

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4051 of file objectaddress.c.

4052 {
4053  ObjectAddress address;
4054 
4055  address.classId = classid;
4056  address.objectId = objid;
4057  address.objectSubId = 0;
4058 
4059  return getObjectDescription(&address, false);
4060 }

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4804 of file objectaddress.c.

4807 {
4808  StringInfoData buffer;
4809 
4810  initStringInfo(&buffer);
4811 
4812  /*
4813  * Make sure that both objname and objargs were passed, or none was; and
4814  * initialize them to empty lists. For objname this is useless because it
4815  * will be initialized in all cases inside the switch; but we do it anyway
4816  * so that we can test below that no branch leaves it unset.
4817  */
4818  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4819  if (objname)
4820  {
4821  *objname = NIL;
4822  *objargs = NIL;
4823  }
4824 
4825  switch (object->classId)
4826  {
4827  case RelationRelationId:
4828  {
4829  char *attr = NULL;
4830 
4831  /*
4832  * Check for the attribute first, so as if it is missing we
4833  * can skip the entire relation description.
4834  */
4835  if (object->objectSubId != 0)
4836  {
4837  attr = get_attname(object->objectId,
4838  object->objectSubId,
4839  missing_ok);
4840 
4841  if (missing_ok && attr == NULL)
4842  break;
4843  }
4844 
4845  getRelationIdentity(&buffer, object->objectId, objname,
4846  missing_ok);
4847  if (objname && *objname == NIL)
4848  break;
4849 
4850  if (attr)
4851  {
4852  appendStringInfo(&buffer, ".%s",
4853  quote_identifier(attr));
4854  if (objname)
4855  *objname = lappend(*objname, attr);
4856  }
4857  }
4858  break;
4859 
4860  case ProcedureRelationId:
4861  {
4863  char *proname = format_procedure_extended(object->objectId,
4864  flags);
4865 
4866  if (proname == NULL)
4867  break;
4868 
4869  appendStringInfoString(&buffer, proname);
4870  if (objname)
4871  format_procedure_parts(object->objectId, objname, objargs,
4872  missing_ok);
4873  break;
4874  }
4875 
4876  case TypeRelationId:
4877  {
4879  char *typeout;
4880 
4881  typeout = format_type_extended(object->objectId, -1, flags);
4882 
4883  if (typeout == NULL)
4884  break;
4885 
4886  appendStringInfoString(&buffer, typeout);
4887  if (objname)
4888  *objname = list_make1(typeout);
4889  }
4890  break;
4891 
4892  case CastRelationId:
4893  {
4894  Relation castRel;
4895  HeapTuple tup;
4896  Form_pg_cast castForm;
4897 
4898  castRel = table_open(CastRelationId, AccessShareLock);
4899 
4900  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4901  object->objectId);
4902 
4903  if (!HeapTupleIsValid(tup))
4904  {
4905  if (!missing_ok)
4906  elog(ERROR, "could not find tuple for cast %u",
4907  object->objectId);
4908 
4909  table_close(castRel, AccessShareLock);
4910  break;
4911  }
4912 
4913  castForm = (Form_pg_cast) GETSTRUCT(tup);
4914 
4915  appendStringInfo(&buffer, "(%s AS %s)",
4916  format_type_be_qualified(castForm->castsource),
4917  format_type_be_qualified(castForm->casttarget));
4918 
4919  if (objname)
4920  {
4921  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4922  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4923  }
4924 
4925  table_close(castRel, AccessShareLock);
4926  break;
4927  }
4928 
4929  case CollationRelationId:
4930  {
4931  HeapTuple collTup;
4932  Form_pg_collation coll;
4933  char *schema;
4934 
4935  collTup = SearchSysCache1(COLLOID,
4936  ObjectIdGetDatum(object->objectId));
4937  if (!HeapTupleIsValid(collTup))
4938  {
4939  if (!missing_ok)
4940  elog(ERROR, "cache lookup failed for collation %u",
4941  object->objectId);
4942  break;
4943  }
4944  coll = (Form_pg_collation) GETSTRUCT(collTup);
4945  schema = get_namespace_name_or_temp(coll->collnamespace);
4946  appendStringInfoString(&buffer,
4948  NameStr(coll->collname)));
4949  if (objname)
4950  *objname = list_make2(schema,
4951  pstrdup(NameStr(coll->collname)));
4952  ReleaseSysCache(collTup);
4953  break;
4954  }
4955 
4956  case ConstraintRelationId:
4957  {
4958  HeapTuple conTup;
4959  Form_pg_constraint con;
4960 
4961  conTup = SearchSysCache1(CONSTROID,
4962  ObjectIdGetDatum(object->objectId));
4963  if (!HeapTupleIsValid(conTup))
4964  {
4965  if (!missing_ok)
4966  elog(ERROR, "cache lookup failed for constraint %u",
4967  object->objectId);
4968  break;
4969  }
4970  con = (Form_pg_constraint) GETSTRUCT(conTup);
4971 
4972  if (OidIsValid(con->conrelid))
4973  {
4974  appendStringInfo(&buffer, "%s on ",
4975  quote_identifier(NameStr(con->conname)));
4976  getRelationIdentity(&buffer, con->conrelid, objname,
4977  false);
4978  if (objname)
4979  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4980  }
4981  else
4982  {
4983  ObjectAddress domain;
4984 
4985  Assert(OidIsValid(con->contypid));
4986  domain.classId = TypeRelationId;
4987  domain.objectId = con->contypid;
4988  domain.objectSubId = 0;
4989 
4990  appendStringInfo(&buffer, "%s on %s",
4991  quote_identifier(NameStr(con->conname)),
4992  getObjectIdentityParts(&domain, objname,
4993  objargs, false));
4994 
4995  if (objname)
4996  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4997  }
4998 
4999  ReleaseSysCache(conTup);
5000  break;
5001  }
5002 
5003  case ConversionRelationId:
5004  {
5005  HeapTuple conTup;
5006  Form_pg_conversion conForm;
5007  char *schema;
5008 
5009  conTup = SearchSysCache1(CONVOID,
5010  ObjectIdGetDatum(object->objectId));
5011  if (!HeapTupleIsValid(conTup))
5012  {
5013  if (!missing_ok)
5014  elog(ERROR, "cache lookup failed for conversion %u",
5015  object->objectId);
5016  break;
5017  }
5018  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
5019  schema = get_namespace_name_or_temp(conForm->connamespace);
5020  appendStringInfoString(&buffer,
5022  NameStr(conForm->conname)));
5023  if (objname)
5024  *objname = list_make2(schema,
5025  pstrdup(NameStr(conForm->conname)));
5026  ReleaseSysCache(conTup);
5027  break;
5028  }
5029 
5030  case AttrDefaultRelationId:
5031  {
5032  ObjectAddress colobject;
5033 
5034  colobject = GetAttrDefaultColumnAddress(object->objectId);
5035 
5036  if (!OidIsValid(colobject.objectId))
5037  {
5038  if (!missing_ok)
5039  elog(ERROR, "could not find tuple for attrdef %u",
5040  object->objectId);
5041  break;
5042  }
5043 
5044  appendStringInfo(&buffer, "for %s",
5045  getObjectIdentityParts(&colobject,
5046  objname, objargs,
5047  false));
5048  break;
5049  }
5050 
5051  case LanguageRelationId:
5052  {
5053  HeapTuple langTup;
5054  Form_pg_language langForm;
5055 
5056  langTup = SearchSysCache1(LANGOID,
5057  ObjectIdGetDatum(object->objectId));
5058  if (!HeapTupleIsValid(langTup))
5059  {
5060  if (!missing_ok)
5061  elog(ERROR, "cache lookup failed for language %u",
5062  object->objectId);
5063  break;
5064  }
5065  langForm = (Form_pg_language) GETSTRUCT(langTup);
5066  appendStringInfoString(&buffer,
5067  quote_identifier(NameStr(langForm->lanname)));
5068  if (objname)
5069  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5070  ReleaseSysCache(langTup);
5071  break;
5072  }
5073 
5074  case LargeObjectRelationId:
5075  if (!LargeObjectExists(object->objectId))
5076  break;
5077  appendStringInfo(&buffer, "%u",
5078  object->objectId);
5079  if (objname)
5080  *objname = list_make1(psprintf("%u", object->objectId));
5081  break;
5082 
5083  case OperatorRelationId:
5084  {
5086  char *oprname = format_operator_extended(object->objectId,
5087  flags);
5088 
5089  if (oprname == NULL)
5090  break;
5091 
5092  appendStringInfoString(&buffer, oprname);
5093  if (objname)
5094  format_operator_parts(object->objectId, objname, objargs, missing_ok);
5095  break;
5096  }
5097 
5098  case OperatorClassRelationId:
5099  {
5100  HeapTuple opcTup;
5101  Form_pg_opclass opcForm;
5102  HeapTuple amTup;
5103  Form_pg_am amForm;
5104  char *schema;
5105 
5106  opcTup = SearchSysCache1(CLAOID,
5107  ObjectIdGetDatum(object->objectId));
5108  if (!HeapTupleIsValid(opcTup))
5109  {
5110  if (!missing_ok)
5111  elog(ERROR, "cache lookup failed for opclass %u",
5112  object->objectId);
5113  break;
5114  }
5115  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
5116  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5117 
5118  amTup = SearchSysCache1(AMOID,
5119  ObjectIdGetDatum(opcForm->opcmethod));
5120  if (!HeapTupleIsValid(amTup))
5121  elog(ERROR, "cache lookup failed for access method %u",
5122  opcForm->opcmethod);
5123  amForm = (Form_pg_am) GETSTRUCT(amTup);
5124 
5125  appendStringInfo(&buffer, "%s USING %s",
5127  NameStr(opcForm->opcname)),
5128  quote_identifier(NameStr(amForm->amname)));
5129  if (objname)
5130  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5131  schema,
5132  pstrdup(NameStr(opcForm->opcname)));
5133 
5134  ReleaseSysCache(amTup);
5135  ReleaseSysCache(opcTup);
5136  break;
5137  }
5138 
5139  case OperatorFamilyRelationId:
5140  getOpFamilyIdentity(&buffer, object->objectId, objname,
5141  missing_ok);
5142  break;
5143 
5144  case AccessMethodRelationId:
5145  {
5146  char *amname;
5147 
5148  amname = get_am_name(object->objectId);
5149  if (!amname)
5150  {
5151  if (!missing_ok)
5152  elog(ERROR, "cache lookup failed for access method %u",
5153  object->objectId);
5154  break;
5155  }
5156  appendStringInfoString(&buffer, quote_identifier(amname));
5157  if (objname)
5158  *objname = list_make1(amname);
5159  }
5160  break;
5161 
5162  case AccessMethodOperatorRelationId:
5163  {
5164  Relation amopDesc;
5165  HeapTuple tup;
5166  ScanKeyData skey[1];
5167  SysScanDesc amscan;
5168  Form_pg_amop amopForm;
5169  StringInfoData opfam;
5170  char *ltype;
5171  char *rtype;
5172 
5173  amopDesc = table_open(AccessMethodOperatorRelationId,
5174  AccessShareLock);
5175 
5176  ScanKeyInit(&skey[0],
5177  Anum_pg_amop_oid,
5178  BTEqualStrategyNumber, F_OIDEQ,
5179  ObjectIdGetDatum(object->objectId));
5180 
5181  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
5182  NULL, 1, skey);
5183 
5184  tup = systable_getnext(amscan);
5185 
5186  if (!HeapTupleIsValid(tup))
5187  {
5188  if (!missing_ok)
5189  elog(ERROR, "could not find tuple for amop entry %u",
5190  object->objectId);
5191 
5192  systable_endscan(amscan);
5193  table_close(amopDesc, AccessShareLock);
5194  break;
5195  }
5196 
5197  amopForm = (Form_pg_amop) GETSTRUCT(tup);
5198 
5199  initStringInfo(&opfam);
5200  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5201  false);
5202 
5203  ltype = format_type_be_qualified(amopForm->amoplefttype);
5204  rtype = format_type_be_qualified(amopForm->amoprighttype);
5205 
5206  if (objname)
5207  {
5208  *objname = lappend(*objname,
5209  psprintf("%d", amopForm->amopstrategy));
5210  *objargs = list_make2(ltype, rtype);
5211  }
5212 
5213  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5214  amopForm->amopstrategy,
5215  ltype, rtype, opfam.data);
5216 
5217  pfree(opfam.data);
5218 
5219  systable_endscan(amscan);
5220  table_close(amopDesc, AccessShareLock);
5221  break;
5222  }
5223 
5224  case AccessMethodProcedureRelationId:
5225  {
5226  Relation amprocDesc;
5227  ScanKeyData skey[1];
5228  SysScanDesc amscan;
5229  HeapTuple tup;
5230  Form_pg_amproc amprocForm;
5231  StringInfoData opfam;
5232  char *ltype;
5233  char *rtype;
5234 
5235  amprocDesc = table_open(AccessMethodProcedureRelationId,
5236  AccessShareLock);
5237 
5238  ScanKeyInit(&skey[0],
5239  Anum_pg_amproc_oid,
5240  BTEqualStrategyNumber, F_OIDEQ,
5241  ObjectIdGetDatum(object->objectId));
5242 
5243  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
5244  NULL, 1, skey);
5245 
5246  tup = systable_getnext(amscan);
5247 
5248  if (!HeapTupleIsValid(tup))
5249  {
5250  if (!missing_ok)
5251  elog(ERROR, "could not find tuple for amproc entry %u",
5252  object->objectId);
5253 
5254  systable_endscan(amscan);
5255  table_close(amprocDesc, AccessShareLock);
5256  break;
5257  }
5258 
5259  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
5260 
5261  initStringInfo(&opfam);
5262  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5263  false);
5264 
5265  ltype = format_type_be_qualified(amprocForm->amproclefttype);
5266  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5267 
5268  if (objname)
5269  {
5270  *objname = lappend(*objname,
5271  psprintf("%d", amprocForm->amprocnum));
5272  *objargs = list_make2(ltype, rtype);
5273  }
5274 
5275  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5276  amprocForm->amprocnum,
5277  ltype, rtype, opfam.data);
5278 
5279  pfree(opfam.data);
5280 
5281  systable_endscan(amscan);
5282  table_close(amprocDesc, AccessShareLock);
5283  break;
5284  }
5285 
5286  case RewriteRelationId:
5287  {
5288  Relation ruleDesc;
5289  HeapTuple tup;
5291 
5292  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
5293 
5294  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
5295  object->objectId);
5296 
5297  if (!HeapTupleIsValid(tup))
5298  {
5299  if (!missing_ok)
5300  elog(ERROR, "could not find tuple for rule %u",
5301  object->objectId);
5302 
5303  table_close(ruleDesc, AccessShareLock);
5304  break;
5305  }
5306 
5307  rule = (Form_pg_rewrite) GETSTRUCT(tup);
5308 
5309  appendStringInfo(&buffer, "%s on ",
5310  quote_identifier(NameStr(rule->rulename)));
5311  getRelationIdentity(&buffer, rule->ev_class, objname, false);
5312  if (objname)
5313  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5314 
5315  table_close(ruleDesc, AccessShareLock);
5316  break;
5317  }
5318 
5319  case TriggerRelationId:
5320  {
5321  Relation trigDesc;
5322  HeapTuple tup;
5323  Form_pg_trigger trig;
5324 
5325  trigDesc = table_open(TriggerRelationId, AccessShareLock);
5326 
5327  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
5328  object->objectId);
5329 
5330  if (!HeapTupleIsValid(tup))
5331  {
5332  if (!missing_ok)
5333  elog(ERROR, "could not find tuple for trigger %u",
5334  object->objectId);
5335 
5336  table_close(trigDesc, AccessShareLock);
5337  break;
5338  }
5339 
5340  trig = (Form_pg_trigger) GETSTRUCT(tup);
5341 
5342  appendStringInfo(&buffer, "%s on ",
5343  quote_identifier(NameStr(trig->tgname)));
5344  getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5345  if (objname)
5346  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5347 
5348  table_close(trigDesc, AccessShareLock);
5349  break;
5350  }
5351 
5352  case NamespaceRelationId:
5353  {
5354  char *nspname;
5355 
5356  nspname = get_namespace_name_or_temp(object->objectId);
5357  if (!nspname)
5358  {
5359  if (!missing_ok)
5360  elog(ERROR, "cache lookup failed for namespace %u",
5361  object->objectId);
5362  break;
5363  }
5364  appendStringInfoString(&buffer,
5365  quote_identifier(nspname));
5366  if (objname)
5367  *objname = list_make1(nspname);
5368  break;
5369  }
5370 
5371  case StatisticExtRelationId:
5372  {
5373  HeapTuple tup;
5374  Form_pg_statistic_ext formStatistic;
5375  char *schema;
5376 
5377  tup = SearchSysCache1(STATEXTOID,
5378  ObjectIdGetDatum(object->objectId));
5379  if (!HeapTupleIsValid(tup))
5380  {
5381  if (!missing_ok)
5382  elog(ERROR, "cache lookup failed for statistics object %u",
5383  object->objectId);
5384  break;
5385  }
5386  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
5387  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5388  appendStringInfoString(&buffer,
5390  NameStr(formStatistic->stxname)));
5391  if (objname)
5392  *objname = list_make2(schema,
5393  pstrdup(NameStr(formStatistic->stxname)));
5394  ReleaseSysCache(tup);
5395  }
5396  break;
5397 
5398  case TSParserRelationId:
5399  {
5400  HeapTuple tup;
5401  Form_pg_ts_parser formParser;
5402  char *schema;
5403 
5404  tup = SearchSysCache1(TSPARSEROID,
5405  ObjectIdGetDatum(object->objectId));
5406  if (!HeapTupleIsValid(tup))
5407  {
5408  if (!missing_ok)
5409  elog(ERROR, "cache lookup failed for text search parser %u",
5410  object->objectId);
5411  break;
5412  }
5413  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
5414  schema = get_namespace_name_or_temp(formParser->prsnamespace);
5415  appendStringInfoString(&buffer,
5417  NameStr(formParser->prsname)));
5418  if (objname)
5419  *objname = list_make2(schema,
5420  pstrdup(NameStr(formParser->prsname)));
5421  ReleaseSysCache(tup);
5422  break;
5423  }
5424 
5425  case TSDictionaryRelationId:
5426  {
5427  HeapTuple tup;
5428  Form_pg_ts_dict formDict;
5429  char *schema;
5430 
5431  tup = SearchSysCache1(TSDICTOID,
5432  ObjectIdGetDatum(object->objectId));
5433  if (!HeapTupleIsValid(tup))
5434  {
5435  if (!missing_ok)
5436  elog(ERROR, "cache lookup failed for text search dictionary %u",
5437  object->objectId);
5438  break;
5439  }
5440  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
5441  schema = get_namespace_name_or_temp(formDict->dictnamespace);
5442  appendStringInfoString(&buffer,
5444  NameStr(formDict->dictname)));
5445  if (objname)
5446  *objname = list_make2(schema,
5447  pstrdup(NameStr(formDict->dictname)));
5448  ReleaseSysCache(tup);
5449  break;
5450  }
5451 
5452  case TSTemplateRelationId:
5453  {
5454  HeapTuple tup;
5455  Form_pg_ts_template formTmpl;
5456  char *schema;
5457 
5458  tup = SearchSysCache1(TSTEMPLATEOID,
5459  ObjectIdGetDatum(object->objectId));
5460  if (!HeapTupleIsValid(tup))
5461  {
5462  if (!missing_ok)
5463  elog(ERROR, "cache lookup failed for text search template %u",
5464  object->objectId);
5465  break;
5466  }
5467  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
5468  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5469  appendStringInfoString(&buffer,
5471  NameStr(formTmpl->tmplname)));
5472  if (objname)
5473  *objname = list_make2(schema,
5474  pstrdup(NameStr(formTmpl->tmplname)));
5475  ReleaseSysCache(tup);
5476  break;
5477  }
5478 
5479  case TSConfigRelationId:
5480  {
5481  HeapTuple tup;
5482  Form_pg_ts_config formCfg;
5483  char *schema;
5484 
5485  tup = SearchSysCache1(TSCONFIGOID,
5486  ObjectIdGetDatum(object->objectId));
5487  if (!HeapTupleIsValid(tup))
5488  {
5489  if (!missing_ok)
5490  elog(ERROR, "cache lookup failed for text search configuration %u",
5491  object->objectId);
5492  break;
5493  }
5494  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
5495  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5496  appendStringInfoString(&buffer,
5498  NameStr(formCfg->cfgname)));
5499  if (objname)
5500  *objname = list_make2(schema,
5501  pstrdup(NameStr(formCfg->cfgname)));
5502  ReleaseSysCache(tup);
5503  break;
5504  }
5505 
5506  case AuthIdRelationId:
5507  {
5508  char *username;
5509 
5510  username = GetUserNameFromId(object->objectId, missing_ok);
5511  if (!username)
5512  break;
5513  if (objname)
5514  *objname = list_make1(username);
5515  appendStringInfoString(&buffer,
5517  break;
5518  }
5519 
5520  case AuthMemRelationId:
5521  {
5522  Relation authMemDesc;
5523  ScanKeyData skey[1];
5524  SysScanDesc amscan;
5525  HeapTuple tup;
5526  Form_pg_auth_members amForm;
5527 
5528  authMemDesc = table_open(AuthMemRelationId,
5529  AccessShareLock);
5530 
5531  ScanKeyInit(&skey[0],
5532  Anum_pg_auth_members_oid,
5533  BTEqualStrategyNumber, F_OIDEQ,
5534  ObjectIdGetDatum(object->objectId));
5535 
5536  amscan = systable_beginscan(authMemDesc, AuthMemOidIndexId, true,
5537  NULL, 1, skey);
5538 
5539  tup = systable_getnext(amscan);
5540 
5541  if (!HeapTupleIsValid(tup))
5542  {
5543  if (!missing_ok)
5544  elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5545  object->objectId);
5546 
5547  systable_endscan(amscan);
5548  table_close(authMemDesc, AccessShareLock);
5549  break;
5550  }
5551 
5552  amForm = (Form_pg_auth_members) GETSTRUCT(tup);
5553 
5554  appendStringInfo(&buffer, _("membership of role %s in role %s"),
5555  GetUserNameFromId(amForm->member, false),
5556  GetUserNameFromId(amForm->roleid, false));
5557 
5558  systable_endscan(amscan);
5559  table_close(authMemDesc, AccessShareLock);
5560  break;
5561  }
5562 
5563  case DatabaseRelationId:
5564  {
5565  char *datname;
5566 
5567  datname = get_database_name(object->objectId);
5568  if (!datname)
5569  {
5570  if (!missing_ok)
5571  elog(ERROR, "cache lookup failed for database %u",
5572  object->objectId);
5573  break;
5574  }
5575  if (objname)
5576  *objname = list_make1(datname);
5577  appendStringInfoString(&buffer,
5579  break;
5580  }
5581 
5582  case TableSpaceRelationId:
5583  {
5584  char *tblspace;
5585 
5586  tblspace = get_tablespace_name(object->objectId);
5587  if (!tblspace)
5588  {
5589  if (!missing_ok)
5590  elog(ERROR, "cache lookup failed for tablespace %u",
5591  object->objectId);
5592  break;
5593  }
5594  if (objname)
5595  *objname = list_make1(tblspace);
5596  appendStringInfoString(&buffer,
5597  quote_identifier(tblspace));
5598  break;
5599  }
5600 
5601  case ForeignDataWrapperRelationId:
5602  {
5603  ForeignDataWrapper *fdw;
5604 
5606  missing_ok);
5607  if (fdw)
5608  {
5610  if (objname)
5611  *objname = list_make1(pstrdup(fdw->fdwname));
5612  }
5613  break;
5614  }
5615 
5616  case ForeignServerRelationId:
5617  {
5618  ForeignServer *srv;
5619 
5620  srv = GetForeignServerExtended(object->objectId,
5621  missing_ok);
5622  if (srv)
5623  {
5624  appendStringInfoString(&buffer,
5626  if (objname)
5627  *objname = list_make1(pstrdup(srv->servername));
5628  }
5629  break;
5630  }
5631 
5632  case UserMappingRelationId:
5633  {
5634  HeapTuple tup;
5635  Oid useid;
5636  Form_pg_user_mapping umform;
5637  ForeignServer *srv;
5638  const char *usename;
5639 
5640  tup = SearchSysCache1(USERMAPPINGOID,
5641  ObjectIdGetDatum(object->objectId));
5642  if (!HeapTupleIsValid(tup))
5643  {
5644  if (!missing_ok)
5645  elog(ERROR, "cache lookup failed for user mapping %u",
5646  object->objectId);
5647  break;
5648  }
5649  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
5650  useid = umform->umuser;
5651  srv = GetForeignServer(umform->umserver);
5652 
5653  ReleaseSysCache(tup);
5654 
5655  if (OidIsValid(useid))
5656  usename = GetUserNameFromId(useid, false);
5657  else
5658  usename = "public";
5659 
5660  if (objname)
5661  {
5662  *objname = list_make1(pstrdup(usename));
5663  *objargs = list_make1(pstrdup(srv->servername));
5664  }
5665 
5666  appendStringInfo(&buffer, "%s on server %s",
5667  quote_identifier(usename),
5668  srv->servername);
5669  break;
5670  }
5671 
5672  case DefaultAclRelationId:
5673  {
5674  Relation defaclrel;
5675  ScanKeyData skey[1];
5676  SysScanDesc rcscan;
5677  HeapTuple tup;
5678  Form_pg_default_acl defacl;
5679  char *schema;
5680  char *username;
5681 
5682  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
5683 
5684  ScanKeyInit(&skey[0],
5685  Anum_pg_default_acl_oid,
5686  BTEqualStrategyNumber, F_OIDEQ,
5687  ObjectIdGetDatum(object->objectId));
5688 
5689  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5690  true, NULL, 1, skey);
5691 
5692  tup = systable_getnext(rcscan);
5693 
5694  if (!HeapTupleIsValid(tup))
5695  {
5696  if (!missing_ok)
5697  elog(ERROR, "could not find tuple for default ACL %u",
5698  object->objectId);
5699 
5700  systable_endscan(rcscan);
5701  table_close(defaclrel, AccessShareLock);
5702  break;
5703  }
5704 
5705  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5706 
5707  username = GetUserNameFromId(defacl->defaclrole, false);
5708  appendStringInfo(&buffer,
5709  "for role %s",
5711 
5712  if (OidIsValid(defacl->defaclnamespace))
5713  {
5714  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5715  appendStringInfo(&buffer,
5716  " in schema %s",
5717  quote_identifier(schema));
5718  }
5719  else
5720  schema = NULL;
5721 
5722  switch (defacl->defaclobjtype)
5723  {
5724  case DEFACLOBJ_RELATION:
5725  appendStringInfoString(&buffer,
5726  " on tables");
5727  break;
5728  case DEFACLOBJ_SEQUENCE:
5729  appendStringInfoString(&buffer,
5730  " on sequences");
5731  break;
5732  case DEFACLOBJ_FUNCTION:
5733  appendStringInfoString(&buffer,
5734  " on functions");
5735  break;
5736  case DEFACLOBJ_TYPE:
5737  appendStringInfoString(&buffer,
5738  " on types");
5739  break;
5740  case DEFACLOBJ_NAMESPACE:
5741  appendStringInfoString(&buffer,
5742  " on schemas");
5743  break;
5744  }
5745 
5746  if (objname)
5747  {
5748  *objname = list_make1(username);
5749  if (schema)
5750  *objname = lappend(*objname, schema);
5751  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5752  }
5753 
5754  systable_endscan(rcscan);
5755  table_close(defaclrel, AccessShareLock);
5756  break;
5757  }
5758 
5759  case ExtensionRelationId:
5760  {
5761  char *extname;
5762 
5763  extname = get_extension_name(object->objectId);
5764  if (!extname)
5765  {
5766  if (!missing_ok)
5767  elog(ERROR, "cache lookup failed for extension %u",
5768  object->objectId);
5769  break;
5770  }
5771  appendStringInfoString(&buffer, quote_identifier(extname));
5772  if (objname)
5773  *objname = list_make1(extname);
5774  break;
5775  }
5776 
5777  case EventTriggerRelationId:
5778  {
5779  HeapTuple tup;
5780  Form_pg_event_trigger trigForm;
5781  char *evtname;
5782 
5783  tup = SearchSysCache1(EVENTTRIGGEROID,
5784  ObjectIdGetDatum(object->objectId));
5785  if (!HeapTupleIsValid(tup))
5786  {
5787  if (!missing_ok)
5788  elog(ERROR, "cache lookup failed for event trigger %u",
5789  object->objectId);
5790  break;
5791  }
5792  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5793  evtname = pstrdup(NameStr(trigForm->evtname));
5794  appendStringInfoString(&buffer, quote_identifier(evtname));
5795  if (objname)
5796  *objname = list_make1(evtname);
5797  ReleaseSysCache(tup);
5798  break;
5799  }
5800 
5801  case ParameterAclRelationId:
5802  {
5803  HeapTuple tup;
5804  Datum nameDatum;
5805  char *parname;
5806 
5807  tup = SearchSysCache1(PARAMETERACLOID,
5808  ObjectIdGetDatum(object->objectId));
5809  if (!HeapTupleIsValid(tup))
5810  {
5811  if (!missing_ok)
5812  elog(ERROR, "cache lookup failed for parameter ACL %u",
5813  object->objectId);
5814  break;
5815  }
5816  nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
5817  Anum_pg_parameter_acl_parname);
5818  parname = TextDatumGetCString(nameDatum);
5819  appendStringInfoString(&buffer, parname);
5820  if (objname)
5821  *objname = list_make1(parname);
5822  ReleaseSysCache(tup);
5823  break;
5824  }
5825 
5826  case PolicyRelationId:
5827  {
5828  Relation polDesc;
5829  HeapTuple tup;
5830  Form_pg_policy policy;
5831 
5832  polDesc = table_open(PolicyRelationId, AccessShareLock);
5833 
5834  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5835  object->objectId);
5836 
5837  if (!HeapTupleIsValid(tup))
5838  {
5839  if (!missing_ok)
5840  elog(ERROR, "could not find tuple for policy %u",
5841  object->objectId);
5842 
5843  table_close(polDesc, AccessShareLock);
5844  break;
5845  }
5846 
5847  policy = (Form_pg_policy) GETSTRUCT(tup);
5848 
5849  appendStringInfo(&buffer, "%s on ",
5850  quote_identifier(NameStr(policy->polname)));
5851  getRelationIdentity(&buffer, policy->polrelid, objname, false);
5852  if (objname)
5853  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5854 
5855  table_close(polDesc, AccessShareLock);
5856  break;
5857  }
5858 
5859  case PublicationRelationId:
5860  {
5861  char *pubname;
5862 
5863  pubname = get_publication_name(object->objectId, missing_ok);
5864  if (pubname)
5865  {
5866  appendStringInfoString(&buffer,
5867  quote_identifier(pubname));
5868  if (objname)
5869  *objname = list_make1(pubname);
5870  }
5871  break;
5872  }
5873 
5874  case PublicationNamespaceRelationId:
5875  {
5876  char *pubname;
5877  char *nspname;
5878 
5879  if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
5880  &nspname))
5881  break;
5882  appendStringInfo(&buffer, "%s in publication %s",
5883  nspname, pubname);
5884 
5885  if (objargs)
5886  *objargs = list_make1(pubname);
5887  else
5888  pfree(pubname);
5889 
5890  if (objname)
5891  *objname = list_make1(nspname);
5892  else
5893  pfree(nspname);
5894 
5895  break;
5896  }
5897 
5898  case PublicationRelRelationId:
5899  {
5900  HeapTuple tup;
5901  char *pubname;
5902  Form_pg_publication_rel prform;
5903 
5904  tup = SearchSysCache1(PUBLICATIONREL,
5905  ObjectIdGetDatum(object->objectId));
5906  if (!HeapTupleIsValid(tup))
5907  {
5908  if (!missing_ok)
5909  elog(ERROR, "cache lookup failed for publication table %u",
5910  object->objectId);
5911  break;
5912  }
5913 
5914  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5915  pubname = get_publication_name(prform->prpubid, false);
5916 
5917  getRelationIdentity(&buffer, prform->prrelid, objname, false);
5918  appendStringInfo(&buffer, " in publication %s", pubname);
5919 
5920  if (objargs)
5921  *objargs = list_make1(pubname);
5922 
5923  ReleaseSysCache(tup);
5924  break;
5925  }
5926 
5927  case SubscriptionRelationId:
5928  {
5929  char *subname;
5930 
5931  subname = get_subscription_name(object->objectId, missing_ok);
5932  if (subname)
5933  {
5934  appendStringInfoString(&buffer,
5936  if (objname)
5937  *objname = list_make1(subname);
5938  }
5939  break;
5940  }
5941 
5942  case TransformRelationId:
5943  {
5944  Relation transformDesc;
5945  HeapTuple tup;
5946  Form_pg_transform transform;
5947  char *transformLang;
5948  char *transformType;
5949 
5950  transformDesc = table_open(TransformRelationId, AccessShareLock);
5951 
5952  tup = get_catalog_object_by_oid(transformDesc,
5953  Anum_pg_transform_oid,
5954  object->objectId);
5955 
5956  if (!HeapTupleIsValid(tup))
5957  {
5958  if (!missing_ok)
5959  elog(ERROR, "could not find tuple for transform %u",
5960  object->objectId);
5961 
5962  table_close(transformDesc, AccessShareLock);
5963  break;
5964  }
5965 
5966  transform = (Form_pg_transform) GETSTRUCT(tup);
5967 
5968  transformType = format_type_be_qualified(transform->trftype);
5969  transformLang = get_language_name(transform->trflang, false);
5970 
5971  appendStringInfo(&buffer, "for %s language %s",
5972  transformType,
5973  transformLang);
5974  if (objname)
5975  {
5976  *objname = list_make1(transformType);
5977  *objargs = list_make1(pstrdup(transformLang));
5978  }
5979 
5980  table_close(transformDesc, AccessShareLock);
5981  }
5982  break;
5983 
5984  default:
5985  elog(ERROR, "unsupported object class: %u", object->classId);
5986  }
5987 
5988  if (!missing_ok)
5989  {
5990  /*
5991  * If a get_object_address() representation was requested, make sure
5992  * we are providing one. We don't check objargs, because many of the
5993  * cases above leave it as NIL.
5994  */
5995  if (objname && *objname == NIL)
5996  elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"",
5997  object->classId, buffer.data);
5998  }
5999  else
6000  {
6001  /* an empty buffer is equivalent to no object found */
6002  if (buffer.len == 0)
6003  {
6004  Assert((objname == NULL || *objname == NIL) &&
6005  (objargs == NULL || *objargs == NIL));
6006  return NULL;
6007  }
6008  }
6009 
6010  return buffer.data;
6011 }
char * get_am_name(Oid amOid)
Definition: amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:126
#define PointerIsValid(pointer)
Definition: c.h:717
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:353
List * lappend(List *list, void *datum)
Definition: list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3390
char * pstrdup(const char *in)
Definition: mcxt.c:1696
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
#define NIL
Definition: pg_list.h:68
#define list_make1(x1)
Definition: pg_list.h:212
#define list_make3(x1, x2, x3)
Definition: pg_list.h:216
#define list_make2(x1, x2)
Definition: pg_list.h:214
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:806
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:398
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:12868

References _, AccessShareLock, appendStringInfo(), appendStringInfoString(), Assert, BTEqualStrategyNumber, ObjectAddress::classId, StringInfoData::data, datname, elog, ERROR, ForeignDataWrapper::fdwname, format_operator_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getOpFamilyIdentity(), getPublicationSchemaInfo(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), lappend(), LargeObjectExists(), StringInfoData::len, list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, pfree(), PointerIsValid, proname, psprintf(), pstrdup(), quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, and username.

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

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4462 of file objectaddress.c.

4463 {
4464  StringInfoData buffer;
4465 
4466  initStringInfo(&buffer);
4467 
4468  switch (object->classId)
4469  {
4470  case RelationRelationId:
4471  getRelationTypeDescription(&buffer, object->objectId,
4472  object->objectSubId,
4473  missing_ok);
4474  break;
4475 
4476  case ProcedureRelationId:
4477  getProcedureTypeDescription(&buffer, object->objectId,
4478  missing_ok);
4479  break;
4480 
4481  case TypeRelationId:
4482  appendStringInfoString(&buffer, "type");
4483  break;
4484 
4485  case CastRelationId:
4486  appendStringInfoString(&buffer, "cast");
4487  break;
4488 
4489  case CollationRelationId:
4490  appendStringInfoString(&buffer, "collation");
4491  break;
4492 
4493  case ConstraintRelationId:
4494  getConstraintTypeDescription(&buffer, object->objectId,
4495  missing_ok);
4496  break;
4497 
4498  case ConversionRelationId:
4499  appendStringInfoString(&buffer, "conversion");
4500  break;
4501 
4502  case AttrDefaultRelationId:
4503  appendStringInfoString(&buffer, "default value");
4504  break;
4505 
4506  case LanguageRelationId:
4507  appendStringInfoString(&buffer, "language");
4508  break;
4509 
4510  case LargeObjectRelationId:
4511  appendStringInfoString(&buffer, "large object");
4512  break;
4513 
4514  case OperatorRelationId:
4515  appendStringInfoString(&buffer, "operator");
4516  break;
4517 
4518  case OperatorClassRelationId:
4519  appendStringInfoString(&buffer, "operator class");
4520  break;
4521 
4522  case OperatorFamilyRelationId:
4523  appendStringInfoString(&buffer, "operator family");
4524  break;
4525 
4526  case AccessMethodRelationId:
4527  appendStringInfoString(&buffer, "access method");
4528  break;
4529 
4530  case AccessMethodOperatorRelationId:
4531  appendStringInfoString(&buffer, "operator of access method");
4532  break;
4533 
4534  case AccessMethodProcedureRelationId:
4535  appendStringInfoString(&buffer, "function of access method");
4536  break;
4537 
4538  case RewriteRelationId:
4539  appendStringInfoString(&buffer, "rule");
4540  break;
4541 
4542  case TriggerRelationId:
4543  appendStringInfoString(&buffer, "trigger");
4544  break;
4545 
4546  case NamespaceRelationId:
4547  appendStringInfoString(&buffer, "schema");
4548  break;
4549 
4550  case StatisticExtRelationId:
4551  appendStringInfoString(&buffer, "statistics object");
4552  break;
4553 
4554  case TSParserRelationId:
4555  appendStringInfoString(&buffer, "text search parser");
4556  break;
4557 
4558  case TSDictionaryRelationId:
4559  appendStringInfoString(&buffer, "text search dictionary");
4560  break;
4561 
4562  case TSTemplateRelationId:
4563  appendStringInfoString(&buffer, "text search template");
4564  break;
4565 
4566  case TSConfigRelationId:
4567  appendStringInfoString(&buffer, "text search configuration");
4568  break;
4569 
4570  case AuthIdRelationId:
4571  appendStringInfoString(&buffer, "role");
4572  break;
4573 
4574  case AuthMemRelationId:
4575  appendStringInfoString(&buffer, "role membership");
4576  break;
4577 
4578  case DatabaseRelationId:
4579  appendStringInfoString(&buffer, "database");
4580  break;
4581 
4582  case TableSpaceRelationId:
4583  appendStringInfoString(&buffer, "tablespace");
4584  break;