6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
14 * Object access hooks are intended to be called just before or just after
15 * performing certain actions on a SQL object. This is intended as
16 * infrastructure for security or logging plugins.
18 * OAT_POST_CREATE should be invoked just after the object is created.
19 * Typically, this is done after inserting the primary catalog records and
20 * associated dependencies. The command counter may or may not be incremented
21 * at the time the hook is invoked; if not, the extension can use SnapshotSelf
22 * to get the new version of the tuple.
24 * OAT_DROP should be invoked just before deletion of objects; typically
25 * deleteOneObject(). Its arguments are packed within ObjectAccessDrop.
27 * OAT_POST_ALTER should be invoked just after the object is altered,
28 * but before the command counter is incremented. An extension using the
29 * hook can use a current MVCC snapshot to get the old version of the tuple,
30 * and can use SnapshotSelf to get the new version of the tuple.
32 * OAT_NAMESPACE_SEARCH should be invoked prior to object name lookup under
33 * a particular namespace. This event is equivalent to usage permission
34 * on a schema under the default access control mechanism.
36 * OAT_FUNCTION_EXECUTE should be invoked prior to function execution.
37 * This event is almost equivalent to execute permission on functions,
38 * except for the case when execute permission is checked during object
39 * creation or altering, because OAT_POST_CREATE or OAT_POST_ALTER are
40 * sufficient for extensions to track these kind of checks.
42 * OAT_TRUNCATE should be invoked just before truncation of objects. This
43 * event is equivalent to truncate permission on a relation under the
44 * default access control mechanism.
46 * Other types may be added in the future.
59 * Arguments of OAT_POST_CREATE event
64 * This flag informs extensions whether the context of this creation is
65 * invoked by user's operations, or not. E.g, it shall be dealt as
66 * internal stuff on toast tables or indexes due to type changes.
72 * Arguments of OAT_DROP event
77 * Flags to inform extensions the context of this deletion. Also see
78 * PERFORM_DELETION_* in dependency.h
84 * Arguments of OAT_POST_ALTER event
89 * This identifier is used when system catalog takes two IDs to identify a
90 * particular tuple of the catalog. It is only used when the caller want
91 * to identify an entry of pg_inherits, pg_db_role_setting or
92 * pg_user_mapping. Elsewhere, InvalidOid should be set.
97 * If this flag is set, the user hasn't requested that the object be
98 * altered, but we're doing it anyway for some internal reason.
99 * Permissions-checking hooks may want to skip checks if, say, we're alter
100 * the constraints of a temporary heap during CLUSTER.
106 * Arguments of OAT_NAMESPACE_SEARCH
111 * If true, hook should report an error when permission to search this
117 * This is, in essence, an out parameter. Core code should initialize
118 * this to true, and any extension that wants to deny access should reset
119 * it to false. But an extension should be careful never to store a true
120 * value here, so that in case there are multiple extensions access is
121 * only allowed if all extensions agree.
126/* Plugin provides a hook function matching one or both of these signatures. */
135 const char *objectStr,
139/* Plugin sets this variable to a suitable hook function. */
144/* Core code uses these functions to call the hook (see macros below). */
151 Oid auxiliaryId,
bool is_internal);
162 Oid auxiliaryId,
bool is_internal);
168 * The following macros are wrappers around the functions above; these should
169 * normally be used to invoke the hook in lieu of calling the above functions
173 #define InvokeObjectPostCreateHook(classId,objectId,subId) \
174 InvokeObjectPostCreateHookArg((classId),(objectId),(subId),false)
175 #define InvokeObjectPostCreateHookArg(classId,objectId,subId,is_internal) \
177 if (object_access_hook) \
178 RunObjectPostCreateHook((classId),(objectId),(subId), \
182 #define InvokeObjectDropHook(classId,objectId,subId) \
183 InvokeObjectDropHookArg((classId),(objectId),(subId),0)
184 #define InvokeObjectDropHookArg(classId,objectId,subId,dropflags) \
186 if (object_access_hook) \
187 RunObjectDropHook((classId),(objectId),(subId), \
191 #define InvokeObjectTruncateHook(objectId) \
193 if (object_access_hook) \
194 RunObjectTruncateHook(objectId); \
197 #define InvokeObjectPostAlterHook(classId,objectId,subId) \
198 InvokeObjectPostAlterHookArg((classId),(objectId),(subId), \
200 #define InvokeObjectPostAlterHookArg(classId,objectId,subId, \
201 auxiliaryId,is_internal) \
203 if (object_access_hook) \
204 RunObjectPostAlterHook((classId),(objectId),(subId), \
205 (auxiliaryId),(is_internal)); \
208 #define InvokeNamespaceSearchHook(objectId, ereport_on_violation) \
209 (!object_access_hook \
211 : RunNamespaceSearchHook((objectId), (ereport_on_violation)))
213 #define InvokeFunctionExecuteHook(objectId) \
215 if (object_access_hook) \
216 RunFunctionExecuteHook(objectId); \
220 #define InvokeObjectPostCreateHookStr(classId,objectName,subId) \
221 InvokeObjectPostCreateHookArgStr((classId),(objectName),(subId),false)
222 #define InvokeObjectPostCreateHookArgStr(classId,objectName,subId,is_internal) \
224 if (object_access_hook_str) \
225 RunObjectPostCreateHookStr((classId),(objectName),(subId), \
229 #define InvokeObjectDropHookStr(classId,objectName,subId) \
230 InvokeObjectDropHookArgStr((classId),(objectName),(subId),0)
231 #define InvokeObjectDropHookArgStr(classId,objectName,subId,dropflags) \
233 if (object_access_hook_str) \
234 RunObjectDropHookStr((classId),(objectName),(subId), \
238 #define InvokeObjectTruncateHookStr(objectName) \
240 if (object_access_hook_str) \
241 RunObjectTruncateHookStr(objectName); \
244 #define InvokeObjectPostAlterHookStr(classId,objectName,subId) \
245 InvokeObjectPostAlterHookArgStr((classId),(objectName),(subId), \
247 #define InvokeObjectPostAlterHookArgStr(classId,objectName,subId, \
248 auxiliaryId,is_internal) \
250 if (object_access_hook_str) \
251 RunObjectPostAlterHookStr((classId),(objectName),(subId), \
252 (auxiliaryId),(is_internal)); \
255 #define InvokeNamespaceSearchHookStr(objectName, ereport_on_violation) \
256 (!object_access_hook_str \
258 : RunNamespaceSearchHookStr((objectName), (ereport_on_violation)))
260 #define InvokeFunctionExecuteHookStr(objectName) \
262 if (object_access_hook_str) \
263 RunFunctionExecuteHookStr(objectName); \
267#endif /* OBJECTACCESS_H */
void RunObjectTruncateHookStr(const char *objectName)
void RunFunctionExecuteHookStr(const char *objectName)
void RunObjectDropHook(Oid classId, Oid objectId, int subId, int dropflags)
void RunObjectPostAlterHook(Oid classId, Oid objectId, int subId, Oid auxiliaryId, bool is_internal)
void RunFunctionExecuteHook(Oid objectId)
bool RunNamespaceSearchHook(Oid objectId, bool ereport_on_violation)
void(* object_access_hook_type)(ObjectAccessType access, Oid classId, Oid objectId, int subId, void *arg)
void RunObjectPostCreateHookStr(Oid classId, const char *objectName, int subId, bool is_internal)
PGDLLIMPORT object_access_hook_type object_access_hook
void(* object_access_hook_type_str)(ObjectAccessType access, Oid classId, const char *objectStr, int subId, void *arg)
void RunObjectTruncateHook(Oid objectId)
void RunObjectPostAlterHookStr(Oid classId, const char *objectName, int subId, Oid auxiliaryId, bool is_internal)
void RunObjectPostCreateHook(Oid classId, Oid objectId, int subId, bool is_internal)
void RunObjectDropHookStr(Oid classId, const char *objectName, int subId, int dropflags)
bool RunNamespaceSearchHookStr(const char *objectName, bool ereport_on_violation)
PGDLLIMPORT object_access_hook_type_str object_access_hook_str
bool ereport_on_violation