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/sysattr.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_enum.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 "nodes/makefuncs.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)
 
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 2425 of file objectaddress.c.

2427 {
2428  switch (objtype)
2429  {
2430  case OBJECT_INDEX:
2431  case OBJECT_SEQUENCE:
2432  case OBJECT_TABLE:
2433  case OBJECT_VIEW:
2434  case OBJECT_MATVIEW:
2435  case OBJECT_FOREIGN_TABLE:
2436  case OBJECT_COLUMN:
2437  case OBJECT_RULE:
2438  case OBJECT_TRIGGER:
2439  case OBJECT_POLICY:
2440  case OBJECT_TABCONSTRAINT:
2441  if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2443  RelationGetRelationName(relation));
2444  break;
2445  case OBJECT_TYPE:
2446  case OBJECT_DOMAIN:
2447  case OBJECT_ATTRIBUTE:
2448  if (!object_ownercheck(address.classId, address.objectId, roleid))
2450  break;
2451  case OBJECT_DOMCONSTRAINT:
2452  {
2453  HeapTuple tuple;
2454  Oid contypid;
2455 
2456  tuple = SearchSysCache1(CONSTROID,
2457  ObjectIdGetDatum(address.objectId));
2458  if (!HeapTupleIsValid(tuple))
2459  elog(ERROR, "constraint with OID %u does not exist",
2460  address.objectId);
2461 
2462  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2463 
2464  ReleaseSysCache(tuple);
2465 
2466  /*
2467  * Fallback to type ownership check in this case as this is
2468  * what domain constraints rely on.
2469  */
2470  if (!object_ownercheck(TypeRelationId, contypid, roleid))
2472  }
2473  break;
2474  case OBJECT_AGGREGATE:
2475  case OBJECT_FUNCTION:
2476  case OBJECT_PROCEDURE:
2477  case OBJECT_ROUTINE:
2478  case OBJECT_OPERATOR:
2479  if (!object_ownercheck(address.classId, address.objectId, roleid))
2481  NameListToString((castNode(ObjectWithArgs, object))->objname));
2482  break;
2483  case OBJECT_DATABASE:
2484  case OBJECT_EVENT_TRIGGER:
2485  case OBJECT_EXTENSION:
2486  case OBJECT_FDW:
2487  case OBJECT_FOREIGN_SERVER:
2488  case OBJECT_LANGUAGE:
2489  case OBJECT_PUBLICATION:
2490  case OBJECT_SCHEMA:
2491  case OBJECT_SUBSCRIPTION:
2492  case OBJECT_TABLESPACE:
2493  if (!object_ownercheck(address.classId, address.objectId, roleid))
2495  strVal(object));
2496  break;
2497  case OBJECT_COLLATION:
2498  case OBJECT_CONVERSION:
2499  case OBJECT_OPCLASS:
2500  case OBJECT_OPFAMILY:
2501  case OBJECT_STATISTIC_EXT:
2502  case OBJECT_TSDICTIONARY:
2504  if (!object_ownercheck(address.classId, address.objectId, roleid))
2506  NameListToString(castNode(List, object)));
2507  break;
2508  case OBJECT_LARGEOBJECT:
2509  if (!lo_compat_privileges &&
2510  !object_ownercheck(address.classId, address.objectId, roleid))
2511  ereport(ERROR,
2512  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2513  errmsg("must be owner of large object %u",
2514  address.objectId)));
2515  break;
2516  case OBJECT_CAST:
2517  {
2518  /* We can only check permissions on the source/target types */
2519  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2520  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2521  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2522  Oid targettypeid = typenameTypeId(NULL, targettype);
2523 
2524  if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
2525  && !object_ownercheck(TypeRelationId, targettypeid, roleid))
2526  ereport(ERROR,
2527  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2528  errmsg("must be owner of type %s or type %s",
2529  format_type_be(sourcetypeid),
2530  format_type_be(targettypeid))));
2531  }
2532  break;
2533  case OBJECT_TRANSFORM:
2534  {
2535  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2536  Oid typeid = typenameTypeId(NULL, typename);
2537 
2538  if (!object_ownercheck(TypeRelationId, typeid, roleid))
2540  }
2541  break;
2542  case OBJECT_ROLE:
2543 
2544  /*
2545  * We treat roles as being "owned" by those with CREATEROLE priv,
2546  * except that superusers are only owned by superusers.
2547  */
2548  if (superuser_arg(address.objectId))
2549  {
2550  if (!superuser_arg(roleid))
2551  ereport(ERROR,
2552  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2553  errmsg("must be superuser")));
2554  }
2555  else
2556  {
2557  if (!has_createrole_privilege(roleid))
2558  ereport(ERROR,
2559  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2560  errmsg("must have CREATEROLE privilege")));
2561  }
2562  break;
2563  case OBJECT_TSPARSER:
2564  case OBJECT_TSTEMPLATE:
2565  case OBJECT_ACCESS_METHOD:
2566  case OBJECT_PARAMETER_ACL:
2567  /* We treat these object types as being owned by superusers */
2568  if (!superuser_arg(roleid))
2569  ereport(ERROR,
2570  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2571  errmsg("must be superuser")));
2572  break;
2573  case OBJECT_AMOP:
2574  case OBJECT_AMPROC:
2575  case OBJECT_DEFAULT:
2576  case OBJECT_DEFACL:
2579  case OBJECT_USER_MAPPING:
2580  /* These are currently not supported or don't make sense here. */
2581  elog(ERROR, "unsupported object type: %d", (int) objtype);
2582  break;
2583  }
2584 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:186
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3485
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4799
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3804
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:4880
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
bool lo_compat_privileges
Definition: inv_api.c:58
char * NameListToString(List *names)
Definition: namespace.c:3145
#define castNode(_type_, nodeptr)
Definition: nodes.h:186
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1876
@ OBJECT_FDW
Definition: parsenodes.h:1878
@ OBJECT_TSPARSER
Definition: parsenodes.h:1909
@ OBJECT_COLLATION
Definition: parsenodes.h:1869
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:1912
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:1862
@ OBJECT_OPCLASS
Definition: parsenodes.h:1886
@ OBJECT_DEFACL
Definition: parsenodes.h:1873
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1863
@ OBJECT_MATVIEW
Definition: parsenodes.h:1885
@ OBJECT_SCHEMA
Definition: parsenodes.h:1898
@ OBJECT_POLICY
Definition: parsenodes.h:1890
@ OBJECT_OPERATOR
Definition: parsenodes.h:1887
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1880
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:1907
@ OBJECT_OPFAMILY
Definition: parsenodes.h:1888
@ OBJECT_DOMAIN
Definition: parsenodes.h:1874
@ OBJECT_COLUMN
Definition: parsenodes.h:1868
@ OBJECT_TABLESPACE
Definition: parsenodes.h:1904
@ OBJECT_ROLE
Definition: parsenodes.h:1895
@ OBJECT_ROUTINE
Definition: parsenodes.h:1896
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1884
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:1893
@ OBJECT_PROCEDURE
Definition: parsenodes.h:1891
@ OBJECT_EXTENSION
Definition: parsenodes.h:1877
@ OBJECT_INDEX
Definition: parsenodes.h:1882
@ OBJECT_DEFAULT
Definition: parsenodes.h:1872
@ OBJECT_DATABASE
Definition: parsenodes.h:1871
@ OBJECT_SEQUENCE
Definition: parsenodes.h:1899
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:1910
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1883
@ OBJECT_AMOP
Definition: parsenodes.h:1864
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:1894
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1879
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:1908
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1866
@ OBJECT_PUBLICATION
Definition: parsenodes.h:1892
@ OBJECT_RULE
Definition: parsenodes.h:1897
@ OBJECT_CONVERSION
Definition: parsenodes.h:1870
@ OBJECT_AMPROC
Definition: parsenodes.h:1865
@ OBJECT_TABLE
Definition: parsenodes.h:1903
@ OBJECT_VIEW
Definition: parsenodes.h:1913
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:1889
@ OBJECT_TYPE
Definition: parsenodes.h:1911
@ OBJECT_FUNCTION
Definition: parsenodes.h:1881
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:1902
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1875
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:1900
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:1901
@ OBJECT_CAST
Definition: parsenodes.h:1867
@ OBJECT_TRIGGER
Definition: parsenodes.h:1906
@ OBJECT_TRANSFORM
Definition: parsenodes.h:1905
FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition: pg_list.h:179
#define lsecond_node(type, l)
Definition: pg_list.h:184
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:600
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:501
#define RelationGetRelationName(relation)
Definition: rel.h:535
Definition: pg_list.h:52
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ CONSTROID
Definition: syscache.h:53
#define strVal(v)
Definition: value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, CONSTROID, elog(), ereport, errcode(), errmsg(), ERROR, format_type_be(), GETSTRUCT, has_createrole_privilege(), HeapTupleIsValid, 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 2813 of file objectaddress.c.

