PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
alter.h File Reference
Include dependency graph for alter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ObjectAddress ExecRenameStmt (RenameStmt *stmt)
 
ObjectAddress ExecAlterObjectDependsStmt (AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
 
ObjectAddress ExecAlterObjectSchemaStmt (AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
 
Oid AlterObjectNamespace_oid (Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
 
ObjectAddress ExecAlterOwnerStmt (AlterOwnerStmt *stmt)
 
void AlterObjectOwner_internal (Relation catalog, Oid objectId, Oid new_ownerId)
 

Function Documentation

Oid AlterObjectNamespace_oid ( Oid  classId,
Oid  objid,
Oid  nspOid,
ObjectAddresses objsMoved 
)

Definition at line 531 of file alter.c.

References AccessExclusiveLock, AlterObjectNamespace_internal(), AlterTableNamespaceInternal(), AlterTypeNamespace_oid(), ObjectAddress::classId, getObjectClass(), heap_close, heap_open(), InvalidOid, NoLock, ObjectAddress::objectId, ObjectAddress::objectSubId, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONVERSION, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PROC, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, relation_close(), relation_open(), RelationGetNamespace, and RowExclusiveLock.

Referenced by AlterExtensionNamespace().

533 {
534  Oid oldNspOid = InvalidOid;
535  ObjectAddress dep;
536 
537  dep.classId = classId;
538  dep.objectId = objid;
539  dep.objectSubId = 0;
540 
541  switch (getObjectClass(&dep))
542  {
543  case OCLASS_CLASS:
544  {
545  Relation rel;
546 
547  rel = relation_open(objid, AccessExclusiveLock);
548  oldNspOid = RelationGetNamespace(rel);
549 
550  AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
551 
552  relation_close(rel, NoLock);
553  break;
554  }
555 
556  case OCLASS_TYPE:
557  oldNspOid = AlterTypeNamespace_oid(objid, nspOid, objsMoved);
558  break;
559 
560  case OCLASS_COLLATION:
561  case OCLASS_CONVERSION:
562  case OCLASS_OPERATOR:
563  case OCLASS_OPCLASS:
564  case OCLASS_OPFAMILY:
565  case OCLASS_PROC:
566  case OCLASS_TSPARSER:
567  case OCLASS_TSDICT:
568  case OCLASS_TSTEMPLATE:
569  case OCLASS_TSCONFIG:
570  {
571  Relation catalog;
572 
573  catalog = heap_open(classId, RowExclusiveLock);
574 
575  oldNspOid = AlterObjectNamespace_internal(catalog, objid,
576  nspOid);
577 
578  heap_close(catalog, RowExclusiveLock);
579  }
580  break;
581 
582  default:
583  break;
584  }
585 
586  return oldNspOid;
587 }
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition: alter.c:601
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1263
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2312
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: tablecmds.c:12135
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: typecmds.c:3453
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define AccessExclusiveLock
Definition: lockdefs.h:46
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1117
#define RelationGetNamespace(relation)
Definition: rel.h:440
void AlterObjectOwner_internal ( Relation  catalog,
Oid  objectId,
Oid  new_ownerId 
)

Definition at line 843 of file alter.c.

References ACL_CREATE, ACL_KIND_NAMESPACE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, aclnewowner(), Assert, CatalogTupleUpdate(), changeDependencyOnOwner(), check_is_member_of_role(), DatumGetAclP, DatumGetName, DatumGetObjectId, elog, ERROR, get_catalog_object_by_oid(), get_namespace_name(), get_object_aclkind(), get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_owner(), GetUserId(), has_privs_of_role(), heap_getattr, heap_modify_tuple(), HeapTupleGetOid, InvalidAttrNumber, InvalidOid, InvokeObjectPostAlterHook, LargeObjectMetadataRelationId, LargeObjectRelationId, NAMEDATALEN, NameStr, NULL, ObjectIdGetDatum, OidIsValid, palloc0(), pfree(), pg_namespace_aclcheck(), PointerGetDatum, RelationGetDescr, RelationGetNumberOfAttributes, RelationGetRelationName, RelationGetRelid, snprintf(), superuser(), HeapTupleData::t_self, and values.

Referenced by ExecAlterOwnerStmt(), and shdepReassignOwned().

844 {
845  Oid classId = RelationGetRelid(rel);
846  AttrNumber Anum_owner = get_object_attnum_owner(classId);
847  AttrNumber Anum_namespace = get_object_attnum_namespace(classId);
848  AttrNumber Anum_acl = get_object_attnum_acl(classId);
849  AttrNumber Anum_name = get_object_attnum_name(classId);
850  HeapTuple oldtup;
851  Datum datum;
852  bool isnull;
853  Oid old_ownerId;
854  Oid namespaceId = InvalidOid;
855 
856  oldtup = get_catalog_object_by_oid(rel, objectId);
857  if (oldtup == NULL)
858  elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
859  objectId, RelationGetRelationName(rel));
860 
861  datum = heap_getattr(oldtup, Anum_owner,
862  RelationGetDescr(rel), &isnull);
863  Assert(!isnull);
864  old_ownerId = DatumGetObjectId(datum);
865 
866  if (Anum_namespace != InvalidAttrNumber)
867  {
868  datum = heap_getattr(oldtup, Anum_namespace,
869  RelationGetDescr(rel), &isnull);
870  Assert(!isnull);
871  namespaceId = DatumGetObjectId(datum);
872  }
873 
874  if (old_ownerId != new_ownerId)
875  {
876  AttrNumber nattrs;
877  HeapTuple newtup;
878  Datum *values;
879  bool *nulls;
880  bool *replaces;
881 
882  /* Superusers can bypass permission checks */
883  if (!superuser())
884  {
885  AclObjectKind aclkind = get_object_aclkind(classId);
886 
887  /* must be owner */
888  if (!has_privs_of_role(GetUserId(), old_ownerId))
889  {
890  char *objname;
891  char namebuf[NAMEDATALEN];
892 
893  if (Anum_name != InvalidAttrNumber)
894  {
895  datum = heap_getattr(oldtup, Anum_name,
896  RelationGetDescr(rel), &isnull);
897  Assert(!isnull);
898  objname = NameStr(*DatumGetName(datum));
899  }
900  else
901  {
902  snprintf(namebuf, sizeof(namebuf), "%u",
903  HeapTupleGetOid(oldtup));
904  objname = namebuf;
905  }
906  aclcheck_error(ACLCHECK_NOT_OWNER, aclkind, objname);
907  }
908  /* Must be able to become new owner */
909  check_is_member_of_role(GetUserId(), new_ownerId);
910 
911  /* New owner must have CREATE privilege on namespace */
912  if (OidIsValid(namespaceId))
913  {
914  AclResult aclresult;
915 
916  aclresult = pg_namespace_aclcheck(namespaceId, new_ownerId,
917  ACL_CREATE);
918  if (aclresult != ACLCHECK_OK)
920  get_namespace_name(namespaceId));
921  }
922  }
923 
924  /* Build a modified tuple */
925  nattrs = RelationGetNumberOfAttributes(rel);
926  values = palloc0(nattrs * sizeof(Datum));
927  nulls = palloc0(nattrs * sizeof(bool));
928  replaces = palloc0(nattrs * sizeof(bool));
929  values[Anum_owner - 1] = ObjectIdGetDatum(new_ownerId);
930  replaces[Anum_owner - 1] = true;
931 
932  /*
933  * Determine the modified ACL for the new owner. This is only
934  * necessary when the ACL is non-null.
935  */
936  if (Anum_acl != InvalidAttrNumber)
937  {
938  datum = heap_getattr(oldtup,
939  Anum_acl, RelationGetDescr(rel), &isnull);
940  if (!isnull)
941  {
942  Acl *newAcl;
943 
944  newAcl = aclnewowner(DatumGetAclP(datum),
945  old_ownerId, new_ownerId);
946  values[Anum_acl - 1] = PointerGetDatum(newAcl);
947  replaces[Anum_acl - 1] = true;
948  }
949  }
950 
951  newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
952  values, nulls, replaces);
953 
954  /* Perform actual update */
955  CatalogTupleUpdate(rel, &newtup->t_self, newtup);
956 
957  /* Update owner dependency reference */
958  if (classId == LargeObjectMetadataRelationId)
959  classId = LargeObjectRelationId;
960  changeDependencyOnOwner(classId, HeapTupleGetOid(newtup), new_ownerId);
961 
962  /* Release memory */
963  pfree(values);
964  pfree(nulls);
965  pfree(replaces);
966  }
967 
968  InvokeObjectPostAlterHook(classId, objectId, 0);
969 }
AttrNumber get_object_attnum_owner(Oid class_id)
#define RelationGetDescr(relation)
Definition: rel.h:425
Oid GetUserId(void)
Definition: miscinit.c:282
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:419
#define DatumGetAclP(X)
Definition: acl.h:113
#define PointerGetDatum(X)
Definition: postgres.h:564
#define DatumGetObjectId(X)
Definition: postgres.h:508
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4831
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
AttrNumber get_object_attnum_namespace(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4459
#define NAMEDATALEN
#define DatumGetName(X)
Definition: postgres.h:593
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:303
void pfree(void *pointer)
Definition: mcxt.c:992
AclObjectKind get_object_aclkind(Oid class_id)
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:75
ItemPointerData t_self
Definition: htup.h:65
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3006
AttrNumber get_object_attnum_acl(Oid class_id)
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RelationGetRelationName(relation)
Definition: rel.h:433
void check_is_member_of_role(Oid member, Oid role)
Definition: acl.c:4877
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:163
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:769
AttrNumber get_object_attnum_name(Oid class_id)
void * palloc0(Size size)
Definition: mcxt.c:920
AclResult
Definition: acl.h:170
uintptr_t Datum
Definition: postgres.h:374
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define LargeObjectMetadataRelationId
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
HeapTuple get_catalog_object_by_oid(Relation catalog, Oid objectId)
#define InvalidAttrNumber
Definition: attnum.h:23
static Datum values[MAXATTR]
Definition: bootstrap.c:162
#define NameStr(name)
Definition: c.h:495
#define elog
Definition: elog.h:219
AclObjectKind
Definition: acl.h:179
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:793
#define LargeObjectRelationId
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
Definition: acl.c:1036
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:413
ObjectAddress ExecAlterObjectDependsStmt ( AlterObjectDependsStmt stmt,
ObjectAddress refAddress 
)

Definition at line 402 of file alter.c.

References AccessExclusiveLock, Assert, DEPENDENCY_AUTO_EXTENSION, AlterObjectDependsStmt::extname, get_object_address(), get_object_address_rv(), heap_close, list_make1, NoLock, NULL, AlterObjectDependsStmt::objargs, OBJECT_EXTENSION, AlterObjectDependsStmt::objectType, AlterObjectDependsStmt::objname, recordDependencyOn(), and AlterObjectDependsStmt::relation.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

403 {
404  ObjectAddress address;
405  ObjectAddress refAddr;
406  Relation rel;
407 
408  address =
409  get_object_address_rv(stmt->objectType, stmt->relation, stmt->objname,
410  stmt->objargs, &rel, AccessExclusiveLock, false);
411 
412  /*
413  * If a relation was involved, it would have been opened and locked. We
414  * don't need the relation here, but we'll retain the lock until commit.
415  */
416  if (rel)
417  heap_close(rel, NoLock);
418 
420  NULL, &rel, AccessExclusiveLock, false);
421  Assert(rel == NULL);
422  if (refAddress)
423  *refAddress = refAddr;
424 
425  recordDependencyOn(&address, &refAddr, DEPENDENCY_AUTO_EXTENSION);
426 
427  return address;
428 }
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
#define heap_close(r, l)
Definition: heapam.h:97
#define list_make1(x1)
Definition: pg_list.h:133
#define NoLock
Definition: lockdefs.h:34
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
ObjectAddress get_object_address_rv(ObjectType objtype, RangeVar *rel, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define AccessExclusiveLock
Definition: lockdefs.h:46
ObjectAddress ExecAlterObjectSchemaStmt ( AlterObjectSchemaStmt stmt,
ObjectAddress oldSchemaAddr 
)

Definition at line 440 of file alter.c.

References AccessExclusiveLock, AlterExtensionNamespace(), AlterObjectNamespace_internal(), AlterTableNamespace(), AlterTypeNamespace(), Assert, ObjectAddress::classId, elog, ERROR, get_object_address(), heap_close, heap_open(), InvalidObjectAddress, LookupCreationNamespace(), NamespaceRelationId, AlterObjectSchemaStmt::newschema, NULL, AlterObjectSchemaStmt::objarg, AlterObjectSchemaStmt::object, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_CONVERSION, OBJECT_DOMAIN, OBJECT_EXTENSION, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddressSet, ObjectAddress::objectId, AlterObjectSchemaStmt::objectType, and RowExclusiveLock.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

442 {
443  ObjectAddress address;
444  Oid oldNspOid;
445 
446  switch (stmt->objectType)
447  {
448  case OBJECT_EXTENSION:
449  address = AlterExtensionNamespace(stmt->object, stmt->newschema,
450  oldSchemaAddr ? &oldNspOid : NULL);
451  break;
452 
454  case OBJECT_SEQUENCE:
455  case OBJECT_TABLE:
456  case OBJECT_VIEW:
457  case OBJECT_MATVIEW:
458  address = AlterTableNamespace(stmt,
459  oldSchemaAddr ? &oldNspOid : NULL);
460  break;
461 
462  case OBJECT_DOMAIN:
463  case OBJECT_TYPE:
464  address = AlterTypeNamespace(stmt->object, stmt->newschema,
465  stmt->objectType,
466  oldSchemaAddr ? &oldNspOid : NULL);
467  break;
468 
469  /* generic code path */
470  case OBJECT_AGGREGATE:
471  case OBJECT_COLLATION:
472  case OBJECT_CONVERSION:
473  case OBJECT_FUNCTION:
474  case OBJECT_OPERATOR:
475  case OBJECT_OPCLASS:
476  case OBJECT_OPFAMILY:
478  case OBJECT_TSDICTIONARY:
479  case OBJECT_TSPARSER:
480  case OBJECT_TSTEMPLATE:
481  {
482  Relation catalog;
483  Relation relation;
484  Oid classId;
485  Oid nspOid;
486 
487  address = get_object_address(stmt->objectType,
488  stmt->object,
489  stmt->objarg,
490  &relation,
492  false);
493  Assert(relation == NULL);
494  classId = address.classId;
495  catalog = heap_open(classId, RowExclusiveLock);
496  nspOid = LookupCreationNamespace(stmt->newschema);
497 
498  oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
499  nspOid);
500  heap_close(catalog, RowExclusiveLock);
501  }
502  break;
503 
504  default:
505  elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
506  (int) stmt->objectType);
507  return InvalidObjectAddress; /* keep compiler happy */
508  }
509 
510  if (oldSchemaAddr)
511  ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid);
512 
513  return address;
514 }
#define NamespaceRelationId
Definition: pg_namespace.h:34
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:2730
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
Definition: typecmds.c:3416
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition: alter.c:601
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
Definition: tablecmds.c:12065
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
ObjectAddress AlterExtensionNamespace(List *names, const char *newschema, Oid *oldschema)
Definition: extension.c:2675
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define AccessExclusiveLock
Definition: lockdefs.h:46
const ObjectAddress InvalidObjectAddress
#define elog
Definition: elog.h:219
ObjectAddress ExecAlterOwnerStmt ( AlterOwnerStmt stmt)

