1/*-------------------------------------------------------------------------
4 * POSTGRES resource owner definitions.
6 * Query-lifespan resources are tracked by associating them with
7 * ResourceOwner objects. This provides a simple mechanism for ensuring
8 * that such resources are freed at the right time.
9 * See utils/resowner/README for more info.
12 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
13 * Portions Copyright (c) 1994, Regents of the University of California
15 * src/include/utils/resowner.h
17 *-------------------------------------------------------------------------
24 * ResourceOwner objects are an opaque data structure known only within
31 * Globally known ResourceOwners
39 * Resource releasing is done in three phases: pre-locks, locks, and
40 * post-locks. The pre-lock phase must release any resources that are visible
41 * to other backends (such as pinned buffers); this ensures that when we
42 * release a lock that another backend may be waiting on, it will see us as
43 * being fully out of our transaction. The post-lock phase should be used for
44 * backend-internal cleanup.
46 * Within each phase, resources are released in priority order. Priority is
47 * just an integer specified in ResourceOwnerDesc. The priorities of built-in
48 * resource types are given below, extensions may use any priority relative to
49 * those or RELEASE_PRIO_FIRST/LAST. RELEASE_PRIO_FIRST is a fine choice if
50 * your resource doesn't depend on any other resources.
61/* priorities of built-in BEFORE_LOCKS resources */
62 #define RELEASE_PRIO_BUFFER_IOS 100
63 #define RELEASE_PRIO_BUFFER_PINS 200
64 #define RELEASE_PRIO_RELCACHE_REFS 300
65 #define RELEASE_PRIO_DSMS 400
66 #define RELEASE_PRIO_JIT_CONTEXTS 500
67 #define RELEASE_PRIO_CRYPTOHASH_CONTEXTS 600
68 #define RELEASE_PRIO_HMAC_CONTEXTS 700
70/* priorities of built-in AFTER_LOCKS resources */
71 #define RELEASE_PRIO_CATCACHE_REFS 100
72 #define RELEASE_PRIO_CATCACHE_LIST_REFS 200
73 #define RELEASE_PRIO_PLANCACHE_REFS 300
74 #define RELEASE_PRIO_TUPDESC_REFS 400
75 #define RELEASE_PRIO_SNAPSHOT_REFS 500
76 #define RELEASE_PRIO_FILES 600
77 #define RELEASE_PRIO_WAITEVENTSETS 700
79/* 0 is considered invalid */
80 #define RELEASE_PRIO_FIRST 1
81 #define RELEASE_PRIO_LAST UINT32_MAX
84 * In order to track an object, resowner.c needs a few callbacks for it.
85 * The callbacks for resources of a specific kind are encapsulated in
88 * Note that the callbacks occur post-commit or post-abort, so the callback
89 * functions can only do noncritical cleanup and must not fail.
93 const char *
name;
/* name for the object kind, for debugging */
95 /* when are these objects released? */
102 * This is called for each resource in the resource owner, in the order
103 * specified by 'release_phase' and 'release_priority' when the whole
104 * resource owner is been released or when ResourceOwnerReleaseAllOfKind()
105 * is called. The resource is implicitly removed from the owner, the
106 * callback function doesn't need to call ResourceOwnerForget.
111 * Format a string describing the resource, for debugging purposes. If a
112 * resource has not been properly released before commit, this is used to
115 * This can be left to NULL, in which case a generic "[resource name]: %p"
123 * Dynamically loaded modules can get control during ResourceOwnerRelease
124 * by providing a callback of this form.
133 * Functions in resowner.c
136/* generic routines */
162/* special support for local lock management */
167/* special support for AIO */
172#endif /* RESOWNER_H */
void ResourceOwnerNewParent(ResourceOwner owner, ResourceOwner newparent)
void ResourceOwnerRememberLock(ResourceOwner owner, struct LOCALLOCK *locallock)
struct ResourceOwnerDesc ResourceOwnerDesc
PGDLLIMPORT ResourceOwner TopTransactionResourceOwner
void UnregisterResourceReleaseCallback(ResourceReleaseCallback callback, void *arg)
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
void ReleaseAuxProcessResources(bool isCommit)
ResourceOwner ResourceOwnerGetParent(ResourceOwner owner)
@ RESOURCE_RELEASE_BEFORE_LOCKS
@ RESOURCE_RELEASE_AFTER_LOCKS
void ResourceOwnerRememberAioHandle(ResourceOwner owner, struct dlist_node *ioh_node)
PGDLLIMPORT ResourceOwner AuxProcessResourceOwner
uint32 ResourceReleasePriority
void CreateAuxProcessResourceOwner(void)
void ResourceOwnerRelease(ResourceOwner owner, ResourceReleasePhase phase, bool isCommit, bool isTopLevel)
PGDLLIMPORT ResourceOwner CurTransactionResourceOwner
void ResourceOwnerForgetLock(ResourceOwner owner, struct LOCALLOCK *locallock)
void RegisterResourceReleaseCallback(ResourceReleaseCallback callback, void *arg)
void ResourceOwnerForget(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerReleaseAllOfKind(ResourceOwner owner, const ResourceOwnerDesc *kind)
void ResourceOwnerDelete(ResourceOwner owner)
PGDLLIMPORT ResourceOwner CurrentResourceOwner
struct ResourceOwnerData * ResourceOwner
void ResourceOwnerRemember(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerForgetAioHandle(ResourceOwner owner, struct dlist_node *ioh_node)
void(* ResourceReleaseCallback)(ResourceReleasePhase phase, bool isCommit, bool isTopLevel, void *arg)
void ResourceOwnerEnlarge(ResourceOwner owner)
ResourceReleasePhase release_phase
void(* ReleaseResource)(Datum res)
ResourceReleasePriority release_priority
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)