2814 {
2815  HeapTuple tuple;
2816  Oid classId = RelationGetRelid(catalog);
2817  int oidCacheId = get_object_catcache_oid(classId);
2818 
2819  if (oidCacheId > 0)
2820  {
2821  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2822  if (!HeapTupleIsValid(tuple)) /* should not happen */
2823  return NULL;
2824  }
2825  else
2826  {
2827  Oid oidIndexId = get_object_oid_index(classId);
2828  SysScanDesc scan;
2829  ScanKeyData skey;
2830 
2831  Assert(OidIsValid(oidIndexId));
2832 
2833  ScanKeyInit(&skey,
2834  oidcol,
2835  BTEqualStrategyNumber, F_OIDEQ,
2836  ObjectIdGetDatum(objectId));
2837 
2838  scan = systable_beginscan(catalog, oidIndexId, true,
2839  NULL, 1, &skey);
2840  tuple = systable_getnext(scan);
2841  if (!HeapTupleIsValid(tuple))
2842  {
2843  systable_endscan(scan);
2844  return NULL;
2845  }
2846  tuple = heap_copytuple(tuple);
2847 
2848  systable_endscan(scan);
2849  }
2850 
2851  return tuple;
2852 }
#define OidIsValid(objectId)
Definition: c.h:711
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:599
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:506
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:680
Assert(fmt[strlen(fmt) - 1] !='\n')
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:179

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(), 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 960 of file objectaddress.c.

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