Definition at line 745 of file alter.c.

References AccessExclusiveLock, AlterDatabaseOwner(), AlterEventTriggerOwner(), AlterForeignDataWrapperOwner(), AlterForeignServerOwner(), AlterObjectOwner_internal(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSubscriptionOwner(), AlterTypeOwner(), Assert, ObjectAddress::classId, elog, ERROR, get_object_address(), get_rolespec_oid(), heap_close, heap_open(), InvalidObjectAddress, LargeObjectMetadataRelationId, LargeObjectRelationId, linitial, AlterOwnerStmt::newowner, NULL, AlterOwnerStmt::objarg, AlterOwnerStmt::object, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FUNCTION, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PUBLICATION, OBJECT_SCHEMA, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TYPE, ObjectAddress::objectId, AlterOwnerStmt::objectType, RowExclusiveLock, and strVal.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

746 {
747  Oid newowner = get_rolespec_oid(stmt->newowner, false);
748 
749  switch (stmt->objectType)
750  {
751  case OBJECT_DATABASE:
752  return AlterDatabaseOwner(strVal(linitial(stmt->object)), newowner);
753 
754  case OBJECT_SCHEMA:
755  return AlterSchemaOwner(strVal(linitial(stmt->object)), newowner);
756 
757  case OBJECT_TYPE:
758  case OBJECT_DOMAIN: /* same as TYPE */
759  return AlterTypeOwner(stmt->object, newowner, stmt->objectType);
760 
761  case OBJECT_FDW:
763  newowner);
764 
767  newowner);
768 
771  newowner);
772 
773  case OBJECT_PUBLICATION:
775  newowner);
776 
777  case OBJECT_SUBSCRIPTION:
779  newowner);
780 
781  /* Generic cases */
782  case OBJECT_AGGREGATE:
783  case OBJECT_COLLATION:
784  case OBJECT_CONVERSION:
785  case OBJECT_FUNCTION:
786  case OBJECT_LANGUAGE:
787  case OBJECT_LARGEOBJECT:
788  case OBJECT_OPERATOR:
789  case OBJECT_OPCLASS:
790  case OBJECT_OPFAMILY:
791  case OBJECT_TABLESPACE:
792  case OBJECT_TSDICTIONARY:
794  {
795  Relation catalog;
796  Relation relation;
797  Oid classId;
798  ObjectAddress address;
799 
800  address = get_object_address(stmt->objectType,
801  stmt->object,
802  stmt->objarg,
803  &relation,
805  false);
806  Assert(relation == NULL);
807  classId = address.classId;
808 
809  /*
810  * XXX - get_object_address returns Oid of pg_largeobject
811  * catalog for OBJECT_LARGEOBJECT because of historical
812  * reasons. Fix up it here.
813  */
814  if (classId == LargeObjectRelationId)
816 
817  catalog = heap_open(classId, RowExclusiveLock);
818 
819  AlterObjectOwner_internal(catalog, address.objectId, newowner);
820  heap_close(catalog, RowExclusiveLock);
821 
822  return address;
823  }
824  break;
825 
826  default:
827  elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
828  (int) stmt->objectType);
829  return InvalidObjectAddress; /* keep compiler happy */
830  }
831 }
RoleSpec * newowner
Definition: parsenodes.h:2729
ObjectType objectType
Definition: parsenodes.h:2725
#define strVal(v)
Definition: value.h:54
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
Definition: typecmds.c:3212
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
Definition: foreigncmds.c:277
void AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
Definition: alter.c:843
#define RowExclusiveLock
Definition: lockdefs.h:38
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition: acl.c:5147
ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
Definition: schemacmds.c:320
#define Assert(condition)
Definition: c.h:671
ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId)
Definition: foreigncmds.c:414
#define LargeObjectMetadataRelationId
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
Definition: dbcommands.c:1593
#define AccessExclusiveLock
Definition: lockdefs.h:46
const ObjectAddress InvalidObjectAddress
#define elog
Definition: elog.h:219
#define LargeObjectRelationId
ObjectAddress ExecRenameStmt ( RenameStmt stmt)

