26 #include "catalog/pg_database_d.h"
81 case EventTriggerRelationId:
82 msgfmt =
gettext_noop(
"event trigger \"%s\" already exists");
84 case ForeignDataWrapperRelationId:
85 msgfmt =
gettext_noop(
"foreign-data wrapper \"%s\" already exists");
87 case ForeignServerRelationId:
90 case LanguageRelationId:
93 case PublicationRelationId:
94 msgfmt =
gettext_noop(
"publication \"%s\" already exists");
96 case SubscriptionRelationId:
97 msgfmt =
gettext_noop(
"subscription \"%s\" already exists");
100 elog(
ERROR,
"unsupported object class: %u", classId);
118 case ConversionRelationId:
120 msgfmt =
gettext_noop(
"conversion \"%s\" already exists in schema \"%s\"");
122 case StatisticExtRelationId:
124 msgfmt =
gettext_noop(
"statistics object \"%s\" already exists in schema \"%s\"");
126 case TSParserRelationId:
128 msgfmt =
gettext_noop(
"text search parser \"%s\" already exists in schema \"%s\"");
130 case TSDictionaryRelationId:
132 msgfmt =
gettext_noop(
"text search dictionary \"%s\" already exists in schema \"%s\"");
134 case TSTemplateRelationId:
136 msgfmt =
gettext_noop(
"text search template \"%s\" already exists in schema \"%s\"");
138 case TSConfigRelationId:
140 msgfmt =
gettext_noop(
"text search configuration \"%s\" already exists in schema \"%s\"");
143 elog(
ERROR,
"unsupported object class: %u", classId);
187 elog(
ERROR,
"cache lookup failed for object %u of catalog \"%s\"",
196 if (Anum_namespace > 0)
212 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
213 errmsg(
"must be superuser to rename %s",
236 if (classId == SubscriptionRelationId)
252 if (!form->subpasswordrequired && !
superuser())
254 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
255 errmsg(
"password_required=false is superuser-only"),
256 errhint(
"Subscriptions with the password_required option set to false may only be created or modified by the superuser.")));
265 if (classId == ProcedureRelationId)
270 &proc->proargtypes, proc->pronamespace);
272 else if (classId == CollationRelationId)
278 else if (classId == OperatorClassRelationId)
285 else if (classId == OperatorFamilyRelationId)
292 else if (classId == SubscriptionRelationId)
300 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
301 if (strncmp(new_name,
"regress_", 8) != 0)
302 elog(
WARNING,
"subscriptions created by regression test cases should have names starting with \"regress_\"");
308 else if (nameCacheId >= 0)
331 replaces[Anum_name - 1] =
true;
358 switch (
stmt->renameType)
440 elog(
ERROR,
"unrecognized rename stmt type: %d",
441 (
int)
stmt->renameType);
473 stmt->objectType, address,
stmt->object, rel);
485 *refAddress = refAddr;
523 switch (
stmt->objectType)
527 oldSchemaAddr ? &oldNspOid : NULL);
536 oldSchemaAddr ? &oldNspOid : NULL);
543 oldSchemaAddr ? &oldNspOid : NULL);
582 elog(
ERROR,
"unrecognized AlterObjectSchemaStmt type: %d",
583 (
int)
stmt->objectType);
615 case RelationRelationId:
632 case ProcedureRelationId:
633 case CollationRelationId:
634 case ConversionRelationId:
635 case OperatorRelationId:
636 case OperatorClassRelationId:
637 case OperatorFamilyRelationId:
638 case StatisticExtRelationId:
639 case TSParserRelationId:
640 case TSDictionaryRelationId:
641 case TSTemplateRelationId:
642 case TSConfigRelationId:
695 elog(
ERROR,
"cache lookup failed for object %u of catalog \"%s\"",
709 if (oldNspOid == nspOid)
728 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
729 errmsg(
"must be superuser to set schema of %s",
753 if (classId == ProcedureRelationId)
758 &proc->proargtypes, nspOid);
760 else if (classId == CollationRelationId)
766 else if (classId == OperatorClassRelationId)
771 opc->opcmethod, nspOid);
773 else if (classId == OperatorFamilyRelationId)
778 opf->opfmethod, nspOid);
780 else if (nameCacheId >= 0 &&
792 replaces[Anum_namespace - 1] =
true;
806 NamespaceRelationId, oldNspOid, nspOid) != 1)
807 elog(
ERROR,
"could not change schema dependency for object %u",
824 switch (
stmt->objectType)
890 elog(
ERROR,
"unrecognized AlterOwnerStmt type: %d",
891 (
int)
stmt->objectType);
912 Oid catalogId = (classId == LargeObjectRelationId) ? LargeObjectMetadataRelationId : classId;
929 elog(
ERROR,
"cache lookup failed for object %u of catalog \"%s\"",
945 if (old_ownerId != new_ownerId)
971 snprintf(namebuf,
sizeof(namebuf),
"%u", objectId);
986 aclresult =
object_aclcheck(NamespaceRelationId, namespaceId, new_ownerId,
997 nulls =
palloc0(nattrs *
sizeof(
bool));
998 replaces =
palloc0(nattrs *
sizeof(
bool));
1000 replaces[Anum_owner - 1] =
true;
1015 old_ownerId, new_ownerId);
1017 replaces[Anum_acl - 1] =
true;
1022 values, nulls, replaces);
bool has_privs_of_role(Oid member, Oid role)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
static void report_name_conflict(Oid classId, const char *name)
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
static void report_namespace_conflict(Oid classId, const char *name, Oid nspOid)
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
void AlterObjectOwner_internal(Oid classId, Oid objectId, Oid new_ownerId)
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
#define InvalidAttrNumber
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
void LogicalRepWorkersWakeupAtCommit(Oid subid)
static Datum values[MAXATTR]
#define Assert(condition)
#define OidIsValid(objectId)
void IsThereCollationInNamespace(const char *collname, Oid nspOid)
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
char * get_database_name(Oid dbid)
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
@ DEPENDENCY_AUTO_EXTENSION
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
void IsThereFunctionInNamespace(const char *proname, int pronargs, oidvector *proargtypes, Oid nspOid)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
bool list_member_oid(const List *list, Oid datum)
#define AccessExclusiveLock
char * get_namespace_name(Oid nspid)
void pfree(void *pointer)
void * palloc0(Size size)
void namestrcpy(Name name, const char *str)
Oid LookupCreationNamespace(const char *nspname)
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
#define castNode(_type_, nodeptr)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
int get_object_catcache_name(Oid class_id)
ObjectAddress get_object_address_rv(ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
AttrNumber get_object_attnum_owner(Oid class_id)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
AttrNumber get_object_attnum_oid(Oid class_id)
char * getObjectDescriptionOids(Oid classid, Oid objid)
AttrNumber get_object_attnum_namespace(Oid class_id)
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
AttrNumber get_object_attnum_name(Oid class_id)
AttrNumber get_object_attnum_acl(Oid class_id)
int get_object_catcache_oid(Oid class_id)
const ObjectAddress InvalidObjectAddress
ObjectType get_object_type(Oid class_id, Oid object_id)
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define ObjectAddressSet(addr, class_id, object_id)
void IsThereOpFamilyInNamespace(const char *opfname, Oid opfmethod, Oid opfnamespace)
void IsThereOpClassInNamespace(const char *opcname, Oid opcmethod, Oid opcnamespace)
FormData_pg_collation * Form_pg_collation
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
FormData_pg_opclass * Form_pg_opclass
FormData_pg_opfamily * Form_pg_opfamily
FormData_pg_proc * Form_pg_proc
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
FormData_pg_subscription * Form_pg_subscription
ObjectAddress rename_policy(RenameStmt *stmt)
static Datum PointerGetDatum(const void *X)
static Name DatumGetName(Datum X)
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *X)
ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName)
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
ObjectAddress RenameSchema(const char *oldname, const char *newname)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
#define ERRCODE_DUPLICATE_OBJECT
ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists2(cacheId, key1, key2)
#define SearchSysCacheExists1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
ObjectAddress RenameRelation(RenameStmt *stmt)
ObjectAddress renameatt(RenameStmt *stmt)
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
ObjectAddress RenameConstraint(RenameStmt *stmt)
ObjectAddress renametrig(RenameStmt *stmt)
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, bool ignoreDependent, ObjectAddresses *objsMoved)
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
ObjectAddress RenameType(RenameStmt *stmt)
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
ObjectAddress RenameRole(const char *oldname, const char *newname)