1586 {
1587  ObjectAddress address;
1588  List *relname;
1589  Oid reloid;
1590  Relation relation;
1591  const char *attname;
1593  TupleDesc tupdesc;
1594  Oid defoid;
1595 
1596  /* Extract relation name and open relation. */
1597  if (list_length(object) < 2)
1598  ereport(ERROR,
1599  (errcode(ERRCODE_SYNTAX_ERROR),
1600  errmsg("column name must be qualified")));
1601  attname = strVal(llast(object));
1602  relname = list_copy_head(object, list_length(object) - 1);
1603  /* XXX no missing_ok support here */
1604  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1605  reloid = RelationGetRelid(relation);
1606 
1607  tupdesc = RelationGetDescr(relation);
1608 
1609  /* Look up attribute number and fetch the pg_attrdef OID */
1610  attnum = get_attnum(reloid, attname);
1611  defoid = InvalidOid;
1612  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1613  defoid = GetAttrDefaultOid(reloid, attnum);
1614  if (!OidIsValid(defoid))
1615  {
1616  if (!missing_ok)
1617  ereport(ERROR,
1618  (errcode(ERRCODE_UNDEFINED_COLUMN),
1619  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1621 
1622  address.classId = AttrDefaultRelationId;
1623  address.objectId = InvalidOid;
1624  address.objectSubId = InvalidAttrNumber;
1625  relation_close(relation, lockmode);
1626  return address;
1627  }
1628 
1629  address.classId = AttrDefaultRelationId;
1630  address.objectId = defoid;
1631  address.objectSubId = 0;
1632 
1633  *relp = relation;
1634  return address;
1635 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
List * list_copy_head(const List *oldlist, int len)
Definition: list.c:1592
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:857
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3105
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Definition: pg_attrdef.c:339
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:83
NameData relname
Definition: pg_class.h:38
#define llast(l)
Definition: pg_list.h:196
static int list_length(const List *l)
Definition: pg_list.h:150
#define RelationGetDescr(relation)
Definition: rel.h:527
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
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 1532 of file objectaddress.c.

1535 {
1536  ObjectAddress address;
1537  List *relname;
1538  Oid reloid;
1539  Relation relation;
1540  const char *attname;
1542 
1543  /* Extract relation name and open relation. */
1544  if (list_length(object) < 2)
1545  ereport(ERROR,
1546  (errcode(ERRCODE_SYNTAX_ERROR),
1547  errmsg("column name must be qualified")));
1548  attname = strVal(llast(object));
1549  relname = list_copy_head(object, list_length(object) - 1);
1550  /* XXX no missing_ok support here */
1551  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1552  reloid = RelationGetRelid(relation);
1553 
1554  /* Look up attribute and construct return value. */
1555  attnum = get_attnum(reloid, attname);
1556  if (attnum == InvalidAttrNumber)
1557  {
1558  if (!missing_ok)
1559  ereport(ERROR,
1560  (errcode(ERRCODE_UNDEFINED_COLUMN),
1561  errmsg("column \"%s\" of relation \"%s\" does not exist",
1563 
1564  address.classId = RelationRelationId;
1565  address.objectId = InvalidOid;
1566  address.objectSubId = InvalidAttrNumber;
1567  relation_close(relation, lockmode);
1568  return address;
1569  }
1570 
1571  address.classId = RelationRelationId;
1572  address.objectId = reloid;
1573  address.objectSubId = attnum;
1574 
1575  *relp = relation;
1576  return address;
1577 }

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

1997 {
1998  HeapTuple tp;
1999  Oid userid;
2000  Oid schemaid;
2001  char *username;
2002  char *schema;
2003  char objtype;
2004  char *objtype_str;
2005  ObjectAddress address;
2006 
2007  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
2008 
2009  /*
2010  * First figure out the textual attributes so that they can be used for
2011  * error reporting.
2012  */
2013  username = strVal(lsecond(object));
2014  if (list_length(object) >= 3)
2015  schema = (char *) strVal(lthird(object));
2016  else
2017  schema = NULL;
2018 
2019  /*
2020  * Decode defaclobjtype. Only first char is considered; the rest of the
2021  * string, if any, is blissfully ignored.
2022  */
2023  objtype = ((char *) strVal(linitial(object)))[0];
2024  switch (objtype)
2025  {
2026  case DEFACLOBJ_RELATION:
2027  objtype_str = "tables";
2028  break;
2029  case DEFACLOBJ_SEQUENCE:
2030  objtype_str = "sequences";
2031  break;
2032  case DEFACLOBJ_FUNCTION:
2033  objtype_str = "functions";
2034  break;
2035  case DEFACLOBJ_TYPE:
2036  objtype_str = "types";
2037  break;
2038  case DEFACLOBJ_NAMESPACE:
2039  objtype_str = "schemas";
2040  break;
2041  default:
2042  ereport(ERROR,
2043  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2044  errmsg("unrecognized default ACL object type \"%c\"", objtype),
2045  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2046  DEFACLOBJ_RELATION,
2047  DEFACLOBJ_SEQUENCE,
2048  DEFACLOBJ_FUNCTION,
2049  DEFACLOBJ_TYPE,
2050  DEFACLOBJ_NAMESPACE)));
2051  }
2052 
2053  /*
2054  * Look up user ID. Behave as "default ACL not found" if the user doesn't
2055  * exist.
2056  */
2059  if (!HeapTupleIsValid(tp))
2060  goto not_found;
2061  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2062  ReleaseSysCache(tp);
2063 
2064  /*
2065  * If a schema name was given, look up its OID. If it doesn't exist,
2066  * behave as "default ACL not found".
2067  */
2068  if (schema)
2069  {
2070  schemaid = get_namespace_oid(schema, true);
2071  if (schemaid == InvalidOid)
2072  goto not_found;
2073  }
2074  else
2075  schemaid = InvalidOid;
2076 
2077  /* Finally, look up the pg_default_acl object */
2079  ObjectIdGetDatum(userid),
2080  ObjectIdGetDatum(schemaid),
2081  CharGetDatum(objtype));
2082  if (!HeapTupleIsValid(tp))
2083  goto not_found;
2084 
2085  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2086  ReleaseSysCache(tp);
2087 
2088  return address;
2089 
2090 not_found:
2091  if (!missing_ok)
2092  {
2093  if (schema)
2094  ereport(ERROR,
2095  (errcode(ERRCODE_UNDEFINED_OBJECT),
2096  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2097  username, schema, objtype_str)));
2098  else
2099  ereport(ERROR,
2100  (errcode(ERRCODE_UNDEFINED_OBJECT),
2101  errmsg("default ACL for user \"%s\" on %s does not exist",
2102  username, objtype_str)));
2103  }
2104  return address;
2105 }
int errhint(const char *fmt,...)
Definition: elog.c:1153
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3086
#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:186
#define linitial(l)
Definition: pg_list.h:176
const char * username
Definition: pgbench.c:305
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:698
static Datum CharGetDatum(char X)
Definition: postgres.h:470
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:1195
@ AUTHNAME
Definition: syscache.h:44
@ DEFACLROLENSPOBJ
Definition: syscache.h:56

References AUTHNAME, CharGetDatum(), CStringGetDatum(), DEFACLROLENSPOBJ, 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 1680 of file objectaddress.c.

1681 {
1682  Oid amoid;
1683  ObjectAddress address;
1684 
1685  /* XXX no missing_ok support here */
1686  amoid = get_index_am_oid(strVal(linitial(object)), false);
1687  object = list_copy_tail(object, 1);
1688 
1689  switch (objtype)
1690  {
1691  case OBJECT_OPCLASS:
1692  address.classId = OperatorClassRelationId;
1693  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1694  address.objectSubId = 0;
1695  break;
1696  case OBJECT_OPFAMILY:
1697  address.classId = OperatorFamilyRelationId;
1698  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1699  address.objectSubId = 0;
1700  break;
1701  default:
1702  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1703  /* placate compiler, which doesn't know elog won't return */
1704  address.classId = InvalidOid;
1705  address.objectId = InvalidOid;
1706  address.objectSubId = 0;
1707  }
1708 
1709  return address;
1710 }
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:1612
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 1718 of file objectaddress.c.

1720 {
1721  ObjectAddress famaddr;
1722  ObjectAddress address;
1723  ListCell *cell;
1724  List *copy;
1725  TypeName *typenames[2];
1726  Oid typeoids[2];
1727  int membernum;
1728  int i;
1729 
1730  /*
1731  * The last element of the object list contains the strategy or procedure
1732  * number. We need to strip that out before getting the opclass/family
1733  * address. The rest can be used directly by get_object_address_opcf().
1734  */
1735  membernum = atoi(strVal(llast(linitial(object))));
1736  copy = list_copy_head(linitial(object), list_length(linitial(object)) - 1);
1737 
1738  /* no missing_ok support here */
1739  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1740 
1741  /* find out left/right type names and OIDs */
1742  typenames[0] = typenames[1] = NULL;
1743  typeoids[0] = typeoids[1] = InvalidOid;
1744  i = 0;
1745  foreach(cell, lsecond(object))
1746  {
1747  ObjectAddress typaddr;
1748 
1749  typenames[i] = lfirst_node(TypeName, cell);
1750  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1751  typeoids[i] = typaddr.objectId;
1752  if (++i >= 2)
1753  break;
1754  }
1755 
1756  switch (objtype)
1757  {
1758  case OBJECT_AMOP:
1759  {
1760  HeapTuple tp;
1761 
1762  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1763  InvalidOid);
1764 
1766  ObjectIdGetDatum(famaddr.objectId),
1767  ObjectIdGetDatum(typeoids[0]),
1768  ObjectIdGetDatum(typeoids[1]),
1769  Int16GetDatum(membernum));
1770  if (!HeapTupleIsValid(tp))
1771  {
1772  if (!missing_ok)
1773  ereport(ERROR,
1774  (errcode(ERRCODE_UNDEFINED_OBJECT),
1775  errmsg("operator %d (%s, %s) of %s does not exist",
1776  membernum,
1777  TypeNameToString(typenames[0]),
1778  TypeNameToString(typenames[1]),
1779  getObjectDescription(&famaddr, false))));
1780  }
1781  else
1782  {
1783  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1784  ReleaseSysCache(tp);
1785  }
1786  }
1787  break;
1788 
1789  case OBJECT_AMPROC:
1790  {
1791  HeapTuple tp;
1792 
1793  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1794  InvalidOid);
1795 
1797  ObjectIdGetDatum(famaddr.objectId),
1798  ObjectIdGetDatum(typeoids[0]),
1799  ObjectIdGetDatum(typeoids[1]),
1800  Int16GetDatum(membernum));
1801  if (!HeapTupleIsValid(tp))
1802  {
1803  if (!missing_ok)
1804  ereport(ERROR,
1805  (errcode(ERRCODE_UNDEFINED_OBJECT),
1806  errmsg("function %d (%s, %s) of %s does not exist",
1807  membernum,
1808  TypeNameToString(typenames[0]),
1809  TypeNameToString(typenames[1]),
1810  getObjectDescription(&famaddr, false))));
1811  }
1812  else
1813  {
1814  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1815  ReleaseSysCache(tp);
1816  }
1817  }
1818  break;
1819  default:
1820  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1821  }
1822 
1823  return address;
1824 }
int i
Definition: isn.c:73
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:174
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:520
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1206
@ AMPROCNUM
Definition: syscache.h:39
@ AMOPSTRATEGY
Definition: syscache.h:38

