1/*-------------------------------------------------------------------------
4 * Declarations for GetRelationPath() and friends
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/common/relpath.h
11 *-------------------------------------------------------------------------
17 * Required here; note that CppAsString2() does not throw an error if the
18 * symbol is not defined.
23 * RelFileNumber data type identifies the specific relation file name.
26 #define InvalidRelFileNumber ((RelFileNumber) InvalidOid)
27 #define RelFileNumberIsValid(relnumber) \
28 ((bool) ((relnumber) != InvalidRelFileNumber))
31 * Name of major-version-specific tablespace subdirectories
33 #define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \
34 CppAsString2(CATALOG_VERSION_NO)
37 * Tablespace path (relative to installation's $PGDATA).
39 * These values should not be changed as many tools rely on it.
41 #define PG_TBLSPC_DIR "pg_tblspc"
42 #define PG_TBLSPC_DIR_SLASH "pg_tblspc/" /* required for strings
45 /* Characters to allow for an OID in a relation path */
46#define OIDCHARS 10 /* max chars printed by %u */
49 * Stuff for fork names.
51 * The physical storage of a relation consists of one or more forks.
52 * The main fork is always created, but in addition to that there can be
53 * additional forks for storing various metadata. ForkNumber is used when
54 * we need to refer to a specific fork in a relation.
65 * NOTE: if you add a new fork, change MAX_FORKNUM and possibly
66 * FORKNAMECHARS below, and update the forkNames array in
67 * src/common/relpath.c
71#define MAX_FORKNUM INIT_FORKNUM
73#define FORKNAMECHARS 4 /* max chars for a fork name */
82 * Unfortunately, there's no easy way to derive PROCNUMBER_CHARS from
83 * MAX_BACKENDS. MAX_BACKENDS is 2^18-1. Crosschecked in test_relpath().
85#define PROCNUMBER_CHARS 6
88 * The longest possible relation path lengths is from the following format:
89 * sprintf(rp.path, "%s/%u/%s/%u/t%d_%u",
90 * PG_TBLSPC_DIR, spcOid,
91 * TABLESPACE_VERSION_DIRECTORY,
92 * dbOid, procNumber, relNumber);
94 * Note this does *not* include the trailing null-byte, to make it easier to
95 * combine it with other lengths.
97#define REL_PATH_STR_MAXLEN \
99 sizeof(PG_TBLSPC_DIR) - 1 \
100 + sizeof((char)'/') \
101 + OIDCHARS /* spcOid */ \
102 + sizeof((char)'/') \
103 + sizeof(TABLESPACE_VERSION_DIRECTORY) - 1 \
104 + sizeof((char)'/') \
105 + OIDCHARS /* dbOid */ \
106 + sizeof((char)'/') \
107 + sizeof((char)'t') /* temporary table indicator */ \
108 + PROCNUMBER_CHARS /* procNumber */ \
109 + sizeof((char)'_') \
110 + OIDCHARS /* relNumber */ \
111 + sizeof((char)'_') \
112 + FORKNAMECHARS /* forkNames[forkNumber] */ \
116 * String of the exact length required to represent a relation path. We return
117 * this struct, instead of char[REL_PATH_STR_MAXLEN + 1], as the pointer would
118 * decay to a plain char * too easily, possibly preventing the compiler from
119 * detecting invalid references to the on-stack return value of
129 * Stuff for computing filesystem pathnames for relations.
137 * Wrapper macros for GetRelationPath. Beware of multiple
138 * evaluation of the RelFileLocator or RelFileLocatorBackend argument!
141 /* First argument is a RelFileLocator */
142#define relpathbackend(rlocator, backend, forknum) \
143 GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
146 /* First argument is a RelFileLocator */
147#define relpathperm(rlocator, forknum) \
148 relpathbackend(rlocator, INVALID_PROC_NUMBER, forknum)
150 /* First argument is a RelFileLocatorBackend */
151#define relpath(rlocator, forknum) \
152 relpathbackend((rlocator).locator, (rlocator).backend, forknum)
154#endif /* RELPATH_H */
RelPathStr GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
struct RelPathStr RelPathStr
#define REL_PATH_STR_MAXLEN
PGDLLIMPORT const char *const forkNames[]
int forkname_chars(const char *str, ForkNumber *fork)
ForkNumber forkname_to_number(const char *forkName)
char * GetDatabasePath(Oid dbOid, Oid spcOid)
char str[REL_PATH_STR_MAXLEN+1]