55 elog(
DEBUG1,
"resetting unlogged relations: cleanup %d init %d",
64 "ResetUnloggedRelations",
78 while ((spc_de =
ReadDir(spc_dir,
"pg_tblspc")) != NULL)
80 if (strcmp(spc_de->
d_name,
".") == 0 ||
81 strcmp(spc_de->
d_name,
"..") == 0)
84 snprintf(temp_path,
sizeof(temp_path),
"pg_tblspc/%s/%s",
118 if (ts_dir == NULL && errno == ENOENT)
122 errmsg(
"could not open directory \"%s\": %m",
127 while ((de =
ReadDir(ts_dir, tsdirname)) != NULL)
134 if (strspn(de->
d_name,
"0123456789") != strlen(de->
d_name))
137 snprintf(dbspace_path,
sizeof(dbspace_path),
"%s/%s",
178 hash =
hash_create(
"unlogged relation OIDs", 32, &ctl,
183 while ((de =
ReadDir(dbspace_dir, dbspacedirname)) != NULL)
223 while ((de =
ReadDir(dbspace_dir, dbspacedirname)) != NULL)
245 snprintf(rm_path,
sizeof(rm_path),
"%s/%s",
246 dbspacedirname, de->
d_name);
247 if (unlink(rm_path) < 0)
250 errmsg(
"could not remove file \"%s\": %m",
253 elog(
DEBUG2,
"unlinked file \"%s\"", rm_path);
273 while ((de =
ReadDir(dbspace_dir, dbspacedirname)) != NULL)
291 snprintf(srcpath,
sizeof(srcpath),
"%s/%s",
292 dbspacedirname, de->
d_name);
295 memcpy(oidbuf, de->
d_name, oidchars);
296 oidbuf[oidchars] =
'\0';
297 snprintf(dstpath,
sizeof(dstpath),
"%s/%s%s",
298 dbspacedirname, oidbuf, de->
d_name + oidchars + 1 +
302 elog(
DEBUG2,
"copying %s to %s", srcpath, dstpath);
316 while ((de =
ReadDir(dbspace_dir, dbspacedirname)) != NULL)
333 memcpy(oidbuf, de->
d_name, oidchars);
334 oidbuf[oidchars] =
'\0';
335 snprintf(mainpath,
sizeof(mainpath),
"%s/%s%s",
336 dbspacedirname, oidbuf, de->
d_name + oidchars + 1 +
375 for (pos = 0; isdigit((
unsigned char) name[pos]); ++pos)
382 if (name[pos] !=
'_')
395 if (name[pos] ==
'.')
399 for (segchar = 1; isdigit((
unsigned char) name[pos + segchar]); ++segchar)
407 if (name[pos] !=
'\0')
void hash_destroy(HTAB *hashp)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
int forkname_chars(const char *str, ForkNumber *fork)
void fsync_fname(const char *fname, bool isdir)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
long hash_get_num_entries(HTAB *hashp)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void ResetUnloggedRelations(int op)
static void ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
#define ALLOCSET_DEFAULT_SIZES
#define TABLESPACE_VERSION_DIRECTORY
#define UNLOGGED_RELATION_INIT
int errcode_for_file_access(void)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void copy_file(char *fromfile, char *tofile)
DIR * AllocateDir(const char *dirname)
MemoryContext CurrentMemoryContext
static char dstpath[MAXPGPATH]
#define ereport(elevel,...)
#define Assert(condition)
struct dirent * ReadDir(DIR *dir, const char *dirname)
bool parse_filename_for_nontemp_relation(const char *name, int *oidchars, ForkNumber *fork)
#define UNLOGGED_RELATION_CLEANUP
int errmsg(const char *fmt,...)
static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
const char *const forkNames[]
static unsigned hash(unsigned *uv, int n)