References AMOPSTRATEGY, AMPROCNUM, 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, 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 1901 of file objectaddress.c.

1903 {
1904  ObjectAddress address;
1905  Relation relation;
1906  List *relname;
1907  char *pubname;
1908  Publication *pub;
1909 
1910  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1911 
1912  relname = linitial(object);
1914  AccessShareLock, missing_ok);
1915  if (!relation)
1916  return address;
1917 
1918  /* fetch publication name from input list */
1919  pubname = strVal(lsecond(object));
1920 
1921  /* Now look up the pg_publication tuple */
1922  pub = GetPublicationByName(pubname, missing_ok);
1923  if (!pub)
1924  {
1925  relation_close(relation, AccessShareLock);
1926  return address;
1927  }
1928 
1929  /* Find the publication relation mapping in syscache. */
1930  address.objectId =
1931  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1933  ObjectIdGetDatum(pub->oid));
1934  if (!OidIsValid(address.objectId))
1935  {
1936  if (!missing_ok)
1937  ereport(ERROR,
1938  (errcode(ERRCODE_UNDEFINED_OBJECT),
1939  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1940  RelationGetRelationName(relation), pubname)));
1941  relation_close(relation, AccessShareLock);
1942  return address;
1943  }
1944 
1945  *relp = relation;
1946  return address;
1947 }
#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:173
@ PUBLICATIONRELMAP
Definition: syscache.h:85
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:199

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, makeRangeVarFromNameList(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, PUBLICATIONRELMAP, 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 1954 of file objectaddress.c.

1955 {
1956  ObjectAddress address;
1957  Publication *pub;
1958  char *pubname;
1959  char *schemaname;
1960  Oid schemaid;
1961 
1962  ObjectAddressSet(address, PublicationNamespaceRelationId, InvalidOid);
1963 
1964  /* Fetch schema name and publication name from input list */
1965  schemaname = strVal(linitial(object));
1966  pubname = strVal(lsecond(object));
1967 
1968  schemaid = get_namespace_oid(schemaname, missing_ok);
1969  if (!OidIsValid(schemaid))
1970  return address;
1971 
1972  /* Now look up the pg_publication tuple */
1973  pub = GetPublicationByName(pubname, missing_ok);
1974  if (!pub)
1975  return address;
1976 
1977  /* Find the publication schema mapping in syscache */
1978  address.objectId =
1980  Anum_pg_publication_namespace_oid,
1981  ObjectIdGetDatum(schemaid),
1982  ObjectIdGetDatum(pub->oid));
1983  if (!OidIsValid(address.objectId) && !missing_ok)
1984  ereport(ERROR,
1985  (errcode(ERRCODE_UNDEFINED_OBJECT),
1986  errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
1987  schemaname, pubname)));
1988 
1989  return address;
1990 }
@ PUBLICATIONNAMESPACEMAP
Definition: syscache.h:82

