27 #include "catalog/pg_database_d.h"
67 #include "utils/fmgroids.h"
85 case EventTriggerRelationId:
86 msgfmt =
gettext_noop(
"event trigger \"%s\" already exists");
88 case ForeignDataWrapperRelationId:
89 msgfmt =
gettext_noop(
"foreign-data wrapper \"%s\" already exists");
91 case ForeignServerRelationId:
94 case LanguageRelationId:
97 case PublicationRelationId:
98 msgfmt =
gettext_noop(
"publication \"%s\" already exists");
100 case SubscriptionRelationId:
101 msgfmt =
gettext_noop(
"subscription \"%s\" already exists");
104 elog(
ERROR,
"unsupported object class: %u", classId);
122 case ConversionRelationId:
124 msgfmt =
gettext_noop(
"conversion \"%s\" already exists in schema \"%s\"");
126 case StatisticExtRelationId:
128 msgfmt =
gettext_noop(
"statistics object \"%s\" already exists in schema \"%s\"");
130 case TSParserRelationId:
132 msgfmt =
gettext_noop(
"text search parser \"%s\" already exists in schema \"%s\"");
134 case TSDictionaryRelationId:
136 msgfmt =
gettext_noop(
"text search dictionary \"%s\" already exists in schema \"%s\"");
138 case TSTemplateRelationId:
140 msgfmt =
gettext_noop(
"text search template \"%s\" already exists in schema \"%s\"");
142 case TSConfigRelationId:
144 msgfmt =
gettext_noop(
"text search configuration \"%s\" already exists in schema \"%s\"");
147 elog(
ERROR,
"unsupported object class: %u", classId);
191 elog(
ERROR,
"cache lookup failed for object %u of catalog \"%s\"",
200 if (Anum_namespace > 0)
216 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
217 errmsg(
"must be superuser to rename %s",
240 if (classId == SubscriptionRelationId)
256 if (!form->subpasswordrequired && !
superuser())
258 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
259 errmsg(
"password_required=false is superuser-only"),
260 errhint(
"Subscriptions with the password_required option set to false may only be created or modified by the superuser.")));
269 if (classId == ProcedureRelationId)
274 &proc->proargtypes, proc->pronamespace);
276 else if (classId == CollationRelationId)
282 else if (classId == OperatorClassRelationId)
289 else if (classId == OperatorFamilyRelationId)
296 else if (classId == SubscriptionRelationId)
303 #ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
304 if (strncmp(new_name,
"regress_", 8) != 0)
305 elog(
WARNING,
"subscriptions created by regression test cases should have names starting with \"regress_\"");
311 else if (nameCacheId >= 0)
334 replaces[Anum_name - 1] =
true;
361 switch (
stmt->renameType)
445 elog(
ERROR,
"unrecognized rename stmt type: %d",
446 (
int)
stmt->renameType);
478 stmt->objectType, address,
stmt->object, rel);
491 *refAddress = refAddr;
529 switch (
stmt->objectType)
533 oldSchemaAddr ? &oldNspOid : NULL);
542 oldSchemaAddr ? &oldNspOid : NULL);
549 oldSchemaAddr ? &oldNspOid : NULL);
590 elog(
ERROR,
"unrecognized AlterObjectSchemaStmt type: %d",
591 (
int)
stmt->objectType);
741 elog(
ERROR,
"cache lookup failed for object %u of catalog \"%s\"",
755 if (oldNspOid == nspOid)
774 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
775 errmsg(
"must be superuser to set schema of %s",
799 if (classId == ProcedureRelationId)
804 &proc->proargtypes, nspOid);
806 else if (classId == CollationRelationId)
812 else if (classId == OperatorClassRelationId)
817 opc->opcmethod, nspOid);
819 else if (classId == OperatorFamilyRelationId)
824 opf->opfmethod, nspOid);
826 else if (nameCacheId >= 0 &&
838 replaces[Anum_namespace - 1] =
true;
852 NamespaceRelationId, oldNspOid, nspOid);
868 switch (
stmt->objectType)
936 if (classId == LargeObjectRelationId)
937 classId = LargeObjectMetadataRelationId;
949 elog(
ERROR,
"unrecognized AlterOwnerStmt type: %d",
950 (
int)
stmt->objectType);
981 elog(
ERROR,
"cache lookup failed for object %u of catalog \"%s\"",
997 if (old_ownerId != new_ownerId)
1023 snprintf(namebuf,
sizeof(namebuf),
"%u", objectId);
1037 aclresult =
object_aclcheck(NamespaceRelationId, namespaceId, new_ownerId,
1048 nulls =
palloc0(nattrs *
sizeof(
bool));
1049 replaces =
palloc0(nattrs *
sizeof(
bool));
1051 replaces[Anum_owner - 1] =
true;
1066 old_ownerId, new_ownerId);
1068 replaces[Anum_acl - 1] =
true;
1073 values, nulls, replaces);
1079 if (classId == LargeObjectMetadataRelationId)
1080 classId = LargeObjectRelationId;
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)
void AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
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 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)
elog(ERROR, "%s: %s", p2, msg)
ObjectClass getObjectClass(const ObjectAddress *object)
@ DEPENDENCY_AUTO_EXTENSION
@ OCLASS_PUBLICATION_NAMESPACE
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, Datum *replValues, bool *replIsnull, 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)
Assert(fmt[strlen(fmt) - 1] !='\n')
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)
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
ObjectAddress RenameType(RenameStmt *stmt)
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved)
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
ObjectAddress RenameRole(const char *oldname, const char *newname)