PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
relpath.c File Reference
#include "postgres.h"
#include "catalog/catalog.h"
#include "catalog/pg_tablespace.h"
#include "common/relpath.h"
#include "storage/backendid.h"
Include dependency graph for relpath.c:

Go to the source code of this file.

Functions

ForkNumber forkname_to_number (const char *forkName)
 
int forkname_chars (const char *str, ForkNumber *fork)
 
char * GetDatabasePath (Oid dbNode, Oid spcNode)
 
char * GetRelationPath (Oid dbNode, Oid spcNode, Oid relNode, int backendId, ForkNumber forkNumber)
 

Variables

const char *const forkNames []
 

Function Documentation

int forkname_chars ( const char *  str,
ForkNumber fork 
)

Definition at line 79 of file relpath.c.

References forkNames, InvalidForkNumber, and MAX_FORKNUM.

Referenced by looks_like_temp_rel_name(), and parse_filename_for_nontemp_relation().

80 {
81  ForkNumber forkNum;
82 
83  for (forkNum = 1; forkNum <= MAX_FORKNUM; forkNum++)
84  {
85  int len = strlen(forkNames[forkNum]);
86 
87  if (strncmp(forkNames[forkNum], str, len) == 0)
88  {
89  if (fork)
90  *fork = forkNum;
91  return len;
92  }
93  }
94  if (fork)
95  *fork = InvalidForkNumber;
96  return 0;
97 }
ForkNumber
Definition: relpath.h:24
#define MAX_FORKNUM
Definition: relpath.h:39
const char *const forkNames[]
Definition: relpath.c:34
ForkNumber forkname_to_number ( const char *  forkName)

Definition at line 48 of file relpath.c.

References ereport, errcode(), errhint(), errmsg(), ERROR, forkNames, InvalidForkNumber, and MAX_FORKNUM.

Referenced by get_raw_page_fork(), pg_prewarm(), and pg_relation_size().

49 {
50  ForkNumber forkNum;
51 
52  for (forkNum = 0; forkNum <= MAX_FORKNUM; forkNum++)
53  if (strcmp(forkNames[forkNum], forkName) == 0)
54  return forkNum;
55 
56 #ifndef FRONTEND
57  ereport(ERROR,
58  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
59  errmsg("invalid fork name"),
60  errhint("Valid fork names are \"main\", \"fsm\", "
61  "\"vm\", and \"init\".")));
62 #endif
63 
64  return InvalidForkNumber;
65 }
int errhint(const char *fmt,...)
Definition: elog.c:987
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
ForkNumber
Definition: relpath.h:24
#define MAX_FORKNUM
Definition: relpath.h:39
int errmsg(const char *fmt,...)
Definition: elog.c:797
const char *const forkNames[]
Definition: relpath.c:34
char* GetDatabasePath ( Oid  dbNode,
Oid  spcNode 
)

Definition at line 108 of file relpath.c.

References Assert, DEFAULTTABLESPACE_OID, GLOBALTABLESPACE_OID, psprintf(), pstrdup(), and TABLESPACE_VERSION_DIRECTORY.

Referenced by check_db_file_conflict(), createdb(), dbase_redo(), InitPostgres(), movedb(), movedb_failure_callback(), ProcessCommittedInvalidationMessages(), relmap_redo(), remove_dbtablespaces(), and TablespaceCreateDbspace().

109 {
110  if (spcNode == GLOBALTABLESPACE_OID)
111  {
112  /* Shared system relations live in {datadir}/global */
113  Assert(dbNode == 0);
114  return pstrdup("global");
115  }
116  else if (spcNode == DEFAULTTABLESPACE_OID)
117  {
118  /* The default tablespace is {datadir}/base */
119  return psprintf("base/%u", dbNode);
120  }
121  else
122  {
123  /* All other tablespaces are accessed via symlinks */
124  return psprintf("pg_tblspc/%u/%s/%u",
125  spcNode, TABLESPACE_VERSION_DIRECTORY, dbNode);
126  }
127 }
char * pstrdup(const char *in)
Definition: mcxt.c:1165
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define GLOBALTABLESPACE_OID
Definition: pg_tablespace.h:64
#define DEFAULTTABLESPACE_OID
Definition: pg_tablespace.h:63
#define Assert(condition)
Definition: c.h:671
#define TABLESPACE_VERSION_DIRECTORY
Definition: catalog.h:26
char* GetRelationPath ( Oid  dbNode,
Oid  spcNode,
Oid  relNode,
int  backendId,
ForkNumber  forkNumber 
)

Definition at line 139 of file relpath.c.

References Assert, DEFAULTTABLESPACE_OID, forkNames, GLOBALTABLESPACE_OID, InvalidBackendId, MAIN_FORKNUM, psprintf(), and TABLESPACE_VERSION_DIRECTORY.

141 {
142  char *path;
143 
144  if (spcNode == GLOBALTABLESPACE_OID)
145  {
146  /* Shared system relations live in {datadir}/global */
147  Assert(dbNode == 0);
148  Assert(backendId == InvalidBackendId);
149  if (forkNumber != MAIN_FORKNUM)
150  path = psprintf("global/%u_%s",
151  relNode, forkNames[forkNumber]);
152  else
153  path = psprintf("global/%u", relNode);
154  }
155  else if (spcNode == DEFAULTTABLESPACE_OID)
156  {
157  /* The default tablespace is {datadir}/base */
158  if (backendId == InvalidBackendId)
159  {
160  if (forkNumber != MAIN_FORKNUM)
161  path = psprintf("base/%u/%u_%s",
162  dbNode, relNode,
163  forkNames[forkNumber]);
164  else
165  path = psprintf("base/%u/%u",
166  dbNode, relNode);
167  }
168  else
169  {
170  if (forkNumber != MAIN_FORKNUM)
171  path = psprintf("base/%u/t%d_%u_%s",
172  dbNode, backendId, relNode,
173  forkNames[forkNumber]);
174  else
175  path = psprintf("base/%u/t%d_%u",
176  dbNode, backendId, relNode);
177  }
178  }
179  else
180  {
181  /* All other tablespaces are accessed via symlinks */
182  if (backendId == InvalidBackendId)
183  {
184  if (forkNumber != MAIN_FORKNUM)
185  path = psprintf("pg_tblspc/%u/%s/%u/%u_%s",
187  dbNode, relNode,
188  forkNames[forkNumber]);
189  else
190  path = psprintf("pg_tblspc/%u/%s/%u/%u",
192  dbNode, relNode);
193  }
194  else
195  {
196  if (forkNumber != MAIN_FORKNUM)
197  path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u_%s",
199  dbNode, backendId, relNode,
200  forkNames[forkNumber]);
201  else
202  path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u",
204  dbNode, backendId, relNode);
205  }
206  }
207  return path;
208 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define GLOBALTABLESPACE_OID
Definition: pg_tablespace.h:64
#define DEFAULTTABLESPACE_OID
Definition: pg_tablespace.h:63
#define InvalidBackendId
Definition: backendid.h:23
#define Assert(condition)
Definition: c.h:671
#define TABLESPACE_VERSION_DIRECTORY
Definition: catalog.h:26
const char *const forkNames[]
Definition: relpath.c:34

Variable Documentation

const char* const forkNames[]
Initial value:
= {
"main",
"fsm",
"vm",
"init"
}

Definition at line 34 of file relpath.c.

Referenced by forkname_chars(), forkname_to_number(), GetRelationPath(), ResetUnloggedRelationsInDbspaceDir(), and XLogDumpDisplayRecord().