References ereport, errcode(), errmsg(), ERROR, get_namespace_oid(), GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, PUBLICATIONNAMESPACEMAP, 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 1453 of file objectaddress.c.

1455 {
1456  ObjectAddress address;
1457  Relation relation = NULL;
1458  int nnames;
1459  const char *depname;
1460  List *relname;
1461  Oid reloid;
1462 
1463  /* Extract name of dependent object. */
1464  depname = strVal(llast(object));
1465 
1466  /* Separate relation name from dependent object name. */
1467  nnames = list_length(object);
1468  if (nnames < 2)
1469  ereport(ERROR,
1470  (errcode(ERRCODE_SYNTAX_ERROR),
1471  errmsg("must specify relation and object name")));
1472 
1473  /* Extract relation name and open relation. */
1474  relname = list_copy_head(object, nnames - 1);
1477  missing_ok);
1478 
1479  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1480 
1481  switch (objtype)
1482  {
1483  case OBJECT_RULE:
1484  address.classId = RewriteRelationId;
1485  address.objectId = relation ?
1486  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1487  address.objectSubId = 0;
1488  break;
1489  case OBJECT_TRIGGER:
1490  address.classId = TriggerRelationId;
1491  address.objectId = relation ?
1492  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1493  address.objectSubId = 0;
1494  break;
1495  case OBJECT_TABCONSTRAINT:
1496  address.classId = ConstraintRelationId;
1497  address.objectId = relation ?
1498  get_relation_constraint_oid(reloid, depname, missing_ok) :
1499  InvalidOid;
1500  address.objectSubId = 0;
1501  break;
1502  case OBJECT_POLICY:
1503  address.classId = PolicyRelationId;
1504  address.objectId = relation ?
1505  get_relation_policy_oid(reloid, depname, missing_ok) :
1506  InvalidOid;
1507  address.objectSubId = 0;
1508  break;
1509  default:
1510  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1511  }
1512 
1513  /* Avoid relcache leak when object not found. */
1514  if (!OidIsValid(address.objectId))
1515  {
1516  if (relation != NULL)
1517  table_close(relation, AccessShareLock);
1518 
1519  relation = NULL; /* department of accident prevention */
1520  return address;
1521  }
1522 
1523  /* Done. */
1524  *relp = relation;
1525  return address;
1526 }
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:1207
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:1376

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