Definition at line 307 of file alter.c.

References AccessExclusiveLock, AlterObjectRename_internal(), Assert, ObjectAddress::classId, elog, ERROR, get_object_address(), heap_close, heap_open(), InvalidObjectAddress, RenameStmt::newname, NULL, RenameStmt::objarg, RenameStmt::object, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_ROLE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddress::objectId, RenameStmt::relation, rename_policy(), renameatt(), RenameConstraint(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameStmt::renameType, RenameType(), RowExclusiveLock, and RenameStmt::subname.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

308 {
309  switch (stmt->renameType)
310  {
313  return RenameConstraint(stmt);
314 
315  case OBJECT_DATABASE:
316  return RenameDatabase(stmt->subname, stmt->newname);
317 
318  case OBJECT_ROLE:
319  return RenameRole(stmt->subname, stmt->newname);
320 
321  case OBJECT_SCHEMA:
322  return RenameSchema(stmt->subname, stmt->newname);
323 
324  case OBJECT_TABLESPACE:
325  return RenameTableSpace(stmt->subname, stmt->newname);
326 
327  case OBJECT_TABLE:
328  case OBJECT_SEQUENCE:
329  case OBJECT_VIEW:
330  case OBJECT_MATVIEW:
331  case OBJECT_INDEX:
333  return RenameRelation(stmt);
334 
335  case OBJECT_COLUMN:
336  case OBJECT_ATTRIBUTE:
337  return renameatt(stmt);
338 
339  case OBJECT_RULE:
340  return RenameRewriteRule(stmt->relation, stmt->subname,
341  stmt->newname);
342 
343  case OBJECT_TRIGGER:
344  return renametrig(stmt);
345 
346  case OBJECT_POLICY:
347  return rename_policy(stmt);
348 
349  case OBJECT_DOMAIN:
350  case OBJECT_TYPE:
351  return RenameType(stmt);
352 
353  case OBJECT_AGGREGATE:
354  case OBJECT_COLLATION:
355  case OBJECT_CONVERSION:
357  case OBJECT_FDW:
359  case OBJECT_FUNCTION:
360  case OBJECT_OPCLASS:
361  case OBJECT_OPFAMILY:
362  case OBJECT_LANGUAGE:
364  case OBJECT_TSDICTIONARY:
365  case OBJECT_TSPARSER:
366  case OBJECT_TSTEMPLATE:
367  {
368  ObjectAddress address;
369  Relation catalog;
370  Relation relation;
371 
372  address = get_object_address(stmt->renameType,
373  stmt->object, stmt->objarg,
374  &relation,
375  AccessExclusiveLock, false);
376  Assert(relation == NULL);
377 
378  catalog = heap_open(address.classId, RowExclusiveLock);
380  address.objectId,
381  stmt->newname);
382  heap_close(catalog, RowExclusiveLock);
383 
384  return address;
385  }
386 
387  default:
388  elog(ERROR, "unrecognized rename stmt type: %d",
389  (int) stmt->renameType);
390  return InvalidObjectAddress; /* keep compiler happy */
391  }
392 }
ObjectAddress RenameSchema(const char *oldname, const char *newname)
Definition: schemacmds.c:241
ObjectAddress RenameType(RenameStmt *stmt)
Definition: typecmds.c:3134
char * subname
Definition: parsenodes.h:2682
ObjectType renameType
Definition: parsenodes.h:2677
ObjectAddress RenameRelation(RenameStmt *stmt)
Definition: tablecmds.c:2810
#define heap_close(r, l)
Definition: heapam.h:97
char * newname
Definition: parsenodes.h:2684
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
Definition: dbcommands.c:969
List * objarg
Definition: parsenodes.h:2681
#define ERROR
Definition: elog.h:43
ObjectAddress rename_policy(RenameStmt *stmt)
Definition: policy.c:1201
#define RowExclusiveLock
Definition: lockdefs.h:38
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
ObjectAddress renametrig(RenameStmt *stmt)
Definition: trigger.c:1364
ObjectAddress renameatt(RenameStmt *stmt)
Definition: tablecmds.c:2622
ObjectAddress RenameConstraint(RenameStmt *stmt)
Definition: tablecmds.c:2759
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
RangeVar * relation
Definition: parsenodes.h:2679
ObjectAddress RenameRole(const char *oldname, const char *newname)
Definition: user.c:1121
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
Definition: alter.c:154
ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName)
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
Definition: tablespace.c:910
#define AccessExclusiveLock
Definition: lockdefs.h:46
const ObjectAddress InvalidObjectAddress
#define elog
Definition: elog.h:219
List * object
Definition: parsenodes.h:2680