PostgreSQL Source Code  git master
dependency.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * dependency.h
4  * Routines to support inter-object dependencies.
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/catalog/dependency.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef DEPENDENCY_H
15 #define DEPENDENCY_H
16 
17 #include "catalog/objectaddress.h"
18 
19 
20 /*
21  * Precise semantics of a dependency relationship are specified by the
22  * DependencyType code (which is stored in a "char" field in pg_depend,
23  * so we assign ASCII-code values to the enumeration members).
24  *
25  * In all cases, a dependency relationship indicates that the referenced
26  * object may not be dropped without also dropping the dependent object.
27  * However, there are several subflavors; see the description of pg_depend
28  * in catalogs.sgml for details.
29  */
30 
31 typedef enum DependencyType
32 {
42 
43 /*
44  * There is also a SharedDependencyType enum type that determines the exact
45  * semantics of an entry in pg_shdepend. Just like regular dependency entries,
46  * any pg_shdepend entry means that the referenced object cannot be dropped
47  * unless the dependent object is dropped at the same time. There are some
48  * additional rules however:
49  *
50  * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object --
51  * rather, the referenced object is an essential part of the system. This
52  * applies to the initdb-created superuser. Entries of this type are only
53  * created by initdb; objects in this category don't need further pg_shdepend
54  * entries if more objects come to depend on them.
55  *
56  * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
57  * the role owning the dependent object. The referenced object must be
58  * a pg_authid entry.
59  *
60  * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
61  * a role mentioned in the ACL field of the dependent object. The referenced
62  * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not
63  * created for the owner of an object; hence two objects may be linked by
64  * one or the other, but not both, of these dependency types.)
65  *
66  * (d) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is
67  * a role mentioned in a policy object. The referenced object must be a
68  * pg_authid entry.
69  *
70  * (e) a SHARED_DEPENDENCY_TABLESPACE entry means that the referenced
71  * object is a tablespace mentioned in a relation without storage. The
72  * referenced object must be a pg_tablespace entry. (Relations that have
73  * storage don't need this: they are protected by the existence of a physical
74  * file in the tablespace.)
75  *
76  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
77  * routines, and is not valid in the catalog itself.
78  */
80 {
88 
89 /* expansible list of ObjectAddresses (private in dependency.c) */
91 
92 /*
93  * This enum covers all system catalogs whose OIDs can appear in
94  * pg_depend.classId or pg_shdepend.classId. Keep object_classes[] in sync.
95  */
96 typedef enum ObjectClass
97 {
98  OCLASS_CLASS, /* pg_class */
99  OCLASS_PROC, /* pg_proc */
100  OCLASS_TYPE, /* pg_type */
101  OCLASS_CAST, /* pg_cast */
102  OCLASS_COLLATION, /* pg_collation */
103  OCLASS_CONSTRAINT, /* pg_constraint */
104  OCLASS_CONVERSION, /* pg_conversion */
105  OCLASS_DEFAULT, /* pg_attrdef */
106  OCLASS_LANGUAGE, /* pg_language */
107  OCLASS_LARGEOBJECT, /* pg_largeobject */
108  OCLASS_OPERATOR, /* pg_operator */
109  OCLASS_OPCLASS, /* pg_opclass */
110  OCLASS_OPFAMILY, /* pg_opfamily */
111  OCLASS_AM, /* pg_am */
112  OCLASS_AMOP, /* pg_amop */
113  OCLASS_AMPROC, /* pg_amproc */
114  OCLASS_REWRITE, /* pg_rewrite */
115  OCLASS_TRIGGER, /* pg_trigger */
116  OCLASS_SCHEMA, /* pg_namespace */
117  OCLASS_STATISTIC_EXT, /* pg_statistic_ext */
118  OCLASS_TSPARSER, /* pg_ts_parser */
119  OCLASS_TSDICT, /* pg_ts_dict */
120  OCLASS_TSTEMPLATE, /* pg_ts_template */
121  OCLASS_TSCONFIG, /* pg_ts_config */
122  OCLASS_ROLE, /* pg_authid */
123  OCLASS_DATABASE, /* pg_database */
124  OCLASS_TBLSPACE, /* pg_tablespace */
125  OCLASS_FDW, /* pg_foreign_data_wrapper */
126  OCLASS_FOREIGN_SERVER, /* pg_foreign_server */
127  OCLASS_USER_MAPPING, /* pg_user_mapping */
128  OCLASS_DEFACL, /* pg_default_acl */
129  OCLASS_EXTENSION, /* pg_extension */
130  OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
131  OCLASS_POLICY, /* pg_policy */
132  OCLASS_PUBLICATION, /* pg_publication */
133  OCLASS_PUBLICATION_REL, /* pg_publication_rel */
134  OCLASS_SUBSCRIPTION, /* pg_subscription */
135  OCLASS_TRANSFORM /* pg_transform */
136 } ObjectClass;
137 
138 #define LAST_OCLASS OCLASS_TRANSFORM
139 
140 /* flag bits for performDeletion/performMultipleDeletions: */
141 #define PERFORM_DELETION_INTERNAL 0x0001 /* internal action */
142 #define PERFORM_DELETION_CONCURRENTLY 0x0002 /* concurrent drop */
143 #define PERFORM_DELETION_QUIETLY 0x0004 /* suppress notices */
144 #define PERFORM_DELETION_SKIP_ORIGINAL 0x0008 /* keep original obj */
145 #define PERFORM_DELETION_SKIP_EXTENSIONS 0x0010 /* keep extensions */
146 #define PERFORM_DELETION_CONCURRENT_LOCK 0x0020 /* normal drop with
147  * concurrent lock mode */
148 
149 
150 /* in dependency.c */
151 
152 extern void AcquireDeletionLock(const ObjectAddress *object, int flags);
153 
154 extern void ReleaseDeletionLock(const ObjectAddress *object);
155 
156 extern void performDeletion(const ObjectAddress *object,
157  DropBehavior behavior, int flags);
158 
159 extern void performMultipleDeletions(const ObjectAddresses *objects,
160  DropBehavior behavior, int flags);
161 
162 extern void recordDependencyOnExpr(const ObjectAddress *depender,
163  Node *expr, List *rtable,
164  DependencyType behavior);
165 
166 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
167  Node *expr, Oid relId,
168  DependencyType behavior,
169  DependencyType self_behavior,
170  bool reverse_self,
171  bool record_version);
172 
173 extern ObjectClass getObjectClass(const ObjectAddress *object);
174 
176 
177 extern void add_exact_object_address(const ObjectAddress *object,
178  ObjectAddresses *addrs);
179 
180 extern bool object_address_present(const ObjectAddress *object,
181  const ObjectAddresses *addrs);
182 
183 extern void record_object_address_dependencies(const ObjectAddress *depender,
184  ObjectAddresses *referenced,
185  DependencyType behavior);
186 
187 extern void sort_object_addresses(ObjectAddresses *addrs);
188 
189 extern void free_object_addresses(ObjectAddresses *addrs);
190 
191 typedef bool(*VisitDependenciesOfCB) (const ObjectAddress *otherObject,
192  const char *version,
193  char **new_version,
194  void *data);
195 
196 extern void visitDependenciesOf(const ObjectAddress *object,
198  void *data);
199 
200 /* in pg_depend.c */
201 
202 extern void recordDependencyOn(const ObjectAddress *depender,
203  const ObjectAddress *referenced,
204  DependencyType behavior);
205 
206 extern void recordDependencyOnCollations(ObjectAddress *myself,
207  List *collations,
208  bool record_version);
209 
210 extern void recordMultipleDependencies(const ObjectAddress *depender,
211  const ObjectAddress *referenced,
212  int nreferenced,
213  DependencyType behavior,
214  bool record_version);
215 
216 extern void recordDependencyOnCurrentExtension(const ObjectAddress *object,
217  bool isReplace);
218 
219 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId,
220  bool skipExtensionDeps);
221 
222 extern long deleteDependencyRecordsForClass(Oid classId, Oid objectId,
223  Oid refclassId, char deptype);
224 
225 extern long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId,
226  char deptype,
227  Oid refclassId, Oid refobjectId);
228 
229 extern long changeDependencyFor(Oid classId, Oid objectId,
230  Oid refClassId, Oid oldRefObjectId,
231  Oid newRefObjectId);
232 
233 extern long changeDependenciesOf(Oid classId, Oid oldObjectId,
234  Oid newObjectId);
235 extern long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId,
236  Oid newRefObjectId);
237 
238 extern Oid getExtensionOfObject(Oid classId, Oid objectId);
239 extern List *getAutoExtensionsOfObject(Oid classId, Oid objectId);
240 
241 extern bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId);
242 extern List *getOwnedSequences(Oid relid);
243 extern Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok);
244 
245 extern Oid get_index_constraint(Oid indexId);
246 
247 extern List *get_index_ref_constraints(Oid indexId);
248 
249 /* in pg_shdepend.c */
250 
251 extern void recordSharedDependencyOn(ObjectAddress *depender,
252  ObjectAddress *referenced,
253  SharedDependencyType deptype);
254 
255 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId,
256  int32 objectSubId);
257 
258 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
259 
260 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
261  Oid newOwnerId);
262 
263 extern void recordDependencyOnTablespace(Oid classId, Oid objectId,
264  Oid tablespace);
265 
266 extern void changeDependencyOnTablespace(Oid classId, Oid objectId,
267  Oid newTablespaceId);
268 
269 extern void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId,
270  Oid ownerId,
271  int noldmembers, Oid *oldmembers,
272  int nnewmembers, Oid *newmembers);
273 
274 extern bool checkSharedDependencies(Oid classId, Oid objectId,
275  char **detail_msg, char **detail_log_msg);
276 
277 extern void shdepLockAndCheckObject(Oid classId, Oid objectId);
278 
279 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
280 
281 extern void dropDatabaseDependencies(Oid databaseId);
282 
283 extern void shdepDropOwned(List *relids, DropBehavior behavior);
284 
285 extern void shdepReassignOwned(List *relids, Oid newrole);
286 
287 #endif /* DEPENDENCY_H */
List * getOwnedSequences(Oid relid)
Definition: pg_depend.c:946
void recordDependencyOnTablespace(Oid classId, Oid objectId, Oid tablespace)
Definition: pg_shdepend.c:361
DependencyType
Definition: dependency.h:31
void ReleaseDeletionLock(const ObjectAddress *object)
Definition: dependency.c:1632
void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:482
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
Definition: pg_depend.c:838
void shdepLockAndCheckObject(Oid classId, Oid objectId)
Definition: pg_shdepend.c:1165
long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:595
void shdepReassignOwned(List *relids, Oid newrole)
Definition: pg_shdepend.c:1489
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
Definition: pg_shdepend.c:633
bool(* VisitDependenciesOfCB)(const ObjectAddress *otherObject, const char *version, char **new_version, void *data)
Definition: dependency.h:191
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:313
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior, bool record_version)
Definition: pg_depend.c:63
Definition: nodes.h:533
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Definition: pg_depend.c:323
unsigned int Oid
Definition: postgres_ext.h:31
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:313
void dropDatabaseDependencies(Oid databaseId)
Definition: pg_shdepend.c:953
signed int int32
Definition: c.h:429
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: pg_depend.c:955
void sort_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2854
void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1603
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
Definition: pg_shdepend.c:852
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:429
ObjectClass
Definition: dependency.h:96
char * tablespace
Definition: pgbench.c:190
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:1001
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2881
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2866
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:165
SharedDependencyType
Definition: dependency.h:79
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:788
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2685
DropBehavior
Definition: parsenodes.h:1814
void recordDependencyOnCollations(ObjectAddress *myself, List *collations, bool record_version)
Definition: dependency.c:1647
Oid get_index_constraint(Oid indexId)
Definition: pg_depend.c:979
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Definition: pg_depend.c:273
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2625
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2570
List * get_index_ref_constraints(Oid indexId)
Definition: pg_depend.c:1035
int16 attnum
Definition: pg_attribute.h:83
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:372
void visitDependenciesOf(const ObjectAddress *object, VisitDependenciesOfCB callback, void *data)
Definition: dependency.c:443
long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)
Definition: pg_depend.c:539
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self, bool record_version)
Definition: dependency.c:1734
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Definition: pg_depend.c:370
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:742
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:221
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1689
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
Definition: pg_shdepend.c:121
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
void changeDependencyOnTablespace(Oid classId, Oid objectId, Oid newTablespaceId)
Definition: pg_shdepend.c:382
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:46
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2834
void shdepDropOwned(List *relids, DropBehavior behavior)
Definition: pg_shdepend.c:1335
unsigned char bool
Definition: c.h:391