1261 {
1262  if (rel)
1263  {
1264  object = lcons(makeString(rel->relname), object);
1265  if (rel->schemaname)
1266  object = lcons(makeString(rel->schemaname), object);
1267  if (rel->catalogname)
1268  object = lcons(makeString(rel->catalogname), object);
1269  }
1270 
1271  return get_object_address(objtype, (Node *) object,
1272  relp, lockmode, missing_ok);
1273 }
List * lcons(void *datum, List *list)
Definition: list.c:494
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:118
char * relname
Definition: primnodes.h:77
char * schemaname
Definition: primnodes.h:74
String * makeString(char *str)
Definition: value.c:63

References 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 1641 of file objectaddress.c.

1642 {
1643  ObjectAddress address;
1644  Type tup;
1645 
1646  address.classId = TypeRelationId;
1647  address.objectId = InvalidOid;
1648  address.objectSubId = 0;
1649 
1650  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1651  if (!HeapTupleIsValid(tup))
1652  {
1653  if (!missing_ok)
1654  ereport(ERROR,
1655  (errcode(ERRCODE_UNDEFINED_OBJECT),
1656  errmsg("type \"%s\" does not exist",
1657  TypeNameToString(typename))));
1658  return address;
1659  }
1660  address.objectId = typeTypeId(tup);
1661 
1662  if (objtype == OBJECT_DOMAIN)
1663  {
1664  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1665  ereport(ERROR,
1666  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1667  errmsg("\"%s\" is not a domain",
1668  TypeNameToString(typename))));
1669  }
1670 
1671  ReleaseSysCache(tup);
1672 
1673  return address;
1674 }
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 1280 of file objectaddress.c.

1282 {
1283  const char *name;
1284  ObjectAddress address;
1285 
1286  name = strVal(strval);
1287 
1288  /* Translate name to OID. */
1289  switch (objtype)
1290  {
1291  case OBJECT_ACCESS_METHOD:
1292  address.classId = AccessMethodRelationId;
1293  address.objectId = get_am_oid(name, missing_ok);
1294  address.objectSubId = 0;
1295  break;
1296  case OBJECT_DATABASE:
1297  address.classId = DatabaseRelationId;
1298  address.objectId = get_database_oid(name, missing_ok);
1299  address.objectSubId = 0;
1300  break;
1301  case OBJECT_EXTENSION:
1302  address.classId = ExtensionRelationId;
1303  address.objectId = get_extension_oid(name, missing_ok);
1304  address.objectSubId = 0;
1305  break;
1306  case OBJECT_TABLESPACE:
1307  address.classId = TableSpaceRelationId;
1308  address.objectId = get_tablespace_oid(name, missing_ok);
1309  address.objectSubId = 0;
1310  break;
1311  case OBJECT_ROLE:
1312  address.classId = AuthIdRelationId;
1313  address.objectId = get_role_oid(name, missing_ok);
1314  address.objectSubId = 0;
1315  break;
1316  case OBJECT_SCHEMA:
1317  address.classId = NamespaceRelationId;
1318  address.objectId = get_namespace_oid(name, missing_ok);
1319  address.objectSubId = 0;
1320  break;
1321  case OBJECT_LANGUAGE:
1322  address.classId = LanguageRelationId;
1323  address.objectId = get_language_oid(name, missing_ok);
1324  address.objectSubId = 0;
1325  break;
1326  case OBJECT_FDW:
1327  address.classId = ForeignDataWrapperRelationId;
1328  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1329  address.objectSubId = 0;
1330  break;
1331  case OBJECT_FOREIGN_SERVER:
1332  address.classId = ForeignServerRelationId;
1333  address.objectId = get_foreign_server_oid(name, missing_ok);
1334  address.objectSubId = 0;
1335  break;
1336  case OBJECT_EVENT_TRIGGER:
1337  address.classId = EventTriggerRelationId;
1338  address.objectId = get_event_trigger_oid(name, missing_ok);
1339  address.objectSubId = 0;
1340  break;
1341  case OBJECT_PARAMETER_ACL:
1342  address.classId = ParameterAclRelationId;
1343  address.objectId = ParameterAclLookup(name, missing_ok);
1344  address.objectSubId = 0;
1345  break;
1346  case OBJECT_PUBLICATION:
1347  address.classId = PublicationRelationId;
1348  address.objectId = get_publication_oid(name, missing_ok);
1349  address.objectSubId = 0;
1350  break;
1351  case OBJECT_SUBSCRIPTION:
1352  address.classId = SubscriptionRelationId;
1353  address.objectId = get_subscription_oid(name, missing_ok);
1354  address.objectSubId = 0;
1355  break;
1356  default:
1357  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1358  /* placate compiler, which doesn't know elog won't return */
1359  address.classId = InvalidOid;
1360  address.objectId = InvalidOid;
1361  address.objectSubId = 0;
1362  }
1363 
1364  return address;
1365 }
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5235
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:1432
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2934
const char * name
Definition: encode.c:561
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:142
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:690
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:667
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition: lsyscache.c:3594
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition: lsyscache.c:3644
Oid ParameterAclLookup(const char *parameter, bool missing_ok)

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

