PostgreSQL Source Code git master
relpath.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * relpath.h
4 * Declarations for GetRelationPath() and friends
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/common/relpath.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef RELPATH_H
14#define RELPATH_H
15
16/*
17 * Required here; note that CppAsString2() does not throw an error if the
18 * symbol is not defined.
19 */
20#include "catalog/catversion.h"
21
22/*
23 * RelFileNumber data type identifies the specific relation file name.
24 */
26#define InvalidRelFileNumber ((RelFileNumber) InvalidOid)
27#define RelFileNumberIsValid(relnumber) \
28 ((bool) ((relnumber) != InvalidRelFileNumber))
29
30/*
31 * Name of major-version-specific tablespace subdirectories
32 */
33#define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \
34 CppAsString2(CATALOG_VERSION_NO)
35
36/*
37 * Tablespace path (relative to installation's $PGDATA).
38 *
39 * These values should not be changed as many tools rely on it.
40 */
41#define PG_TBLSPC_DIR "pg_tblspc"
42#define PG_TBLSPC_DIR_SLASH "pg_tblspc/" /* required for strings
43 * comparisons */
44
45/* Characters to allow for an OID in a relation path */
46#define OIDCHARS 10 /* max chars printed by %u */
47
48/*
49 * Stuff for fork names.
50 *
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.
55 */
56typedef enum ForkNumber
63
64 /*
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
68 */
71#define MAX_FORKNUM INIT_FORKNUM
73#define FORKNAMECHARS 4 /* max chars for a fork name */
74
75extern PGDLLIMPORT const char *const forkNames[];
76
77extern ForkNumber forkname_to_number(const char *forkName);
78extern int forkname_chars(const char *str, ForkNumber *fork);
79
80/*
81 * Stuff for computing filesystem pathnames for relations.
82 */
83extern char *GetDatabasePath(Oid dbOid, Oid spcOid);
84
85extern char *GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber,
86 int procNumber, ForkNumber forkNumber);
87
88/*
89 * Wrapper macros for GetRelationPath. Beware of multiple
90 * evaluation of the RelFileLocator or RelFileLocatorBackend argument!
91 */
92
93/* First argument is a RelFileLocator */
94#define relpathbackend(rlocator, backend, forknum) \
95 GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
96 backend, forknum)
97
98/* First argument is a RelFileLocator */
99#define relpathperm(rlocator, forknum) \
100 relpathbackend(rlocator, INVALID_PROC_NUMBER, forknum)
101
102/* First argument is a RelFileLocatorBackend */
103#define relpath(rlocator, forknum) \
104 relpathbackend((rlocator).locator, (rlocator).backend, forknum)
105
106#endif /* RELPATH_H */
#define PGDLLIMPORT
Definition: c.h:1277
const char * str
unsigned int Oid
Definition: postgres_ext.h:32
Oid RelFileNumber
Definition: relpath.h:25
PGDLLIMPORT const char *const forkNames[]
Definition: relpath.c:33
ForkNumber
Definition: relpath.h:56
@ FSM_FORKNUM
Definition: relpath.h:59
@ VISIBILITYMAP_FORKNUM
Definition: relpath.h:60
@ MAIN_FORKNUM
Definition: relpath.h:58
@ InvalidForkNumber
Definition: relpath.h:57
@ INIT_FORKNUM
Definition: relpath.h:61
char * GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber, int procNumber, ForkNumber forkNumber)
Definition: relpath.c:142
int forkname_chars(const char *str, ForkNumber *fork)
Definition: relpath.c:81
ForkNumber forkname_to_number(const char *forkName)
Definition: relpath.c:50
char * GetDatabasePath(Oid dbOid, Oid spcOid)
Definition: relpath.c:110