PostgreSQL Source Code  git master
reinit.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define UNLOGGED_RELATION_CLEANUP   0x0001
 
#define UNLOGGED_RELATION_INIT   0x0002
 

Functions

void ResetUnloggedRelations (int op)
 

Macro Definition Documentation

◆ UNLOGGED_RELATION_CLEANUP

#define UNLOGGED_RELATION_CLEANUP   0x0001

◆ UNLOGGED_RELATION_INIT

#define UNLOGGED_RELATION_INIT   0x0002

Function Documentation

◆ ResetUnloggedRelations()

void ResetUnloggedRelations ( int  op)

Definition at line 49 of file reinit.c.

References AllocateDir(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), CurrentMemoryContext, dirent::d_name, DEBUG1, elog, FreeDir(), MAXPGPATH, MemoryContextDelete(), MemoryContextSwitchTo(), ReadDir(), ResetUnloggedRelationsInTablespaceDir(), snprintf(), TABLESPACE_VERSION_DIRECTORY, UNLOGGED_RELATION_CLEANUP, and UNLOGGED_RELATION_INIT.

Referenced by StartupXLOG().

50 {
51  char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
52  DIR *spc_dir;
53  struct dirent *spc_de;
54  MemoryContext tmpctx,
55  oldctx;
56 
57  /* Log it. */
58  elog(DEBUG1, "resetting unlogged relations: cleanup %d init %d",
59  (op & UNLOGGED_RELATION_CLEANUP) != 0,
60  (op & UNLOGGED_RELATION_INIT) != 0);
61 
62  /*
63  * Just to be sure we don't leak any memory, let's create a temporary
64  * memory context for this operation.
65  */
67  "ResetUnloggedRelations",
69  oldctx = MemoryContextSwitchTo(tmpctx);
70 
71  /*
72  * First process unlogged files in pg_default ($PGDATA/base)
73  */
75 
76  /*
77  * Cycle through directories for all non-default tablespaces.
78  */
79  spc_dir = AllocateDir("pg_tblspc");
80 
81  while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL)
82  {
83  if (strcmp(spc_de->d_name, ".") == 0 ||
84  strcmp(spc_de->d_name, "..") == 0)
85  continue;
86 
87  snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
90  }
91 
92  FreeDir(spc_dir);
93 
94  /*
95  * Restore memory context.
96  */
97  MemoryContextSwitchTo(oldctx);
98  MemoryContextDelete(tmpctx);
99 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
#define DEBUG1
Definition: elog.h:25
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
Definition: dirent.h:9
Definition: dirent.c:25
#define MAXPGPATH
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:170
#define UNLOGGED_RELATION_INIT
Definition: reinit.h:21
DIR * AllocateDir(const char *dirname)
Definition: fd.c:2373
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition: fd.c:2439
#define TABLESPACE_VERSION_DIRECTORY
Definition: catalog.h:26
#define UNLOGGED_RELATION_CLEANUP
Definition: reinit.h:20
static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
Definition: reinit.c:103
char d_name[MAX_PATH]
Definition: dirent.h:14
#define elog
Definition: elog.h:219
int FreeDir(DIR *dir)
Definition: fd.c:2482