1831 {
1832  ObjectAddress address;
1833  Oid userid;
1834  char *username;
1835  char *servername;
1836  ForeignServer *server;
1837  HeapTuple tp;
1838 
1839  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1840 
1841  /* fetch string names from input lists, for error messages */
1842  username = strVal(linitial(object));
1843  servername = strVal(lsecond(object));
1844 
1845  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1846  if (strcmp(username, "public") == 0)
1847  userid = InvalidOid;
1848  else
1849  {
1852  if (!HeapTupleIsValid(tp))
1853  {
1854  if (!missing_ok)
1855  ereport(ERROR,
1856  (errcode(ERRCODE_UNDEFINED_OBJECT),
1857  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1858  username, servername)));
1859  return address;
1860  }
1861  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1862  ReleaseSysCache(tp);
1863  }
1864 
1865  /* Now look up the pg_user_mapping tuple */
1866  server = GetForeignServerByName(servername, true);
1867  if (!server)
1868  {
1869  if (!missing_ok)
1870  ereport(ERROR,
1871  (errcode(ERRCODE_UNDEFINED_OBJECT),
1872  errmsg("server \"%s\" does not exist", servername)));
1873  return address;
1874  }
1875  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1876  ObjectIdGetDatum(userid),
1877  ObjectIdGetDatum(server->serverid));
1878  if (!HeapTupleIsValid(tp))
1879  {
1880  if (!missing_ok)
1881  ereport(ERROR,
1882  (errcode(ERRCODE_UNDEFINED_OBJECT),
1883  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1884  username, servername)));
1885  return address;
1886  }
1887 
1888  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1889 
1890  ReleaseSysCache(tp);
1891 
1892  return address;
1893 }
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:1184

References AUTHNAME, 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 2716 of file objectaddress.c.

2717 {
2718  const ObjectPropertyType *prop = get_object_property_data(class_id);
2719 
2720  return prop->attnum_acl;
2721 }
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(), and object_aclmask().

◆ 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()

AttrNumber get_object_attnum_owner ( Oid  class_id)

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2676 of file objectaddress.c.

2677 {
2678  const ObjectPropertyType *prop = get_object_property_data(class_id);
2679 
2680  return prop->name_catcache_id;
2681 }

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

int get_object_catcache_oid ( Oid  class_id)

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

Definition at line 2652 of file objectaddress.c.

2653 {
2654  const ObjectPropertyType *prop = get_object_property_data(class_id);
2655 
2656  return prop->class_descr;
2657 }
const char * class_descr

References ObjectPropertyType::class_descr, and get_object_property_data().

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

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2749 of file objectaddress.c.

2750 {
2751  const ObjectPropertyType *prop = get_object_property_data(class_id);
2752 
2753  return prop->is_nsp_name_unique;
2754 }

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

2594 {
2595  int cache;
2596  HeapTuple tuple;
2597  bool isnull;
2598  Oid oid;
2599  const ObjectPropertyType *property;
2600 
2601  /* If not owned by a namespace, just return InvalidOid. */
2602  property = get_object_property_data(address->classId);
2603  if (property->attnum_namespace == InvalidAttrNumber)
2604  return InvalidOid;
2605 
2606  /* Currently, we can only handle object types with system caches. */
2607  cache = property->oid_catcache_id;
2608  Assert(cache != -1);
2609 
2610  /* Fetch tuple from syscache and extract namespace attribute. */
2611  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2612  if (!HeapTupleIsValid(tuple))
2613  elog(ERROR, "cache lookup failed for cache %d oid %u",
2614  cache, address->objectId);
2615  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2616  tuple,
2617  property->attnum_namespace,
2618  &isnull));
2619  Assert(!isnull);
2620  ReleaseSysCache(tuple);
2621 
2622  return oid;
2623 }
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:590
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1434

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

Referenced by RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2660 of file objectaddress.c.

2661 {
2662  const ObjectPropertyType *prop = get_object_property_data(class_id);
2663 
2664  return prop->oid_index_oid;
2665 }

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

2779 {
2780  static const ObjectPropertyType *prop_last = NULL;
2781  int index;
2782 
2783  /*
2784  * A shortcut to speed up multiple consecutive lookups of a particular
2785  * object class.
2786  */
2787  if (prop_last && prop_last->class_oid == class_id)
2788  return prop_last;
2789 
2790  for (index = 0; index < lengthof(ObjectProperty); index++)
2791  {
2792  if (ObjectProperty[index].class_oid == class_id)
2793  {
2794  prop_last = &ObjectProperty[index];
2795  return &ObjectProperty[index];
2796  }
2797  }
2798 
2799  ereport(ERROR,
2800  (errmsg_internal("unrecognized class ID: %u", class_id)));
2801 
2802  return NULL; /* keep MSC compiler happy */
2803 }
#define lengthof(array)
Definition: c.h:724
int errmsg_internal(const char *fmt,...)
Definition: elog.c:993
static const ObjectPropertyType ObjectProperty[]
Definition: type.h:95

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

