diff options
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r-- | src/backend/access/transam/xlog.c | 54 |
1 files changed, 12 insertions, 42 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 5d77cbf6bd1..b974b3d438a 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -696,8 +696,6 @@ static void rm_redo_error_callback(void *arg); static int get_sync_bit(int method); -static void fsync_pgdata(char *datadir); - /* * Insert an XLOG record having the specified RMID and info bytes, * with the body of the record being the data chunk(s) described by @@ -5015,18 +5013,6 @@ StartupXLOG(void) (errmsg("database system was interrupted; last known up at %s", str_time(ControlFile->time)))); - /* - * If we previously crashed, there might be data which we had written, - * intending to fsync it, but which we had not actually fsync'd yet. - * Therefore, a power failure in the near future might cause earlier - * unflushed writes to be lost, even though more recent data written to - * disk from here on would be persisted. To avoid that, fsync the entire - * data directory. - */ - if (ControlFile->state != DB_SHUTDOWNED && - ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY) - fsync_pgdata(data_directory); - /* This is just to allow attaching to startup process with a debugger */ #ifdef XLOG_REPLAY_DELAY if (ControlFile->state != DB_SHUTDOWNED) @@ -5051,6 +5037,18 @@ StartupXLOG(void) RelationCacheInitFileRemove(); /* + * If we previously crashed, there might be data which we had written, + * intending to fsync it, but which we had not actually fsync'd yet. + * Therefore, a power failure in the near future might cause earlier + * unflushed writes to be lost, even though more recent data written to + * disk from here on would be persisted. To avoid that, fsync the entire + * data directory. + */ + if (ControlFile->state != DB_SHUTDOWNED && + ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY) + SyncDataDirectory(); + + /* * Initialize on the assumption we want to recover to the latest timeline * that's active according to pg_control. */ @@ -10193,31 +10191,3 @@ SetWalWriterSleeping(bool sleeping) xlogctl->WalWriterSleeping = sleeping; SpinLockRelease(&xlogctl->info_lck); } - -/* - * Issue fsync recursively on PGDATA and all its contents. - */ -static void -fsync_pgdata(char *datadir) -{ - if (!enableFsync) - return; - - /* - * If possible, hint to the kernel that we're soon going to fsync - * the data directory and its contents. - */ -#if defined(HAVE_SYNC_FILE_RANGE) || \ - (defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED)) - walkdir(datadir, pre_sync_fname); -#endif - - /* - * Now we do the fsync()s in the same order. - * - * It's important to fsync the destination directory itself as individual - * file fsyncs don't guarantee that the directory entry for the file is - * synced. - */ - walkdir(datadir, fsync_fname); -} |