35 #if defined(HAVE_SYNC_FILE_RANGE)
36 #define PG_FLUSH_DATA_WORKS 1
37 #elif defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
38 #define PG_FLUSH_DATA_WORKS 1
44 #define MINIMUM_VERSION_FOR_PG_WAL 100000
46 #ifdef PG_FLUSH_DATA_WORKS
47 static int pre_sync_fname(
const char *fname,
bool isdir);
49 static void walkdir(
const char *path,
50 int (*
action) (
const char *fname,
bool isdir),
51 bool process_symlinks);
64 fsync_pgdata(
const char *
pg_data,
80 xlog_is_symlink =
false;
86 if (
lstat(pg_wal, &st) < 0)
88 else if (S_ISLNK(st.st_mode))
89 xlog_is_symlink =
true;
93 xlog_is_symlink =
true;
100 #ifdef PG_FLUSH_DATA_WORKS
103 walkdir(pg_wal, pre_sync_fname,
false);
104 walkdir(pg_tblspc, pre_sync_fname,
true);
128 fsync_dir_recurse(
const char *dir)
134 #ifdef PG_FLUSH_DATA_WORKS
135 walkdir(dir, pre_sync_fname,
false);
157 int (*
action) (
const char *fname,
bool isdir),
158 bool process_symlinks)
166 pg_log_error(
"could not open directory \"%s\": %m", path);
170 while (errno = 0, (de =
readdir(dir)) != NULL)
174 if (strcmp(de->
d_name,
".") == 0 ||
175 strcmp(de->
d_name,
"..") == 0)
200 pg_log_error(
"could not read directory \"%s\": %m", path);
210 (*action) (path,
true);
219 #ifdef PG_FLUSH_DATA_WORKS
222 pre_sync_fname(
const char *fname,
bool isdir)
230 if (errno == EACCES || (isdir && errno == EISDIR))
241 #if defined(HAVE_SYNC_FILE_RANGE)
242 (void) sync_file_range(
fd, 0, 0, SYNC_FILE_RANGE_WRITE);
243 #elif defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)
244 (void) posix_fadvise(
fd, 0, 0, POSIX_FADV_DONTNEED);
246 #error PG_FLUSH_DATA_WORKS should not have been defined
286 fd = open(fname, flags, 0);
289 if (errno == EACCES || (isdir && errno == EISDIR))
301 if (returncode != 0 && !(isdir && (errno == EBADF || errno == EINVAL)))
331 if (strlen(parentpath) == 0)
365 pg_log_error(
"could not open file \"%s\": %m", newfile);
373 pg_log_error(
"could not fsync file \"%s\": %m", newfile);
381 if (rename(oldfile, newfile) != 0)
383 pg_log_error(
"could not rename file \"%s\" to \"%s\": %m",
412 bool look_through_symlinks,
423 #if defined(DT_REG) && defined(DT_DIR) && defined(DT_LNK)
428 else if (de->
d_type ==
DT_LNK && !look_through_symlinks)
442 if (look_through_symlinks)
443 sret =
stat(path, &fst);
445 sret =
lstat(path, &fst);
455 errmsg(
"could not stat file \"%s\": %m", path)));
struct dirent * readdir(DIR *)
DIR * opendir(const char *)
int errcode_for_file_access(void)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int durable_rename(const char *oldfile, const char *newfile, int elevel)
void fsync_fname(const char *fname, bool isdir)
static int fsync_parent_path(const char *fname, int elevel)
static void walkdir(const char *path, void(*action)(const char *fname, bool isdir, int elevel), bool process_symlinks, int elevel)
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
void pg_log_generic(enum pg_log_level level, enum pg_log_part part, const char *pg_restrict fmt,...)
#define pg_log_error(...)
Datum subpath(PG_FUNCTION_ARGS)
#define MINIMUM_VERSION_FOR_PG_WAL
void get_parent_directory(char *path)
size_t strlcpy(char *dst, const char *src, size_t siz)
static int fd(const char *x, int i)
bool pgwin32_is_junction(const char *path)