2732 {
2733  const ObjectPropertyType *prop = get_object_property_data(class_id);
2734 
2735  if (prop->objtype == OBJECT_TABLE)
2736  {
2737  /*
2738  * If the property data says it's a table, dig a little deeper to get
2739  * the real relation kind, so that callers can produce more precise
2740  * error messages.
2741  */
2742  return get_relkind_objtype(get_rel_relkind(object_id));
2743  }
2744  else
2745  return prop->objtype;
2746 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1985
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(), and object_aclmask().

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

1374 {
1375  Relation relation;
1376  ObjectAddress address;
1377 
1378  address.classId = RelationRelationId;
1379  address.objectId = InvalidOid;
1380  address.objectSubId = 0;
1381 
1383  lockmode, missing_ok);
1384  if (!relation)
1385  return address;
1386 
1387  switch (objtype)
1388  {
1389  case OBJECT_INDEX:
1390  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1391  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1392  ereport(ERROR,
1393  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1394  errmsg("\"%s\" is not an index",
1395  RelationGetRelationName(relation))));
1396  break;
1397  case OBJECT_SEQUENCE:
1398  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1399  ereport(ERROR,
1400  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1401  errmsg("\"%s\" is not a sequence",
1402  RelationGetRelationName(relation))));
1403  break;
1404  case OBJECT_TABLE:
1405  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1406  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1407  ereport(ERROR,
1408  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1409  errmsg("\"%s\" is not a table",
1410  RelationGetRelationName(relation))));
1411  break;
1412  case OBJECT_VIEW:
1413  if (relation->rd_rel->relkind != RELKIND_VIEW)
1414  ereport(ERROR,
1415  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1416  errmsg("\"%s\" is not a view",
1417  RelationGetRelationName(relation))));
1418  break;
1419  case OBJECT_MATVIEW:
1420  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1421  ereport(ERROR,
1422  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1423  errmsg("\"%s\" is not a materialized view",
1424  RelationGetRelationName(relation))));
1425  break;
1426  case OBJECT_FOREIGN_TABLE:
1427  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1428  ereport(ERROR,
1429  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1430  errmsg("\"%s\" is not a foreign table",
1431  RelationGetRelationName(relation))));
1432  break;
1433  default:
1434  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1435  break;
1436  }
1437 
1438  /* Done. */
1439  address.objectId = RelationGetRelid(relation);
1440  *relp = relation;
1441 
1442  return address;
1443 }
Form_pg_class rd_rel
Definition: rel.h:110

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

6125 {
6126  switch (relkind)
6127  {
6128  case RELKIND_RELATION:
6129  case RELKIND_PARTITIONED_TABLE:
6130  return OBJECT_TABLE;
6131  case RELKIND_INDEX:
6132  case RELKIND_PARTITIONED_INDEX:
6133  return OBJECT_INDEX;
6134  case RELKIND_SEQUENCE:
6135  return OBJECT_SEQUENCE;
6136  case RELKIND_VIEW:
6137  return OBJECT_VIEW;
6138  case RELKIND_MATVIEW:
6139  return OBJECT_MATVIEW;
6140  case RELKIND_FOREIGN_TABLE:
6141  return OBJECT_FOREIGN_TABLE;
6142  case RELKIND_TOASTVALUE:
6143  return OBJECT_TABLE;
6144  default:
6145  /* Per above, don't raise an error */
6146  return OBJECT_TABLE;
6147  }
6148 }

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(), ExecCheckRTPerms(), get_object_type(), get_rel_from_relname(), heap_force_common(), LockViewRecurse_walker(), LogicalRepSyncTableStart(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), TargetPrivilegesCheck(), transformTableLikeClause(), and truncate_check_perms().

◆ getConstraintTypeDescription()

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

Definition at line 4688 of file objectaddress.c.

4689 {
4690  Relation constrRel;
4691  HeapTuple constrTup;
4692  Form_pg_constraint constrForm;
4693 
4694  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4695  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4696  constroid);
4697  if (!HeapTupleIsValid(constrTup))
4698  {
4699  if (!missing_ok)
4700  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4701 
4702  table_close(constrRel, AccessShareLock);
4703 
4704  /* fallback to "constraint" for an undefined object */
4705  appendStringInfoString(buffer, "constraint");
4706  return;
4707  }
4708 
4709  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4710 
4711  if (OidIsValid(constrForm->conrelid))
4712  appendStringInfoString(buffer, "table constraint");
4713  else if (OidIsValid(constrForm->contypid))
4714  appendStringInfoString(buffer, "domain constraint");
4715  else
4716  elog(ERROR, "invalid constraint %u", constrForm->oid);
4717 
4718  table_close(constrRel, AccessShareLock);
4719 }
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
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 2910 of file objectaddress.c.

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

References _, AccessShareLock, AMOID, appendStringInfo(), Assert(), attname, BTEqualStrategyNumber, CLAOID, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, elog(), ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), 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(), getObjectClass(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_ROLE_MEMBERSHIP, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), PARAMETERACLOID, pfree(), proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TRFOID, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, typname, USERMAPPINGOID, and username.

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4067 of file objectaddress.c.

4068 {
4069  ObjectAddress address;
4070 
4071  address.classId = classid;
4072  address.objectId = objid;
4073  address.objectSubId = 0;
4074 
4075  return getObjectDescription(&address, false);
4076 }

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

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