PostgreSQL Source Code git master
Loading...
Searching...
No Matches
alter.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * alter.c
4 * Drivers for generic alter commands
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/commands/alter.c
12 *
13 *-------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "access/htup_details.h"
18#include "access/relation.h"
19#include "access/table.h"
20#include "catalog/dependency.h"
21#include "catalog/indexing.h"
22#include "catalog/namespace.h"
26#include "catalog/pg_database_d.h"
30#include "catalog/pg_language.h"
34#include "catalog/pg_opclass.h"
35#include "catalog/pg_operator.h"
36#include "catalog/pg_opfamily.h"
37#include "catalog/pg_proc.h"
41#include "catalog/pg_ts_dict.h"
44#include "commands/alter.h"
46#include "commands/dbcommands.h"
47#include "commands/defrem.h"
49#include "commands/extension.h"
50#include "commands/policy.h"
52#include "commands/schemacmds.h"
54#include "commands/tablecmds.h"
55#include "commands/tablespace.h"
56#include "commands/trigger.h"
57#include "commands/typecmds.h"
58#include "commands/user.h"
59#include "miscadmin.h"
62#include "storage/lmgr.h"
63#include "utils/acl.h"
64#include "utils/builtins.h"
65#include "utils/lsyscache.h"
66#include "utils/rel.h"
67#include "utils/syscache.h"
68
70
71/*
72 * Raise an error to the effect that an object of the given name is already
73 * present in the given namespace.
74 */
75static void
76report_name_conflict(Oid classId, const char *name)
77{
78 char *msgfmt;
79
80 switch (classId)
81 {
83 msgfmt = gettext_noop("event trigger \"%s\" already exists");
84 break;
86 msgfmt = gettext_noop("foreign-data wrapper \"%s\" already exists");
87 break;
89 msgfmt = gettext_noop("server \"%s\" already exists");
90 break;
92 msgfmt = gettext_noop("language \"%s\" already exists");
93 break;
95 msgfmt = gettext_noop("publication \"%s\" already exists");
96 break;
98 msgfmt = gettext_noop("subscription \"%s\" already exists");
99 break;
100 default:
101 elog(ERROR, "unsupported object class: %u", classId);
102 break;
103 }
104
107 errmsg(msgfmt, name)));
108}
109
110static void
112{
113 char *msgfmt;
114
116
117 switch (classId)
118 {
120 msgfmt = gettext_noop("conversion \"%s\" already exists in schema \"%s\"");
121 break;
123 msgfmt = gettext_noop("statistics object \"%s\" already exists in schema \"%s\"");
124 break;
126 msgfmt = gettext_noop("text search parser \"%s\" already exists in schema \"%s\"");
127 break;
129 msgfmt = gettext_noop("text search dictionary \"%s\" already exists in schema \"%s\"");
130 break;
132 msgfmt = gettext_noop("text search template \"%s\" already exists in schema \"%s\"");
133 break;
135 msgfmt = gettext_noop("text search configuration \"%s\" already exists in schema \"%s\"");
136 break;
137 default:
138 elog(ERROR, "unsupported object class: %u", classId);
139 break;
140 }
141
145}
146
147/*
148 * AlterObjectRename_internal
149 *
150 * Generic function to rename the given object, for simple cases (won't
151 * work for tables, nor other cases where we need to do more than change
152 * the name column of a single catalog entry).
153 *
154 * rel: catalog relation containing object (RowExclusiveLock'd by caller)
155 * objectId: OID of object to be renamed
156 * new_name: CString representation of new name
157 */
158static void
160{
161 Oid classId = RelationGetRelid(rel);
162 int oidCacheId = get_object_catcache_oid(classId);
169 Datum datum;
170 bool isnull;
172 Oid ownerId;
173 char *old_name;
175 Datum *values;
176 bool *nulls;
177 bool *replaces;
179
182 elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
183 objectId, RelationGetRelationName(rel));
184
186 RelationGetDescr(rel), &isnull);
187 Assert(!isnull);
188 old_name = NameStr(*(DatumGetName(datum)));
189
190 /* Get OID of namespace */
191 if (Anum_namespace > 0)
192 {
194 RelationGetDescr(rel), &isnull);
195 Assert(!isnull);
197 }
198 else
200
201 /* Permission checks ... superusers can always do it */
202 if (!superuser())
203 {
204 /* Fail if object does not have an explicit owner */
205 if (Anum_owner <= 0)
208 errmsg("must be superuser to rename %s",
209 getObjectDescriptionOids(classId, objectId))));
210
211 /* Otherwise, must be owner of the existing object */
213 RelationGetDescr(rel), &isnull);
214 Assert(!isnull);
215 ownerId = DatumGetObjectId(datum);
216
217 if (!has_privs_of_role(GetUserId(), ownerId))
219 old_name);
220
221 /* User must have CREATE privilege on the namespace */
223 {
225 ACL_CREATE);
226 if (aclresult != ACLCHECK_OK)
229 }
230
231 if (classId == SubscriptionRelationId)
232 {
234
235 /* must have CREATE privilege on database */
238 if (aclresult != ACLCHECK_OK)
241
242 /*
243 * Don't allow non-superuser modification of a subscription with
244 * password_required=false.
245 */
247 if (!form->subpasswordrequired && !superuser())
250 errmsg("password_required=false is superuser-only"),
251 errhint("Subscriptions with the password_required option set to false may only be created or modified by the superuser.")));
252 }
253 }
254
255 /*
256 * Check for duplicate name (more friendly than unique-index failure).
257 * Since this is just a friendliness check, we can just skip it in cases
258 * where there isn't suitable support.
259 */
260 if (classId == ProcedureRelationId)
261 {
263
264 IsThereFunctionInNamespace(new_name, proc->pronargs,
265 &proc->proargtypes, proc->pronamespace);
266 }
267 else if (classId == CollationRelationId)
268 {
270
272 }
273 else if (classId == OperatorClassRelationId)
274 {
276
278 opc->opcnamespace);
279 }
280 else if (classId == OperatorFamilyRelationId)
281 {
283
285 opf->opfnamespace);
286 }
287 else if (classId == SubscriptionRelationId)
288 {
293
294 /* Also enforce regression testing naming rules, if enabled */
295#ifdef ENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS
296 if (strncmp(new_name, "regress_", 8) != 0)
297 elog(WARNING, "subscriptions created by regression test cases should have names starting with \"regress_\"");
298#endif
299
300 /* Wake up related replication workers to handle this change quickly */
302 }
303 else if (nameCacheId >= 0)
304 {
306 {
311 }
312 else
313 {
317 }
318 }
319
320 /* Build modified tuple */
322 nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
323 replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
326 replaces[Anum_name - 1] = true;
328 values, nulls, replaces);
329
330 /* Perform actual update */
331 CatalogTupleUpdate(rel, &oldtup->t_self, newtup);
332
333 InvokeObjectPostAlterHook(classId, objectId, 0);
334
335 /* Do post catalog-update tasks */
336 if (classId == PublicationRelationId)
337 {
339
340 /*
341 * Invalidate relsynccache entries.
342 *
343 * Unlike ALTER PUBLICATION ADD/SET/DROP commands, renaming a
344 * publication does not impact the publication status of tables. So,
345 * we don't need to invalidate relcache to rebuild the rd_pubdesc.
346 * Instead, we invalidate only the relsyncache.
347 */
348 InvalidatePubRelSyncCache(pub->oid, pub->puballtables);
349 }
350
351 /* Release memory */
352 pfree(values);
353 pfree(nulls);
356
358}
359
360/*
361 * Executes an ALTER OBJECT / RENAME TO statement. Based on the object
362 * type, the function appropriate to that type is executed.
363 *
364 * Return value is the address of the renamed object.
365 */
368{
369 switch (stmt->renameType)
370 {
373 return RenameConstraint(stmt);
374
375 case OBJECT_DATABASE:
376 return RenameDatabase(stmt->subname, stmt->newname);
377
378 case OBJECT_ROLE:
379 return RenameRole(stmt->subname, stmt->newname);
380
381 case OBJECT_SCHEMA:
382 return RenameSchema(stmt->subname, stmt->newname);
383
385 return RenameTableSpace(stmt->subname, stmt->newname);
386
387 case OBJECT_TABLE:
388 case OBJECT_SEQUENCE:
389 case OBJECT_VIEW:
390 case OBJECT_MATVIEW:
391 case OBJECT_INDEX:
393 return RenameRelation(stmt);
394
395 case OBJECT_COLUMN:
396 case OBJECT_ATTRIBUTE:
397 return renameatt(stmt);
398
399 case OBJECT_RULE:
400 return RenameRewriteRule(stmt->relation, stmt->subname,
401 stmt->newname);
402
403 case OBJECT_TRIGGER:
404 return renametrig(stmt);
405
406 case OBJECT_POLICY:
407 return rename_policy(stmt);
408
409 case OBJECT_DOMAIN:
410 case OBJECT_TYPE:
411 return RenameType(stmt);
412
413 case OBJECT_AGGREGATE:
414 case OBJECT_COLLATION:
417 case OBJECT_FDW:
419 case OBJECT_FUNCTION:
420 case OBJECT_OPCLASS:
421 case OBJECT_OPFAMILY:
422 case OBJECT_LANGUAGE:
423 case OBJECT_PROCEDURE:
424 case OBJECT_ROUTINE:
428 case OBJECT_TSPARSER:
432 {
433 ObjectAddress address;
435
436 address = get_object_address(stmt->renameType,
437 stmt->object,
438 NULL,
439 AccessExclusiveLock, false);
440
443 address.objectId,
444 stmt->newname);
446
447 return address;
448 }
449
450 default:
451 elog(ERROR, "unrecognized rename stmt type: %d",
452 (int) stmt->renameType);
453 return InvalidObjectAddress; /* keep compiler happy */
454 }
455}
456
457/*
458 * Executes an ALTER OBJECT / [NO] DEPENDS ON EXTENSION statement.
459 *
460 * Return value is the address of the altered object. refAddress is an output
461 * argument which, if not null, receives the address of the object that the
462 * altered object now depends on.
463 */
466{
467 ObjectAddress address;
469 Relation rel;
470
471 address =
472 get_object_address_rv(stmt->objectType, stmt->relation, (List *) stmt->object,
473 &rel, AccessExclusiveLock, false);
474
475 /*
476 * Verify that the user is entitled to run the command.
477 *
478 * We don't check any privileges on the extension, because that's not
479 * needed. The object owner is stipulating, by running this command, that
480 * the extension owner can drop the object whenever they feel like it,
481 * which is not considered a problem.
482 */
484 stmt->objectType, address, stmt->object, rel);
485
486 /*
487 * If a relation was involved, it would have been opened and locked. We
488 * don't need the relation here, but we'll retain the lock until commit.
489 */
490 if (rel)
491 table_close(rel, NoLock);
492
494 NULL, AccessExclusiveLock, false);
495 if (refAddress)
497
498 if (stmt->remove)
499 {
502 refAddr.classId, refAddr.objectId);
503 }
504 else
505 {
506 List *currexts;
507
508 /* Avoid duplicates */
510 address.objectId);
511 if (!list_member_oid(currexts, refAddr.objectId))
513 }
514
515 return address;
516}
517
518/*
519 * Executes an ALTER OBJECT / SET SCHEMA statement. Based on the object
520 * type, the function appropriate to that type is executed.
521 *
522 * Return value is that of the altered object.
523 *
524 * oldSchemaAddr is an output argument which, if not NULL, is set to the object
525 * address of the original schema.
526 */
530{
531 ObjectAddress address;
533
534 switch (stmt->objectType)
535 {
536 case OBJECT_EXTENSION:
537 address = AlterExtensionNamespace(strVal(stmt->object), stmt->newschema,
539 break;
540
542 case OBJECT_SEQUENCE:
543 case OBJECT_TABLE:
544 case OBJECT_VIEW:
545 case OBJECT_MATVIEW:
546 address = AlterTableNamespace(stmt,
548 break;
549
550 case OBJECT_DOMAIN:
551 case OBJECT_TYPE:
552 address = AlterTypeNamespace(castNode(List, stmt->object), stmt->newschema,
553 stmt->objectType,
555 break;
556
557 /* generic code path */
558 case OBJECT_AGGREGATE:
559 case OBJECT_COLLATION:
561 case OBJECT_FUNCTION:
562 case OBJECT_OPERATOR:
563 case OBJECT_OPCLASS:
564 case OBJECT_OPFAMILY:
565 case OBJECT_PROCEDURE:
566 case OBJECT_ROUTINE:
570 case OBJECT_TSPARSER:
572 {
574 Oid classId;
575 Oid nspOid;
576
577 address = get_object_address(stmt->objectType,
578 stmt->object,
579 NULL,
581 false);
582 classId = address.classId;
584 nspOid = LookupCreationNamespace(stmt->newschema);
585
587 nspOid);
589 }
590 break;
591
592 default:
593 elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
594 (int) stmt->objectType);
595 return InvalidObjectAddress; /* keep compiler happy */
596 }
597
598 if (oldSchemaAddr)
600
601 return address;
602}
603
604/*
605 * Change an object's namespace given its classOid and object Oid.
606 *
607 * Objects that don't have a namespace should be ignored, as should
608 * dependent types such as array types.
609 *
610 * This function is currently used only by ALTER EXTENSION SET SCHEMA,
611 * so it only needs to cover object kinds that can be members of an
612 * extension, and it can silently ignore dependent types --- we assume
613 * those will be moved when their parent object is moved.
614 *
615 * Returns the OID of the object's previous namespace, or InvalidOid if
616 * object doesn't have a schema or was ignored due to being a dependent type.
617 */
618Oid
621{
623
624 switch (classId)
625 {
627 {
628 Relation rel;
629
632
634
636 break;
637 }
638
639 case TypeRelationId:
641 break;
642
654 {
656
658
660 nspOid);
661
663 }
664 break;
665
666 default:
667 /* ignore object types that don't have schema-qualified names */
669 }
670
671 return oldNspOid;
672}
673
674/*
675 * Generic function to change the namespace of a given object, for simple
676 * cases (won't work for tables, nor other cases where we need to do more
677 * than change the namespace column of a single catalog entry).
678 *
679 * rel: catalog relation containing object (RowExclusiveLock'd by caller)
680 * objid: OID of object to change the namespace of
681 * nspOid: OID of new namespace
682 *
683 * Returns the OID of the object's previous namespace.
684 */
685static Oid
687{
688 Oid classId = RelationGetRelid(rel);
689 int oidCacheId = get_object_catcache_oid(classId);
695 Datum name,
696 namespace;
697 bool isnull;
699 newtup;
700 Datum *values;
701 bool *nulls;
702 bool *replaces;
703
705 if (!HeapTupleIsValid(tup)) /* should not happen */
706 elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
707 objid, RelationGetRelationName(rel));
708
710 Assert(!isnull);
712 &isnull);
713 Assert(!isnull);
714 oldNspOid = DatumGetObjectId(namespace);
715
716 /*
717 * If the object is already in the correct namespace, we don't need to do
718 * anything except fire the object access hook.
719 */
720 if (oldNspOid == nspOid)
721 {
722 InvokeObjectPostAlterHook(classId, objid, 0);
723 return oldNspOid;
724 }
725
726 /* Check basic namespace related issues */
728
729 /* Permission checks ... superusers can always do it */
730 if (!superuser())
731 {
732 Datum owner;
733 Oid ownerId;
735
736 /* Fail if object does not have an explicit owner */
737 if (Anum_owner <= 0)
740 errmsg("must be superuser to set schema of %s",
741 getObjectDescriptionOids(classId, objid))));
742
743 /* Otherwise, must be owner of the existing object */
744 owner = heap_getattr(tup, Anum_owner, RelationGetDescr(rel), &isnull);
745 Assert(!isnull);
746 ownerId = DatumGetObjectId(owner);
747
748 if (!has_privs_of_role(GetUserId(), ownerId))
751
752 /* User must have CREATE privilege on new namespace */
754 if (aclresult != ACLCHECK_OK)
757 }
758
759 /*
760 * Check for duplicate name (more friendly than unique-index failure).
761 * Since this is just a friendliness check, we can just skip it in cases
762 * where there isn't suitable support.
763 */
764 if (classId == ProcedureRelationId)
765 {
767
768 IsThereFunctionInNamespace(NameStr(proc->proname), proc->pronargs,
769 &proc->proargtypes, nspOid);
770 }
771 else if (classId == CollationRelationId)
772 {
774
776 }
777 else if (classId == OperatorClassRelationId)
778 {
780
782 opc->opcmethod, nspOid);
783 }
784 else if (classId == OperatorFamilyRelationId)
785 {
787
789 opf->opfmethod, nspOid);
790 }
791 else if (nameCacheId >= 0 &&
796 nspOid);
797
798 /* Build modified tuple */
800 nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
801 replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
803 replaces[Anum_namespace - 1] = true;
805 values, nulls, replaces);
806
807 /* Perform actual update */
808 CatalogTupleUpdate(rel, &tup->t_self, newtup);
809
810 /* Release memory */
811 pfree(values);
812 pfree(nulls);
814
815 /* update dependency to point to the new schema */
816 if (changeDependencyFor(classId, objid,
818 elog(ERROR, "could not change schema dependency for object %u",
819 objid);
820
821 InvokeObjectPostAlterHook(classId, objid, 0);
822
823 return oldNspOid;
824}
825
826/*
827 * Executes an ALTER OBJECT / OWNER TO statement. Based on the object
828 * type, the function appropriate to that type is executed.
829 */
832{
833 Oid newowner = get_rolespec_oid(stmt->newowner, false);
834
835 switch (stmt->objectType)
836 {
837 case OBJECT_DATABASE:
838 return AlterDatabaseOwner(strVal(stmt->object), newowner);
839
840 case OBJECT_SCHEMA:
841 return AlterSchemaOwner(strVal(stmt->object), newowner);
842
843 case OBJECT_TYPE:
844 case OBJECT_DOMAIN: /* same as TYPE */
845 return AlterTypeOwner(castNode(List, stmt->object), newowner, stmt->objectType);
846 break;
847
848 case OBJECT_FDW:
850 newowner);
851
853 return AlterForeignServerOwner(strVal(stmt->object),
854 newowner);
855
857 return AlterEventTriggerOwner(strVal(stmt->object),
858 newowner);
859
861 return AlterPublicationOwner(strVal(stmt->object),
862 newowner);
863
865 return AlterSubscriptionOwner(strVal(stmt->object),
866 newowner);
867
868 /* Generic cases */
869 case OBJECT_AGGREGATE:
870 case OBJECT_COLLATION:
872 case OBJECT_FUNCTION:
873 case OBJECT_LANGUAGE:
875 case OBJECT_OPERATOR:
876 case OBJECT_OPCLASS:
877 case OBJECT_OPFAMILY:
878 case OBJECT_PROCEDURE:
879 case OBJECT_ROUTINE:
884 {
885 ObjectAddress address;
886
887 address = get_object_address(stmt->objectType,
888 stmt->object,
889 NULL,
891 false);
892
894 newowner);
895
896 return address;
897 }
898 break;
899
900 default:
901 elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
902 (int) stmt->objectType);
903 return InvalidObjectAddress; /* keep compiler happy */
904 }
905}
906
907/*
908 * Generic function to change the ownership of a given object, for simple
909 * cases (won't work for tables, nor other cases where we need to do more than
910 * change the ownership column of a single catalog entry).
911 *
912 * classId: OID of catalog containing object
913 * objectId: OID of object to change the ownership of
914 * new_ownerId: OID of new object owner
915 *
916 * This will work on large objects, but we have to beware of the fact that
917 * classId isn't the OID of the catalog to modify in that case.
918 */
919void
921{
922 /* For large objects, the catalog to modify is pg_largeobject_metadata */
923 Oid catalogId = (classId == LargeObjectRelationId) ? LargeObjectMetadataRelationId : classId;
929 Relation rel;
931 Datum datum;
932 bool isnull;
935
936 rel = table_open(catalogId, RowExclusiveLock);
937
938 /* Search tuple and lock it. */
939 oldtup =
940 get_catalog_object_by_oid_extended(rel, Anum_oid, objectId, true);
941 if (oldtup == NULL)
942 elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
943 objectId, RelationGetRelationName(rel));
944
946 RelationGetDescr(rel), &isnull);
947 Assert(!isnull);
949
951 {
953 RelationGetDescr(rel), &isnull);
954 Assert(!isnull);
956 }
957
959 {
960 AttrNumber nattrs;
962 Datum *values;
963 bool *nulls;
964 bool *replaces;
965
966 /* Superusers can bypass permission checks */
967 if (!superuser())
968 {
969 /* must be owner */
971 {
972 char *objname;
973 char namebuf[NAMEDATALEN];
974
976 {
978 RelationGetDescr(rel), &isnull);
979 Assert(!isnull);
980 objname = NameStr(*DatumGetName(datum));
981 }
982 else
983 {
984 snprintf(namebuf, sizeof(namebuf), "%u", objectId);
985 objname = namebuf;
986 }
988 get_object_type(catalogId, objectId),
989 objname);
990 }
991 /* Must be able to become new owner */
993
994 /* New owner must have CREATE privilege on namespace */
996 {
998
1000 ACL_CREATE);
1001 if (aclresult != ACLCHECK_OK)
1004 }
1005 }
1006
1007 /* Build a modified tuple */
1008 nattrs = RelationGetNumberOfAttributes(rel);
1009 values = palloc0(nattrs * sizeof(Datum));
1010 nulls = palloc0(nattrs * sizeof(bool));
1011 replaces = palloc0(nattrs * sizeof(bool));
1013 replaces[Anum_owner - 1] = true;
1014
1015 /*
1016 * Determine the modified ACL for the new owner. This is only
1017 * necessary when the ACL is non-null.
1018 */
1020 {
1021 datum = heap_getattr(oldtup,
1022 Anum_acl, RelationGetDescr(rel), &isnull);
1023 if (!isnull)
1024 {
1025 Acl *newAcl;
1026
1030 replaces[Anum_acl - 1] = true;
1031 }
1032 }
1033
1035 values, nulls, replaces);
1036
1037 /* Perform actual update */
1038 CatalogTupleUpdate(rel, &newtup->t_self, newtup);
1039
1041
1042 /* Update owner dependency reference */
1043 changeDependencyOnOwner(classId, objectId, new_ownerId);
1044
1045 /* Release memory */
1046 pfree(values);
1047 pfree(nulls);
1048 pfree(replaces);
1049 }
1050 else
1052
1053 /* Note the post-alter hook gets classId not catalogId */
1054 InvokeObjectPostAlterHook(classId, objectId, 0);
1055
1057}
bool has_privs_of_role(Oid member, Oid role)
Definition acl.c:5284
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
Definition acl.c:1119
void check_can_set_role(Oid member, Oid role)
Definition acl.c:5341
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition acl.c:5586
AclResult
Definition acl.h:182
@ ACLCHECK_OK
Definition acl.h:183
@ ACLCHECK_NOT_OWNER
Definition acl.h:185
#define DatumGetAclP(X)
Definition acl.h:120
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2654
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition aclchk.c:3836
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition alter.c:686
static void report_name_conflict(Oid classId, const char *name)
Definition alter.c:76
ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
Definition alter.c:831
static void report_namespace_conflict(Oid classId, const char *name, Oid nspOid)
Definition alter.c:111
ObjectAddress ExecAlterObjectDependsStmt(AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
Definition alter.c:465
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
Definition alter.c:159
ObjectAddress ExecRenameStmt(RenameStmt *stmt)
Definition alter.c:367
void AlterObjectOwner_internal(Oid classId, Oid objectId, Oid new_ownerId)
Definition alter.c:920
ObjectAddress ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
Definition alter.c:528
Oid AlterObjectNamespace_oid(Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
Definition alter.c:619
int16 AttrNumber
Definition attnum.h:21
#define InvalidAttrNumber
Definition attnum.h:23
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
Definition tablespace.c:930
void LogicalRepWorkersWakeupAtCommit(Oid subid)
Definition worker.c:6259
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define NameStr(name)
Definition c.h:765
#define gettext_noop(x)
Definition c.h:1185
#define Assert(condition)
Definition c.h:873
#define OidIsValid(objectId)
Definition c.h:788
void IsThereCollationInNamespace(const char *collname, Oid nspOid)
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
@ DEPENDENCY_AUTO_EXTENSION
Definition dependency.h:39
int errhint(const char *fmt,...)
Definition elog.c:1330
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define WARNING
Definition elog.h:36
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
Definition extension.c:3122
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)
Oid MyDatabaseId
Definition globals.c:94
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition heaptuple.c:1210
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static void * GETSTRUCT(const HeapTupleData *tuple)
#define stmt
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
bool list_member_oid(const List *list, Oid datum)
Definition list.c:722
void UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
Definition lmgr.c:601
#define NoLock
Definition lockdefs.h:34
#define AccessExclusiveLock
Definition lockdefs.h:43
#define InplaceUpdateTupleLock
Definition lockdefs.h:48
#define RowExclusiveLock
Definition lockdefs.h:38
char * get_database_name(Oid dbid)
Definition lsyscache.c:1242
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3516
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc0(Size size)
Definition mcxt.c:1417
Oid GetUserId(void)
Definition miscinit.c:469
void namestrcpy(Name name, const char *str)
Definition name.c:233
Oid LookupCreationNamespace(const char *nspname)
Definition namespace.c:3498
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
Definition namespace.c:3529
#define castNode(_type_, nodeptr)
Definition nodes.h:182
#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)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
char * getObjectDescriptionOids(Oid classid, Oid objid)
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)
HeapTuple get_catalog_object_by_oid_extended(Relation catalog, AttrNumber oidcol, Oid objectId, bool locktup)
#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)
@ OBJECT_EVENT_TRIGGER
@ OBJECT_FDW
@ OBJECT_TSPARSER
@ OBJECT_COLLATION
@ OBJECT_OPCLASS
@ OBJECT_AGGREGATE
@ OBJECT_MATVIEW
@ OBJECT_SCHEMA
@ OBJECT_POLICY
@ OBJECT_OPERATOR
@ OBJECT_FOREIGN_TABLE
@ OBJECT_TSCONFIGURATION
@ OBJECT_OPFAMILY
@ OBJECT_DOMAIN
@ OBJECT_COLUMN
@ OBJECT_TABLESPACE
@ OBJECT_ROLE
@ OBJECT_ROUTINE
@ OBJECT_LARGEOBJECT
@ OBJECT_PROCEDURE
@ OBJECT_EXTENSION
@ OBJECT_INDEX
@ OBJECT_DATABASE
@ OBJECT_SEQUENCE
@ OBJECT_TSTEMPLATE
@ OBJECT_LANGUAGE
@ OBJECT_FOREIGN_SERVER
@ OBJECT_TSDICTIONARY
@ OBJECT_ATTRIBUTE
@ OBJECT_PUBLICATION
@ OBJECT_RULE
@ OBJECT_CONVERSION
@ OBJECT_TABLE
@ OBJECT_VIEW
@ OBJECT_TYPE
@ OBJECT_FUNCTION
@ OBJECT_TABCONSTRAINT
@ OBJECT_DOMCONSTRAINT
@ OBJECT_SUBSCRIPTION
@ OBJECT_STATISTIC_EXT
@ OBJECT_TRIGGER
#define ACL_CREATE
Definition parsenodes.h:85
FormData_pg_collation * Form_pg_collation
#define NAMEDATALEN
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition pg_depend.c:45
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition pg_depend.c:457
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Definition pg_depend.c:398
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
Definition pg_depend.c:778
FormData_pg_opclass * Form_pg_opclass
Definition pg_opclass.h:83
FormData_pg_opfamily * Form_pg_opfamily
Definition pg_opfamily.h:51
FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:136
FormData_pg_publication * Form_pg_publication
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
FormData_pg_subscription * Form_pg_subscription
ObjectAddress rename_policy(RenameStmt *stmt)
Definition policy.c:1096
#define snprintf
Definition port.h:260
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
static Name DatumGetName(Datum X)
Definition postgres.h:390
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:252
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static Datum NameGetDatum(const NameData *X)
Definition postgres.h:403
uint64_t Datum
Definition postgres.h:70
static Datum CStringGetDatum(const char *X)
Definition postgres.h:380
#define InvalidOid
unsigned int Oid
static int fb(int x)
void InvalidatePubRelSyncCache(Oid pubid, bool puballtables)
ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId)
#define RelationGetRelid(relation)
Definition rel.h:514
#define RelationGetDescr(relation)
Definition rel.h:540
#define RelationGetNumberOfAttributes(relation)
Definition rel.h:520
#define RelationGetRelationName(relation)
Definition rel.h:548
#define RelationGetNamespace(relation)
Definition rel.h:555
ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName)
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
Definition schemacmds.c:331
ObjectAddress RenameSchema(const char *oldname, const char *newname)
Definition schemacmds.c:250
void relation_close(Relation relation, LOCKMODE lockmode)
Definition relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition relation.c:47
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30
Definition pg_list.h:54
Definition nodes.h:135
Definition c.h:760
ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId)
bool superuser(void)
Definition superuser.c:46
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91
#define SearchSysCacheExists2(cacheId, key1, key2)
Definition syscache.h:102
#define SearchSysCacheExists1(cacheId, key1)
Definition syscache.h:100
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
ObjectAddress RenameRelation(RenameStmt *stmt)
Definition tablecmds.c:4204
ObjectAddress renameatt(RenameStmt *stmt)
Definition tablecmds.c:4007
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
ObjectAddress RenameConstraint(RenameStmt *stmt)
Definition tablecmds.c:4154
ObjectAddress renametrig(RenameStmt *stmt)
Definition trigger.c:1467
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, bool ignoreDependent, ObjectAddresses *objsMoved)
Definition typecmds.c:4139
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
Definition typecmds.c:3857
ObjectAddress RenameType(RenameStmt *stmt)
Definition typecmds.c:3776
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
Definition typecmds.c:4090
ObjectAddress RenameRole(const char *oldname, const char *newname)
Definition user.c:1335
#define strVal(v)
Definition value.h:82
const char * name